added initial

This commit is contained in:
Tobias Schmidl 2021-01-29 11:36:03 +01:00
commit b76212bc1d
2 changed files with 211 additions and 0 deletions

161
.gitignore vendored Normal file
View file

@ -0,0 +1,161 @@
### Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
### Vim
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

50
tweetdelete.py Normal file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env python
import tweepy
from datetime import datetime, timedelta
# options
test_mode = False
verbose = True
delete_tweets = True
days_to_keep = 30
tweets_to_save = [
# 1234567890
]
# auth and api
consumer_key = 'FOOBAR'
consumer_secret = 'FOOBAR'
access_token = 'FOOBAR'
access_token_secret = 'FOOBAR'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# set cutoff date, use utc to match twitter
cutoff_date = datetime.utcnow() - timedelta(days=days_to_keep)
# delete old tweets
if delete_tweets:
# 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)
deletion_count += 1
else:
ignored_count += 1
print("Deleted %d tweets, ignored %d" % (deletion_count, ignored_count))
else:
print("Not deleting tweets")