Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare PyPI package #53

Merged
merged 5 commits into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Publish Python package

on:
release:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
4 changes: 0 additions & 4 deletions Dockerfile

This file was deleted.

41 changes: 6 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Delete tweets
# delete-tweets

![](https://github.com/koenrh/delete-tweets/workflows/build/badge.svg)

Expand Down Expand Up @@ -67,60 +67,31 @@ export TWITTER_ACCESS_TOKEN_SECRET="your_access_token_secret"
First, install the required dependencies.

```bash
pip install -r requirements.txt
pip install delete-tweets
```

Then, for example, delete any tweet from _before_ January 1, 2018:

```bash
python deletetweets.py -d 2018-01-01 tweet.js
delete-tweets -d 2018-01-01 tweet.js
```

Or only delete all retweets:

```bash
python deletetweets.py -r retweet tweet.js
delete-tweets -r retweet tweet.js
```

### Spare tweets

You can optionally spare tweets by passing their `id_str`, setting a minimum amount of likes or retweets:

```bash
python deletetweets.py -d 2018-01-01 tweet.js --spare-ids 21235434 23498723 23498723
delete-tweets -d 2018-01-01 tweet.js --spare-ids 21235434 23498723 23498723
```

Spare tweets that have at least 10 likes, or 5 retweets:

```bash
python deletetweets.py -d 2018-01-01 tweet.js --spare-min-likes 10 --spare-min-retweets 5
delete-tweets -d 2018-01-01 tweet.js --spare-min-likes 10 --spare-min-retweets 5
```

### Docker

Alternatively, you could run this script in a [Docker](https://docs.docker.com/install/)
container.

First, you need to build the Docker image.

```bash
docker build -t koenrh/delete-tweets .
```

Then, run the script using the following command.

:warning: Before you continue, you should be aware that most shells record user
input (and thus secrets) into a history file. In Bash you could prevent this by
prepending your command with a _single space_ (requires `$HISTCONTROL` to be set
to `ignorespace` or `ignoreboth`).

```bash
docker run --env TWITTER_CONSUMER_KEY="$TWITTER_CONSUMER_KEY" \
--env TWITTER_CONSUMER_SECRET="$TWITTER_CONSUMER_SECRET" \
--env TWITTER_ACCESS_TOKEN="$TWITTER_ACCESS_TOKEN" \
--env TWITTER_ACCESS_TOKEN_SECRET="$TWITTER_ACCESS_TOKEN_SECRET" \
--volume "$PWD:/app" --rm -it koenrh/delete-tweets -d 2018-01-01 /app/tweet.js
```

You could make this command more easily accessible by putting it an executable,
and make sure that it is available in your `$PATH`.
39 changes: 39 additions & 0 deletions bin/delete-tweets
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python

import argparse
import os
import sys

__author__ = "Koen Rouwhorst"
__version__ = "1.0.0"

def main():
parser = argparse.ArgumentParser(description="Delete old tweets.")
parser.add_argument("-d", dest="date", required=True,
help="Delete tweets until this date")
parser.add_argument("-r", dest="restrict", choices=["reply", "retweet"],
help="Restrict to either replies or retweets")
parser.add_argument("file", help="Path to the tweet.js file",
type=str)
parser.add_argument("--spare-ids", dest="spare_ids", help="A list of tweet ids to spare",
type=str, nargs="+", default=[])
parser.add_argument("--spare-min-likes", dest="min_likes",
help="Spare tweets with more than the provided likes", type=int, default=0)
parser.add_argument("--spare-min-retweets", dest="min_retweets",
help="Spare tweets with more than the provided retweets", type=int, default=0)
parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)

args = parser.parse_args()

if not ("TWITTER_CONSUMER_KEY" in os.environ and
"TWITTER_CONSUMER_SECRET" in os.environ and
"TWITTER_ACCESS_TOKEN" in os.environ and
"TWITTER_ACCESS_TOKEN_SECRET" in os.environ):
sys.stderr.write("Twitter API credentials not set.\n")
exit(1)

deletetweets.delete(args.file, args.date, args.restrict, args.spare_ids, args.min_likes, args.min_retweets)


if __name__ == "__main__":
main()
37 changes: 1 addition & 36 deletions deletetweets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env python

import argparse
import io
import os
import sys
Expand All @@ -10,9 +7,6 @@
import twitter
from dateutil.parser import parse

__author__ = "Koen Rouwhorst"
__version__ = "1.0.0"


class TweetDestroyer(object):
def __init__(self, twitter_api):
Expand Down Expand Up @@ -80,33 +74,4 @@ def delete(tweetjs_path, date, r, s, min_l, min_r):

print("Number of deleted tweets: %s\n" % count)


def main():
parser = argparse.ArgumentParser(description="Delete old tweets.")
parser.add_argument("-d", dest="date", required=True,
help="Delete tweets until this date")
parser.add_argument("-r", dest="restrict", choices=["reply", "retweet"],
help="Restrict to either replies or retweets")
parser.add_argument("file", help="Path to the tweet.js file",
type=str)
parser.add_argument("--spare-ids", dest="spare_ids", help="A list of tweet ids to spare",
type=str, nargs="+", default=[])
parser.add_argument("--spare-min-likes", dest="min_likes",
help="Spare tweets with more than the provided likes", type=int, default=0)
parser.add_argument("--spare-min-retweets", dest="min_retweets",
help="Spare tweets with more than the provided retweets", type=int, default=0)

args = parser.parse_args()

if not ("TWITTER_CONSUMER_KEY" in os.environ and
"TWITTER_CONSUMER_SECRET" in os.environ and
"TWITTER_ACCESS_TOKEN" in os.environ and
"TWITTER_ACCESS_TOKEN_SECRET" in os.environ):
sys.stderr.write("Twitter API credentials not set.")
exit(1)

delete(args.file, args.date, args.restrict, args.spare_ids, args.min_likes, args.min_retweets)


if __name__ == "__main__":
main()
sys.exit()
24 changes: 24 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="delete-tweets",
version="1.0.0",
author="Koen Rouwhorst",
author_email="info@koenrouwhorst.nl",
description="Delete tweets from your Twitter timeline.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/koenrh/delete-tweets",
packages=setuptools.find_packages(),
scripts=['bin/delete-tweets'],
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2.7",
"License :: OSI Approved :: ISC License (ISCL)",
"Operating System :: OS Independent",
],
python_requires='>=2.7',
)