Skip to content

Instantly share code, notes, and snippets.

@blha303
Last active July 26, 2019 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blha303/449f320c06c896daac45c94bd89cbd07 to your computer and use it in GitHub Desktop.
Save blha303/449f320c06c896daac45c94bd89cbd07 to your computer and use it in GitHub Desktop.
#!/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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment