Skip to content

Commit

Permalink
Merge pull request #1 from buckket/master
Browse files Browse the repository at this point in the history
update twtxt
  • Loading branch information
cremesk authored Dec 28, 2024
2 parents fe31c32 + ec421d1 commit 42b37f3
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 106 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Python

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

name: Testing using Python ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --editable .
pip install flake8 pytest pytest-cov
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
make pytest
coverage:
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --editable .
pip install flake8 pytest pytest-cov coveralls
- name: Test with pytest and run coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
make pytest
coveralls --service=github
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Jan Schütze <[email protected]>
Jeremy Kitchen <[email protected]>
Matthew Brady <[email protected]>
Melvin Carvalho <[email protected]>
Sergei Kolesnikov <[email protected]>
tedder <[email protected]>
teddydestodes <[email protected]>
Ted Timmons <[email protected]>
Expand Down
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Changelog

These are all the changes in twtxt since the first public release.

1.3.0
-----

- Bumped all dependencies
- Python >= 3.7 is now supported

1.2.3
-----

Expand Down
17 changes: 10 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ Check out the full documentation at: http://twtxt.readthedocs.org/en/latest/
Community
---------

- twtxt IRC channel: **#twtxt** on `irc.freenode.net`_
- twtxt IRC channel: **#twtxt** on `irc.libera.chat`_

Contributions
-------------

- A curated list of active twtxt users by `mdom <https://github.com/mdom>`_: https://github.com/mdom/we-are-twtxt
- A curated list of active twtxt users by `yarn.social <https://yarn.social/>`_: https://git.mills.io/yarnsocial/we-are-twtxt
- A web-based directory of twtxt users by `reednj <https://twitter.com/reednj>`_: http://twtxt.reednj.com/
- A web-based twtxt feed hoster for the masses by `plomlompom <http://www.plomlompom.de/>`_: https://github.com/plomlompom/htwtxt
- A twtxt-to-atom converter in sh by `erlehmann <http://news.dieweltistgarnichtso.net/>`_: http://news.dieweltistgarnichtso.net/bin/twtxt2atom
Expand All @@ -45,11 +45,14 @@ Contributions
- A twtxt client written in C by `dertuxmalwieder <https://github.com/dertuxmalwieder>`_: https://hub.darcs.net/dertuxmalwieder/twtxtc
- A read-only timeline of the last 3000 tweets via gopher by `trqx <gopher://shroom.party>`_: gopher://shroom.party/1/twtxt
- A bot for using twtxt over xmpp by `mdosch <https://blog.mdosch.de>`_: https://salsa.debian.org/mdosch-guest/goxtxt
- twtxt registry server written in Go by `gbmor <https://github.com/gbmor>`_: https://github.com/getwtxt/getwtxt
- twtxt registry server written in Go by `gbmor <https://github.com/gbmor>`_: https://github.com/gbmor/getwtxt-ng
- A twtxt parsing library written in Rust by `gbmor <https://github.com/gbmor>`_: https://github.com/rustwtxt/rustwtxt
- A twtxt WordPress plugin, that provides the blog-posts as twtxt file, written by `pfefferle <https://github.com/pfefferle>`_: https://github.com/pfefferle/wordpress-twtxt
- A twtxt client for Emacs by `deadblackclover <https://github.com/deadblackclover>`_: https://github.com/deadblackclover/twtxt-el
- A twtxt client for Emacs by `deadblackclover <https://codeberg.org/deadblackclover/twtxt-el>`_: https://codeberg.org/deadblackclover/twtxt-el
- An php interface for publishing to your selfhosted twtxt.txt by `sorenpeter <https://github.com/sorenpeter>`_: https://github.com/sorenpeter/phpub2twtxt/
- A graphical twtxt client written in Tcl/Tk, RSS-to-twtxt converter, and mentions extractor by `dbohdan <https://dbohdan.com>`_: https://gitlab.com/dbohdan/twtxt.tcl
- twtwt: a really fast UNIX only twtxt client written in C by `win0err <https://github.com/win0err>`_: https://github.com/win0err/twtwt



License
Expand All @@ -62,8 +65,8 @@ twtxt is released under the MIT License. See the bundled LICENSE file for detail
:target: https://pypi.python.org/pypi/twtxt
:alt: Latest version released on PyPi

.. |build| image:: https://img.shields.io/travis/buckket/twtxt/master.svg?style=flat
:target: http://travis-ci.org/buckket/twtxt
.. |build| image:: https://github.com/buckket/twtxt/actions/workflows/python.yml/badge.svg
:target: https://github.com/buckket/twtxt/actions/workflows/python.yml
:alt: Build status of the master branch

.. |coverage| image:: https://img.shields.io/coveralls/buckket/twtxt/master.svg?style=flat
Expand All @@ -82,4 +85,4 @@ twtxt is released under the MIT License. See the bundled LICENSE file for detail
:target: http://twtxt.readthedocs.org/en/latest/?badge=latest
:alt: Documentation Status

.. _irc.freenode.net: https://freenode.net/
.. _irc.libera.chat: https://libera.chat/
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ User Guide
Community
---------

- twtxt IRC channel: **#twtxt** on `irc.freenode.net`_
- twtxt IRC channel: **#twtxt** on `irc.libera.chat`_

API Reference
-------------
Expand All @@ -42,4 +42,4 @@ This part of the documentation describes the modules, classes, functions and oth
api

.. _GitHub: https://github.com/buckket/twtxt
.. _irc.freenode.net: https://freenode.net/
.. _irc.libera.chat: https://libera.chat/
14 changes: 9 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@

platforms='any',

python_requires='>=3.8',
install_requires=[
'aiohttp>=2.2.5,<3',
'aiohttp>=3.8.1,<4',
'python-dateutil>=2.6.1,<3',
'humanize>=0.5.1,<1',
'click>=6.7,<7',
'humanize>=3.1.0,<5',
'click>=8.0.0,<9',
],

extras_require={
Expand All @@ -56,8 +57,11 @@
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Operating System :: OS Independent',
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py34, py35
envlist = py38, py39, py310, py311, py312

[testenv]
commands = py.test --tb=short -v --cov {envsitepackagesdir}/twtxt/ tests/
Expand Down
4 changes: 2 additions & 2 deletions twtxt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
Decentralised, minimalist microblogging service for hackers.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""


__version__ = '1.2.3'
__version__ = '1.3.2-dev'
2 changes: 1 addition & 1 deletion twtxt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Alias for twtxt.cli for the command line.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

Expand Down
6 changes: 3 additions & 3 deletions twtxt/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module implements a caching system for storing tweets.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

Expand All @@ -22,7 +22,7 @@ class Cache:
cache_dir = get_app_dir("twtxt")
cache_name = "cache"

def __init__(self, cache_file, cache, update_interval):
def __init__(self, cache_file, cache, update_interval=0):
"""Initializes new :class:`Cache` object.
:param str cache_file: full path to the loaded cache file.
Expand Down Expand Up @@ -52,7 +52,7 @@ def from_file(cls, file, *args, **kwargs):

@classmethod
def discover(cls, *args, **kwargs):
"""Make a guess about the cache file location an try loading it."""
"""Make a guess about the cache file location and try loading it."""
file = os.path.join(Cache.cache_dir, Cache.cache_name)
return cls.from_file(file, *args, **kwargs)

Expand Down
9 changes: 5 additions & 4 deletions twtxt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
This module implements the command-line interface of twtxt.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

import logging
import os
import shutil
import sys
import textwrap
from itertools import chain
Expand Down Expand Up @@ -239,7 +240,7 @@ def follow(ctx, nick, url, force):
click.confirm("➤ You’re already following {0}. Overwrite?".format(
click.style(source.nick, bold=True)), default=False, abort=True)

_, status = get_remote_status([source])[0]
_, status = (get_remote_status([source]))[0]
if not status or status.status_code != 200:
click.confirm("➤ The feed of {0} at {1} is not available. Follow anyway?".format(
click.style(source.nick, bold=True),
Expand All @@ -258,7 +259,7 @@ def unfollow(ctx, nick):
source = ctx.obj['conf'].get_source_by_nick(nick)

try:
with Cache.discover() as cache:
with Cache.discover(update_interval=ctx.obj["conf"].timeline_update_interval) as cache:
cache.remove_tweets(source.url)
except OSError as e:
logger.debug(e)
Expand All @@ -275,7 +276,7 @@ def unfollow(ctx, nick):
@cli.command()
def quickstart():
"""Quickstart wizard for setting up twtxt."""
width = click.get_terminal_size()[0]
width = shutil.get_terminal_size()[0]
width = width if width <= 79 else 79

click.secho("twtxt - quickstart", fg="cyan")
Expand Down
2 changes: 1 addition & 1 deletion twtxt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module implements the config file parser/writer.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

Expand Down
10 changes: 3 additions & 7 deletions twtxt/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module implements various helper for use in twtxt.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

Expand All @@ -14,7 +14,6 @@
import textwrap

import click
import pkg_resources

from twtxt.mentions import format_mentions
from twtxt.parser import parse_iso8601
Expand Down Expand Up @@ -69,7 +68,7 @@ def style_source_with_status(source, status, porcelain=False):
content_length=status.content_length,
last_modified=status.last_modified)
else:
if status.status_code == 200:
if hasattr(status, "status_code") and status.status_code == 200:
scolor, smessage = "green", str(status.status_code)
elif status:
scolor, smessage = "red", str(status.status_code)
Expand Down Expand Up @@ -164,10 +163,7 @@ def sort_and_truncate_tweets(tweets, direction, limit):


def generate_user_agent():
try:
version = pkg_resources.require("twtxt")[0].version
except pkg_resources.DistributionNotFound:
version = "unknown"
from twtxt import __version__ as version

conf = click.get_current_context().obj["conf"]
if conf.disclose_identity and conf.nick and conf.twturl:
Expand Down
2 changes: 1 addition & 1 deletion twtxt/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module configures the logging module for twtxt.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

Expand Down
2 changes: 1 addition & 1 deletion twtxt/mentions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module implements functions for handling mentions in twtxt.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

Expand Down
10 changes: 7 additions & 3 deletions twtxt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module implements the main models used in twtxt.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

Expand Down Expand Up @@ -75,8 +75,12 @@ def __str__(self):
def relative_datetime(self):
"""Return human-readable relative time string."""
now = datetime.now(timezone.utc)
tense = "from now" if self.created_at > now else "ago"
return "{0} {1}".format(humanize.naturaldelta(now - self.created_at), tense)
created_at = self.created_at.astimezone(timezone.utc)

delta = humanize.naturaldelta(abs(created_at - now))
tense = "from now" if now < created_at else "ago"

return f"{delta} {tense}"

@property
def absolute_datetime(self):
Expand Down
2 changes: 1 addition & 1 deletion twtxt/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module implements the parser for twtxt files.
:copyright: (c) 2016-2017 by buckket.
:copyright: (c) 2016-2022 by buckket.
:license: MIT, see LICENSE for more details.
"""

Expand Down
Loading

0 comments on commit 42b37f3

Please sign in to comment.