Last active 1564075774

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

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