All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
5 # Fetches tweets since a given timestamp and stores data in JSON files, as
6 # well as an HTML dump for each in the subdirectory ./tweets.
8 # Usage: ./tweetfetch.py 1159606554041040896
10 # The timestamp of the last tweet fetched is stored in ./tweets/.sentinel
12 # Copyright © 2017–2019 by martin f. krafft <madduck@madduck.net>
13 # Released under the Artistic Licence 2.0
16 from authdata import *
18 from twython import Twython
22 twitter = Twython(app_key=consumer_key,
23 app_secret=consumer_secret,
24 oauth_token=access_token,
25 oauth_token_secret=access_secret,
28 config = {'include_rts': False,
31 'exclude_replies': True,
35 config['since_id'] = sys.argv[1]
36 print("Limiting results to tweets since ID {}".format(config['since_id']),
39 user_timeline = twitter.get_user_timeline(screen_name="martinkrafft",
42 max_id = int(config.get('since_id', 0))
44 print("Fetched {} tweets, writing them to disk…".format(len(user_timeline)),
47 for tweet in user_timeline:
48 with open("tweets/{}.json".format(tweet['id_str']), "wt") as tf:
49 print(json.dumps(tweet), file=tf)
51 with open("tweets/{}.html".format(tweet['id_str']), "wt") as tf:
52 print(Twython.html_for_tweet(tweet, use_expanded_url=True), file=tf)
54 print(" wrote tweet ID {}".format(tweet['id_str']),
57 max_id = max(tweet['id'], max_id)
59 print("Writing ID {} to sentinel file…".format(max_id), file=sys.stderr)
60 with open("tweets/.sentinel", "wt") as tf:
61 print('{0:d}'.format(max_id), file=tf)