From 937ff844cd5e655d6dd028341292c8b9d52a6ca9 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 8 Feb 2021 09:23:51 +0100 Subject: [PATCH] Added scaffold --- .gitlab-ci.yml | 21 ++++++++++++++++++++ .style.yapf | 33 +++++++++++++++++++++++++++++++ README.md | 3 +++ pylama.ini | 14 +++++++++++++ requirements.txt | 3 +++ setup.py | 21 ++++++++++++++++++++ tweetdelete.py | 51 ++++++++++++++++++++++++++---------------------- 7 files changed, 123 insertions(+), 23 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 .style.yapf create mode 100644 README.md create mode 100644 pylama.ini create mode 100644 setup.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..2cd73c4 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,21 @@ +image: python:alpine + +test:pylama: + stage: test + only: + - master + - develop + before_script: + - pip install -r requirements.txt + script: + pylama . + +test:pytest: + stage: test + only: + - master + - develop + before_script: + - pip install -r requirements.txt + script: + pytest . diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 0000000..b34c3f4 --- /dev/null +++ b/.style.yapf @@ -0,0 +1,33 @@ +[style] + +# Insert a blank line before a module docstring. +blank_line_before_module_docstring=True + +# The column limit. +column_limit=120 + +# Split before the '.' if we need to split a longer expression: +# +# foo = ('This is a really long string: {}, {}, {}, {}'.format(a, b, c, d)) +# +# would reformat to something like: +# +# foo = ('This is a really long string: {}, {}, {}, {}' +# .format(a, b, c, d)) +split_before_dot=True + +# Set to True to split list comprehensions and generators that have +# non-trivial expressions and multiple clauses before each of these +# clauses. For example: +# +# result = [ +# a_long_var + 100 for a_long_var in xrange(1000) +# if a_long_var % 10] +# +# would reformat to something like: +# +# result = [ +# a_long_var + 100 +# for a_long_var in xrange(1000) +# if a_long_var % 10] +split_complex_comprehension=True diff --git a/README.md b/README.md new file mode 100644 index 0000000..1abf6af --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# tweetdelete + + diff --git a/pylama.ini b/pylama.ini new file mode 100644 index 0000000..48d15c9 --- /dev/null +++ b/pylama.ini @@ -0,0 +1,14 @@ +[pylama] +format = pylint +linters = mccabe,pep257,pydocstyle,pep8,pycodestyle,pyflakes,pylint,isort +ignore = D203 +skip=.env/* + +[pylama:pycodestyle] +max_line_length = 120 + +[pylama:pep8] +max_line_length = 120 + +[pylama:pylint] +max_line_length = 120 diff --git a/requirements.txt b/requirements.txt index 3797e4f..8e8ced6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,6 @@ +pylama>=7.7.0 +pylint>=2.3.0 toml>=0.10.0 tweepy>=3.10.0 xdg>=5.0.0 +yapf>=0.27.0 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..21cdec5 --- /dev/null +++ b/setup.py @@ -0,0 +1,21 @@ +#! /usr/bin/env python3 + +"""Setup script for tweetdelete.""" + +from setuptools import setup + +import tweetdelete + +with open("README.md", "r") as f: + LONG_DESCRIPTION = f.read() + +setup(name="tweetdelete", + version=tweetdelete.__version__, + author=tweetdelete.__author__, + description=tweetdelete.__doc__, + license=tweetdelete.__license__, + long_description=LONG_DESCRIPTION, + install_requires=["toml >= 0.10.0", "tweepy >= 3.10.0", "xdg >= 5.0.0"], + scripts=["tweetdelete.py"], + url="https://schmidl.cc/", + classifiers=[]) diff --git a/tweetdelete.py b/tweetdelete.py index 1e24f37..fbcc5e9 100755 --- a/tweetdelete.py +++ b/tweetdelete.py @@ -1,5 +1,11 @@ #!/usr/bin/env python3 +"""Deletes old tweets.""" +__author__ = "Tobias Schmidl" +__copyright__ = "Copyright 2021 Tobias Schmidl" +__license__ = "MIT" +__version__ = "0.1" + import os from datetime import datetime, timedelta @@ -16,30 +22,29 @@ tweets_to_save = twitter_config["tweets_to_save"] if "tweets_to_save" in twitter secrets = twitter_config["secrets"] # auth and api -auth = tweepy.OAuthHandler(secrets['api_key'], secrets['api_key_secret']) -auth.set_access_token(secrets['access_token'], secrets['access_token_secret']) -api = tweepy.API(auth) +if __name__ == "__main__": + auth = tweepy.OAuthHandler(secrets['api_key'], secrets['api_key_secret']) + auth.set_access_token(secrets['access_token'], secrets['access_token_secret']) + api = tweepy.API(auth) + # set cutoff date, use utc to match twitter + cutoff_date = datetime.utcnow() - timedelta(days=days_to_keep) -# set cutoff date, use utc to match twitter -cutoff_date = datetime.utcnow() - timedelta(days=days_to_keep) + # get all timeline tweets + print("Retrieving timeline tweets") + timeline = tweepy.Cursor(api.user_timeline).items() + deletion_count = 0 # pylint:disable=C0103 + ignored_count = 0 # pylint:disable=C0103 -# get all timeline tweets -print("Retrieving timeline tweets") -timeline = tweepy.Cursor(api.user_timeline).items() -deletion_count = 0 -ignored_count = 0 + for tweet in timeline: + # where tweets are not in save list and older than cutoff date + if tweet.id not in tweets_to_save and tweet.created_at < cutoff_date: + if verbose: + print("Deleting %d: [%s] %s" % (tweet.id, tweet.created_at, tweet.text)) + if not test_mode: + api.destroy_status(tweet.id) -for tweet in timeline: - # where tweets are not in save list and older than cutoff date - if tweet.id not in tweets_to_save and tweet.created_at < cutoff_date: - if verbose: - print("Deleting %d: [%s] %s" % - (tweet.id, tweet.created_at, tweet.text)) - if not test_mode: - api.destroy_status(tweet.id) + deletion_count += 1 + else: + ignored_count += 1 - deletion_count += 1 - else: - ignored_count += 1 - -print("Deleted %d tweets, ignored %d" % (deletion_count, ignored_count)) + print("Deleted %d tweets, ignored %d" % (deletion_count, ignored_count))