Last active 1564075774

https://github.com/blha303/Twitter-IRC-lists 2: electric boogaloo

Revision 7d4cda457f2a306d690e522f638ab024c9421335

twitter-discord-lists.py Raw
1#!/usr/bin/env python3
2from requests import post
3from twitter import Api # pip install python-twitter
4from json import load
5
6lists = [("567697393169072140", "blha303", "reog")]
7
8with open("twitter.json") as f:
9 api = Api(**load(f))
10
11with open(".bottoken") as f:
12 token = f.read().strip()
13
14
15def get_list_since(sn, slug, since):
16 timeline = api.GetListTimeline(slug=slug, owner_screen_name=sn, since_id=since)
17 return timeline, timeline[0].id if timeline else None
18
19def post_to_discord(channel, text):
20 """ Posts to Discord like a boss """
21 if text is False:
22 return "cool"
23 print(text)
24 d = post("https://discordapp.com/api/channels/{}/messages".format(channel),
25 json={"content": text},
26 headers={"Authorization": "Bot " + token,
27 "User-Agent": "twitter-discord-lists by suv"
28 }).json()
29 return "cool"
30
31if __name__ == "__main__":
32 for channel, sn, slug in lists:
33 try:
34 with open(".{}{}since".format(sn, slug)) as f:
35 since = f.read().strip()
36 except:
37 since = None
38 timeline, since = get_list_since(since)
39 if since:
40 for t in timeline:
41 post_to_discord(567697393169072140, "https://twitter.com/{}/status/{}".format(t.user.screen_name, t.id))
42 with open(".{}{}since".format(sn, slug)) as f:
43 f.write(str(since))
44