twitter-discord-lists.py
· 1.2 KiB · Python
Raw
#!/usr/bin/env python3
from requests import post
import twitter # pip install python-twitter
from json import load
with open("twitter.json") as f:
api = twitter.Api(**load(f))
with open(".bottoken") as f:
token = f.read().strip()
def get_list_since(since):
try:
timeline = api.GetListTimeline(slug=_slug, owner_screen_name=_sn, since_id=since)
except twitter.error.TwitterError:
return [], None
return timeline, timeline[0].id if timeline else None
def post_to_discord(channel, text):
""" Posts to Discord like a boss """
if text is False:
return "cool"
print(text)
d = post("https://discordapp.com/api/channels/{}/messages".format(channel),
json={"content": text},
headers={"Authorization": "Bot " + token,
"User-Agent": "twitter-discord-lists by suv"
}).json()
return "cool"
if __name__ == "__main__":
with open(".since") as f:
since = f.read().strip()
timeline, since = get_list_since(since)
if since:
for t in timeline:
post_to_discord(x, "https://twitter.com/{}/status/{}".format(t.user.screen_name, t.id))
with open(".since", "w") as f:
f.write(str(since))
| 1 | #!/usr/bin/env python3 |
| 2 | from requests import post |
| 3 | import twitter # pip install python-twitter |
| 4 | from json import load |
| 5 | |
| 6 | with open("twitter.json") as f: |
| 7 | api = twitter.Api(**load(f)) |
| 8 | |
| 9 | with open(".bottoken") as f: |
| 10 | token = f.read().strip() |
| 11 | |
| 12 | |
| 13 | def 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 | |
| 20 | def 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 | |
| 32 | if __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)) |