Added scaffold

This commit is contained in:
Tobias Schmidl 2021-02-08 09:23:51 +01:00
parent 68fc515cf8
commit 937ff844cd
7 changed files with 123 additions and 23 deletions

21
.gitlab-ci.yml Normal file
View file

@ -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 .

33
.style.yapf Normal file
View file

@ -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

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# tweetdelete

14
pylama.ini Normal file
View file

@ -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

View file

@ -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

21
setup.py Normal file
View file

@ -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=[])

View file

@ -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,25 +22,24 @@ tweets_to_save = twitter_config["tweets_to_save"] if "tweets_to_save" in twitter
secrets = twitter_config["secrets"]
# auth and api
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)
# get all timeline tweets
print("Retrieving timeline tweets")
timeline = tweepy.Cursor(api.user_timeline).items()
deletion_count = 0
ignored_count = 0
deletion_count = 0 # pylint:disable=C0103
ignored_count = 0 # pylint:disable=C0103
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))
print("Deleting %d: [%s] %s" % (tweet.id, tweet.created_at, tweet.text))
if not test_mode:
api.destroy_status(tweet.id)