diff options
author | André Glüpker <git@wgmd.de> | 2021-07-29 10:44:00 +0200 |
---|---|---|
committer | André Glüpker <git@wgmd.de> | 2021-07-29 10:44:00 +0200 |
commit | 4b0a75b85d1892e04230de828fe09b90d4f73f09 (patch) | |
tree | fe18bd687c1966d47412269dde06b4efe738d972 /twitter.py | |
parent | 1d8f04124d1eab31b104731a6e672a014b818859 (diff) | |
download | rss-feeds-4b0a75b85d1892e04230de828fe09b90d4f73f09.tar.gz rss-feeds-4b0a75b85d1892e04230de828fe09b90d4f73f09.tar.bz2 rss-feeds-4b0a75b85d1892e04230de828fe09b90d4f73f09.zip |
Handle empty twitter feeds
Diffstat (limited to 'twitter.py')
-rwxr-xr-x | twitter.py | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -103,22 +103,25 @@ def twitter(user): logging.error('Request to twitter failed.', exc_info=exc) return None + feed = { + 'title': 'Twitter: ' + user, + 'url': 'https://twitter.com/' + user, + 'description': 'The latest entries of the twitter account of ' + user, + 'content': [] + } + if not response["meta"]["result_count"]: - return [] + return feed - tweets = [parse_tweet( + feed['content'] = [parse_tweet( user, tweet, response.get("includes", {}).get("tweets", []), response.get("includes", {}).get("media", []), ) for tweet in response["data"]] - return { - 'title': 'Twitter: ' + user, - 'url': 'https://twitter.com/' + user, - 'description': 'The latest entries of the twitter account of ' + user, - 'content': tweets - } + return feed + def parse_tweet(user, tweet, included_tweets, included_media): title = description = tweet["text"] |