summaryrefslogtreecommitdiff
path: root/twitter.py
diff options
context:
space:
mode:
Diffstat (limited to 'twitter.py')
-rwxr-xr-xtwitter.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/twitter.py b/twitter.py
index 4c53933..7f2dfae 100755
--- a/twitter.py
+++ b/twitter.py
@@ -109,7 +109,8 @@ def twitter(user):
tweets = [parse_tweet(
user,
tweet,
- response["includes"]["media"],
+ response.get("includes", {}).get("tweets", []),
+ response.get("includes", {}).get("media", []),
) for tweet in response["data"]]
return {
@@ -119,7 +120,7 @@ def twitter(user):
'content': tweets
}
-def parse_tweet(user, tweet, media):
+def parse_tweet(user, tweet, included_tweets, included_media):
title = description = tweet["text"]
link = "https://twitter.com/" + user + "/status/" + str(tweet["id"])
@@ -129,7 +130,7 @@ def parse_tweet(user, tweet, media):
if rt["type"] == "retweeted":
rt_info = title[: title.index(":") + 2]
ref_tweet = next(
- t for t in response["includes"]["tweets"] if t["id"] == rt["id"]
+ t for t in included_tweets if t["id"] == rt["id"]
)
title = rt_info + ref_tweet["text"]
description = rt_info + ref_tweet["text"]
@@ -150,7 +151,7 @@ def parse_tweet(user, tweet, media):
included_media_keys = tweet.get('attachments', {}).get('media_keys', [])
for included_media_key in included_media_keys:
ref_media = next(
- t for t in media if t["media_key"] == included_media_key
+ t for t in included_media if t["media_key"] == included_media_key
)
if 'url' not in ref_media: continue
if ref_media.get('type', '') == 'photo':