From 97042b994a99d784df35bc54510779510f605823 Mon Sep 17 00:00:00 2001 From: Zhuoyun Wei Date: Wed, 9 Aug 2023 01:41:34 -0700 Subject: [PATCH 1/5] test: add fixture of tweet with bare user dict --- tests/fixtures/tweet_with_bare_user_dict.json | 37 ++ tests/fixtures/tweet_with_photo.json | 186 +++++- tests/fixtures/tweet_with_video.json | 530 +++++++++++++++++- 3 files changed, 751 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/tweet_with_bare_user_dict.json diff --git a/tests/fixtures/tweet_with_bare_user_dict.json b/tests/fixtures/tweet_with_bare_user_dict.json new file mode 100644 index 0000000..5ebad8d --- /dev/null +++ b/tests/fixtures/tweet_with_bare_user_dict.json @@ -0,0 +1,37 @@ +{ + "@timestamp": "2023-07-04T00:21:26+00:00", + "created_at": "Tue Jul 04 00:21:26 +0000 2023", + "display_text_range": [ + "0", + "45" + ], + "edit_info": { + "initial": { + "editTweetIds": [ + "1676023376631197696" + ], + "editableUntil": "2023-07-04T01:21:26.000Z", + "editsRemaining": "5", + "isEditEligible": true + } + }, + "entities": { + "hashtags": [], + "symbols": [], + "urls": [], + "user_mentions": [] + }, + "favorite_count": "5", + "favorited": false, + "full_text": "想不到Twitter比Facebook先死... 🔜@alan_blake@dabr.ca", + "id": "1676023376631197696", + "id_str": "1676023376631197696", + "lang": "ja", + "retweet_count": "0", + "retweeted": false, + "source": "Twitter for Android", + "truncated": false, + "user": { + "screen_name": "alan_blake" + } +} diff --git a/tests/fixtures/tweet_with_photo.json b/tests/fixtures/tweet_with_photo.json index 523eae6..bb4ec0d 100644 --- a/tests/fixtures/tweet_with_photo.json +++ b/tests/fixtures/tweet_with_photo.json @@ -1 +1,185 @@ -{"@timestamp": "2023-01-17T19:06:46+00:00", "contributors": null, "coordinates": null, "created_at": "Tue Jan 17 19:06:46 +0000 2023", "display_text_range": [0, 75], "entities": {"hashtags": [], "media": [{"display_url": "pic.twitter.com/9dauLWrDZS", "expanded_url": "https://twitter.com/wzyboy/status/1615425412921987074/photo/1", "id": 1615425410095017984, "id_str": "1615425410095017984", "indices": [76, 99], "media_url": "http://pbs.twimg.com/media/Fmsk2gHacAAJGL0.jpg", "media_url_https": "https://pbs.twimg.com/media/Fmsk2gHacAAJGL0.jpg", "sizes": {"large": {"h": 2048, "resize": "fit", "w": 922}, "medium": {"h": 1200, "resize": "fit", "w": 540}, "small": {"h": 680, "resize": "fit", "w": 306}, "thumb": {"h": 150, "resize": "crop", "w": 150}}, "type": "photo", "url": "https://t.co/9dauLWrDZS"}], "symbols": [], "urls": [], "user_mentions": []}, "extended_entities": {"media": [{"display_url": "pic.twitter.com/9dauLWrDZS", "expanded_url": "https://twitter.com/wzyboy/status/1615425412921987074/photo/1", "id": 1615425410095017984, "id_str": "1615425410095017984", "indices": [76, 99], "media_url": "http://pbs.twimg.com/media/Fmsk2gHacAAJGL0.jpg", "media_url_https": "https://pbs.twimg.com/media/Fmsk2gHacAAJGL0.jpg", "sizes": {"large": {"h": 2048, "resize": "fit", "w": 922}, "medium": {"h": 1200, "resize": "fit", "w": 540}, "small": {"h": 680, "resize": "fit", "w": 306}, "thumb": {"h": 150, "resize": "crop", "w": 150}}, "type": "photo", "url": "https://t.co/9dauLWrDZS"}]}, "favorite_count": 0, "favorited": false, "full_text": "Todoist: please connect a keyboard to your phone and press F12 to continue. https://t.co/9dauLWrDZS", "geo": null, "id": 1615425412921987074, "id_str": "1615425412921987074", "in_reply_to_screen_name": null, "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "is_quote_status": false, "lang": "en", "place": null, "possibly_sensitive": false, "retweet_count": 0, "retweeted": false, "source": "Twitter for Android", "truncated": false, "user": {"contributors_enabled": false, "created_at": "Fri Jun 26 05:13:44 +0000 2009", "default_profile": false, "default_profile_image": false, "description": "Das Leben ist zu kurz, um Deutsch zu lernen. 每天给 @Uucky_Lee 洗碗。欢迎在 Fediverse 里关注我。了解 Fediverse 联邦宇宙: https://t.co/WGCqN97JAz", "entities": {"description": {"urls": [{"display_url": "wzyboy.im/post/1486.html", "expanded_url": "https://wzyboy.im/post/1486.html", "indices": [101, 124], "url": "https://t.co/WGCqN97JAz"}]}, "url": {"urls": [{"display_url": "wzyboy.im", "expanded_url": "https://wzyboy.im/", "indices": [0, 23], "url": "https://t.co/btXCkHdabG"}]}}, "favourites_count": 1608, "follow_request_sent": false, "followers_count": 5072, "following": false, "friends_count": 429, "geo_enabled": true, "has_extended_profile": true, "id": 50932982, "id_str": "50932982", "is_translation_enabled": true, "is_translator": true, "lang": null, "listed_count": 115, "location": "Vancouver, BC", "name": "@wzyboy@dabr.ca", "notifications": false, "profile_background_color": "FFFFFF", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme16/bg.gif", "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme16/bg.gif", "profile_background_tile": false, "profile_banner_url": "https://pbs.twimg.com/profile_banners/50932982/1573897758", "profile_image_url": "http://pbs.twimg.com/profile_images/1195639287456391168/IAxCxK39_normal.jpg", "profile_image_url_https": "https://pbs.twimg.com/profile_images/1195639287456391168/IAxCxK39_normal.jpg", "profile_link_color": "8CB2BD", "profile_sidebar_border_color": "FFFFFF", "profile_sidebar_fill_color": "424C55", "profile_text_color": "8C94A2", "profile_use_background_image": false, "protected": true, "screen_name": "wzyboy", "statuses_count": 52391, "time_zone": null, "translator_type": "badged", "url": "https://t.co/btXCkHdabG", "utc_offset": null, "verified": false, "withheld_in_countries": []}} \ No newline at end of file +{ + "@timestamp": "2023-01-17T19:06:46+00:00", + "contributors": null, + "coordinates": null, + "created_at": "Tue Jan 17 19:06:46 +0000 2023", + "display_text_range": [ + 0, + 75 + ], + "entities": { + "hashtags": [], + "media": [ + { + "display_url": "pic.twitter.com/9dauLWrDZS", + "expanded_url": "https://twitter.com/wzyboy/status/1615425412921987074/photo/1", + "id": 1615425410095017984, + "id_str": "1615425410095017984", + "indices": [ + 76, + 99 + ], + "media_url": "http://pbs.twimg.com/media/Fmsk2gHacAAJGL0.jpg", + "media_url_https": "https://pbs.twimg.com/media/Fmsk2gHacAAJGL0.jpg", + "sizes": { + "large": { + "h": 2048, + "resize": "fit", + "w": 922 + }, + "medium": { + "h": 1200, + "resize": "fit", + "w": 540 + }, + "small": { + "h": 680, + "resize": "fit", + "w": 306 + }, + "thumb": { + "h": 150, + "resize": "crop", + "w": 150 + } + }, + "type": "photo", + "url": "https://t.co/9dauLWrDZS" + } + ], + "symbols": [], + "urls": [], + "user_mentions": [] + }, + "extended_entities": { + "media": [ + { + "display_url": "pic.twitter.com/9dauLWrDZS", + "expanded_url": "https://twitter.com/wzyboy/status/1615425412921987074/photo/1", + "id": 1615425410095017984, + "id_str": "1615425410095017984", + "indices": [ + 76, + 99 + ], + "media_url": "http://pbs.twimg.com/media/Fmsk2gHacAAJGL0.jpg", + "media_url_https": "https://pbs.twimg.com/media/Fmsk2gHacAAJGL0.jpg", + "sizes": { + "large": { + "h": 2048, + "resize": "fit", + "w": 922 + }, + "medium": { + "h": 1200, + "resize": "fit", + "w": 540 + }, + "small": { + "h": 680, + "resize": "fit", + "w": 306 + }, + "thumb": { + "h": 150, + "resize": "crop", + "w": 150 + } + }, + "type": "photo", + "url": "https://t.co/9dauLWrDZS" + } + ] + }, + "favorite_count": 0, + "favorited": false, + "full_text": "Todoist: please connect a keyboard to your phone and press F12 to continue. https://t.co/9dauLWrDZS", + "geo": null, + "id": 1615425412921987074, + "id_str": "1615425412921987074", + "in_reply_to_screen_name": null, + "in_reply_to_status_id": null, + "in_reply_to_status_id_str": null, + "in_reply_to_user_id": null, + "in_reply_to_user_id_str": null, + "is_quote_status": false, + "lang": "en", + "place": null, + "possibly_sensitive": false, + "retweet_count": 0, + "retweeted": false, + "source": "Twitter for Android", + "truncated": false, + "user": { + "contributors_enabled": false, + "created_at": "Fri Jun 26 05:13:44 +0000 2009", + "default_profile": false, + "default_profile_image": false, + "description": "Das Leben ist zu kurz, um Deutsch zu lernen. 每天给 @Uucky_Lee 洗碗。欢迎在 Fediverse 里关注我。了解 Fediverse 联邦宇宙: https://t.co/WGCqN97JAz", + "entities": { + "description": { + "urls": [ + { + "display_url": "wzyboy.im/post/1486.html", + "expanded_url": "https://wzyboy.im/post/1486.html", + "indices": [ + 101, + 124 + ], + "url": "https://t.co/WGCqN97JAz" + } + ] + }, + "url": { + "urls": [ + { + "display_url": "wzyboy.im", + "expanded_url": "https://wzyboy.im/", + "indices": [ + 0, + 23 + ], + "url": "https://t.co/btXCkHdabG" + } + ] + } + }, + "favourites_count": 1608, + "follow_request_sent": false, + "followers_count": 5072, + "following": false, + "friends_count": 429, + "geo_enabled": true, + "has_extended_profile": true, + "id": 50932982, + "id_str": "50932982", + "is_translation_enabled": true, + "is_translator": true, + "lang": null, + "listed_count": 115, + "location": "Vancouver, BC", + "name": "@wzyboy@dabr.ca", + "notifications": false, + "profile_background_color": "FFFFFF", + "profile_background_image_url": "http://abs.twimg.com/images/themes/theme16/bg.gif", + "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme16/bg.gif", + "profile_background_tile": false, + "profile_banner_url": "https://pbs.twimg.com/profile_banners/50932982/1573897758", + "profile_image_url": "http://pbs.twimg.com/profile_images/1195639287456391168/IAxCxK39_normal.jpg", + "profile_image_url_https": "https://pbs.twimg.com/profile_images/1195639287456391168/IAxCxK39_normal.jpg", + "profile_link_color": "8CB2BD", + "profile_sidebar_border_color": "FFFFFF", + "profile_sidebar_fill_color": "424C55", + "profile_text_color": "8C94A2", + "profile_use_background_image": false, + "protected": true, + "screen_name": "wzyboy", + "statuses_count": 52391, + "time_zone": null, + "translator_type": "badged", + "url": "https://t.co/btXCkHdabG", + "utc_offset": null, + "verified": false, + "withheld_in_countries": [] + } +} diff --git a/tests/fixtures/tweet_with_video.json b/tests/fixtures/tweet_with_video.json index a2720c9..d03c9d0 100644 --- a/tests/fixtures/tweet_with_video.json +++ b/tests/fixtures/tweet_with_video.json @@ -1 +1,529 @@ -{"@timestamp": "2022-12-03T22:41:03+00:00", "contributors": null, "coordinates": null, "created_at": "Sat Dec 03 22:41:03 +0000 2022", "display_text_range": [0, 118], "entities": {"hashtags": [], "media": [{"display_url": "pic.twitter.com/CZTKmX68wh", "expanded_url": "https://twitter.com/dodo/status/1599161556507365376/video/1", "id": 1598448776582115328, "id_str": "1598448776582115328", "indices": [95, 118], "media_url": "http://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", "media_url_https": "https://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", "sizes": {"large": {"h": 1080, "resize": "fit", "w": 1080}, "medium": {"h": 1080, "resize": "fit", "w": 1080}, "small": {"h": 680, "resize": "fit", "w": 680}, "thumb": {"h": 150, "resize": "crop", "w": 150}}, "source_status_id": 1599161556507365376, "source_status_id_str": "1599161556507365376", "source_user_id": 1604444052, "source_user_id_str": "1604444052", "type": "photo", "url": "https://t.co/CZTKmX68wh"}], "symbols": [], "urls": [], "user_mentions": [{"id": 1604444052, "id_str": "1604444052", "indices": [3, 8], "name": "The Dodo", "screen_name": "dodo"}, {"id": 780516438113153025, "id_str": "780516438113153025", "indices": [80, 94], "name": "PlayforStrays", "screen_name": "PlayforStrays"}]}, "extended_entities": {"media": [{"additional_media_info": {"description": "", "embeddable": true, "monetizable": true, "source_user": {"contributors_enabled": false, "created_at": "Thu Jul 18 22:19:02 +0000 2013", "default_profile": false, "default_profile_image": false, "description": "For animal people.", "entities": {"description": {"urls": []}, "url": {"urls": [{"display_url": "thedodo.com", "expanded_url": "http://www.thedodo.com", "indices": [0, 23], "url": "https://t.co/vdKLF4z50p"}]}}, "favourites_count": 20883, "follow_request_sent": false, "followers_count": 2632250, "following": false, "friends_count": 4446, "geo_enabled": true, "has_extended_profile": false, "id": 1604444052, "id_str": "1604444052", "is_translation_enabled": true, "is_translator": false, "lang": null, "listed_count": 7063, "location": "New York, NY", "name": "The Dodo", "notifications": false, "profile_background_color": "A0E6F9", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", "profile_background_tile": true, "profile_banner_url": "https://pbs.twimg.com/profile_banners/1604444052/1619619087", "profile_image_url": "http://pbs.twimg.com/profile_images/1542905116168056832/3QZfoNql_normal.jpg", "profile_image_url_https": "https://pbs.twimg.com/profile_images/1542905116168056832/3QZfoNql_normal.jpg", "profile_link_color": "FA0011", "profile_sidebar_border_color": "FFFFFF", "profile_sidebar_fill_color": "DDEEF6", "profile_text_color": "333333", "profile_use_background_image": false, "protected": false, "screen_name": "dodo", "statuses_count": 79958, "time_zone": null, "translator_type": "none", "url": "https://t.co/vdKLF4z50p", "utc_offset": null, "verified": true, "withheld_in_countries": []}, "title": " Guy Finds Starving Dog On Deserted Island "}, "display_url": "pic.twitter.com/CZTKmX68wh", "expanded_url": "https://twitter.com/dodo/status/1599161556507365376/video/1", "id": 1598448776582115328, "id_str": "1598448776582115328", "indices": [95, 118], "media_url": "http://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", "media_url_https": "https://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", "sizes": {"large": {"h": 1080, "resize": "fit", "w": 1080}, "medium": {"h": 1080, "resize": "fit", "w": 1080}, "small": {"h": 680, "resize": "fit", "w": 680}, "thumb": {"h": 150, "resize": "crop", "w": 150}}, "source_status_id": 1599161556507365376, "source_status_id_str": "1599161556507365376", "source_user_id": 1604444052, "source_user_id_str": "1604444052", "type": "video", "url": "https://t.co/CZTKmX68wh", "video_info": {"aspect_ratio": [1, 1], "duration_millis": 212212, "variants": [{"bitrate": 1280000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/720x720/mn336TwuCUiapYKo.mp4?tag=16"}, {"bitrate": 832000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/540x540/c3ysrVHaOS3gS4pV.mp4?tag=16"}, {"bitrate": 8768000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/1080x1080/uj5eNeYYAafmOFL1.mp4?tag=16"}, {"bitrate": 432000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/320x320/2LKcsB380YiG24b8.mp4?tag=16"}, {"content_type": "application/x-mpegURL", "url": "https://video.twimg.com/amplify_video/1598448776582115328/pl/8ThFK3LUK7Z5dwno.m3u8?tag=16&container=fmp4"}]}}]}, "favorite_count": 0, "favorited": false, "full_text": "RT @dodo: This guy found a starving dog on a beach and knew what he had to do 💙 @playforstrays https://t.co/CZTKmX68wh", "geo": null, "id": 1599171888076722176, "id_str": "1599171888076722176", "in_reply_to_screen_name": null, "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "is_quote_status": false, "lang": "en", "place": null, "possibly_sensitive": false, "retweet_count": 131, "retweeted": false, "retweeted_status": {"contributors": null, "coordinates": null, "created_at": "Sat Dec 03 22:00:00 +0000 2022", "display_text_range": [0, 84], "entities": {"hashtags": [], "media": [{"display_url": "pic.twitter.com/CZTKmX68wh", "expanded_url": "https://twitter.com/dodo/status/1599161556507365376/video/1", "id": 1598448776582115328, "id_str": "1598448776582115328", "indices": [85, 108], "media_url": "http://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", "media_url_https": "https://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", "sizes": {"large": {"h": 1080, "resize": "fit", "w": 1080}, "medium": {"h": 1080, "resize": "fit", "w": 1080}, "small": {"h": 680, "resize": "fit", "w": 680}, "thumb": {"h": 150, "resize": "crop", "w": 150}}, "type": "photo", "url": "https://t.co/CZTKmX68wh"}], "symbols": [], "urls": [], "user_mentions": [{"id": 780516438113153025, "id_str": "780516438113153025", "indices": [70, 84], "name": "PlayforStrays", "screen_name": "PlayforStrays"}]}, "extended_entities": {"media": [{"additional_media_info": {"description": "", "embeddable": true, "monetizable": true, "title": " Guy Finds Starving Dog On Deserted Island "}, "display_url": "pic.twitter.com/CZTKmX68wh", "expanded_url": "https://twitter.com/dodo/status/1599161556507365376/video/1", "id": 1598448776582115328, "id_str": "1598448776582115328", "indices": [85, 108], "media_url": "http://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", "media_url_https": "https://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", "sizes": {"large": {"h": 1080, "resize": "fit", "w": 1080}, "medium": {"h": 1080, "resize": "fit", "w": 1080}, "small": {"h": 680, "resize": "fit", "w": 680}, "thumb": {"h": 150, "resize": "crop", "w": 150}}, "type": "video", "url": "https://t.co/CZTKmX68wh", "video_info": {"aspect_ratio": [1, 1], "duration_millis": 212212, "variants": [{"bitrate": 1280000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/720x720/mn336TwuCUiapYKo.mp4?tag=16"}, {"bitrate": 832000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/540x540/c3ysrVHaOS3gS4pV.mp4?tag=16"}, {"bitrate": 8768000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/1080x1080/uj5eNeYYAafmOFL1.mp4?tag=16"}, {"bitrate": 432000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/320x320/2LKcsB380YiG24b8.mp4?tag=16"}, {"content_type": "application/x-mpegURL", "url": "https://video.twimg.com/amplify_video/1598448776582115328/pl/8ThFK3LUK7Z5dwno.m3u8?tag=16&container=fmp4"}]}}]}, "favorite_count": 1102, "favorited": false, "full_text": "This guy found a starving dog on a beach and knew what he had to do 💙 @playforstrays https://t.co/CZTKmX68wh", "geo": null, "id": 1599161556507365376, "id_str": "1599161556507365376", "in_reply_to_screen_name": null, "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "is_quote_status": false, "lang": "en", "place": null, "possibly_sensitive": false, "retweet_count": 131, "retweeted": false, "source": "Twitter Media Studio", "truncated": false, "user": {"contributors_enabled": false, "created_at": "Thu Jul 18 22:19:02 +0000 2013", "default_profile": false, "default_profile_image": false, "description": "For animal people.", "entities": {"description": {"urls": []}, "url": {"urls": [{"display_url": "thedodo.com", "expanded_url": "http://www.thedodo.com", "indices": [0, 23], "url": "https://t.co/vdKLF4z50p"}]}}, "favourites_count": 20883, "follow_request_sent": false, "followers_count": 2632250, "following": false, "friends_count": 4446, "geo_enabled": true, "has_extended_profile": false, "id": 1604444052, "id_str": "1604444052", "is_translation_enabled": true, "is_translator": false, "lang": null, "listed_count": 7063, "location": "New York, NY", "name": "The Dodo", "notifications": false, "profile_background_color": "A0E6F9", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", "profile_background_tile": true, "profile_banner_url": "https://pbs.twimg.com/profile_banners/1604444052/1619619087", "profile_image_url": "http://pbs.twimg.com/profile_images/1542905116168056832/3QZfoNql_normal.jpg", "profile_image_url_https": "https://pbs.twimg.com/profile_images/1542905116168056832/3QZfoNql_normal.jpg", "profile_link_color": "FA0011", "profile_sidebar_border_color": "FFFFFF", "profile_sidebar_fill_color": "DDEEF6", "profile_text_color": "333333", "profile_use_background_image": false, "protected": false, "screen_name": "dodo", "statuses_count": 79958, "time_zone": null, "translator_type": "none", "url": "https://t.co/vdKLF4z50p", "utc_offset": null, "verified": true, "withheld_in_countries": []}}, "source": "Twitter Web App", "truncated": false, "user": {"contributors_enabled": false, "created_at": "Sat Jan 05 08:10:03 +0000 2013", "default_profile": false, "default_profile_image": false, "description": "UX。日常推为主,摸鱼up主、@HondaJOJO 鉴定过的傻、好奇、梦多、颈椎病十级、不耐冻、漆黑意志。喜欢逛超市和公园。每天给 @wzyboy 做饭。", "entities": {"description": {"urls": []}, "url": {"urls": [{"display_url": "uucky.me", "expanded_url": "https://uucky.me", "indices": [0, 23], "url": "https://t.co/j80l9t44tU"}]}}, "favourites_count": 9164, "follow_request_sent": false, "followers_count": 2336, "following": true, "friends_count": 963, "geo_enabled": true, "has_extended_profile": true, "id": 1062473329, "id_str": "1062473329", "is_translation_enabled": false, "is_translator": false, "lang": null, "listed_count": 67, "location": "海女美術大学🍁", "name": "@uucky@o3o.ca", "notifications": true, "profile_background_color": "DBE9ED", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme17/bg.gif", "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme17/bg.gif", "profile_background_tile": false, "profile_banner_url": "https://pbs.twimg.com/profile_banners/1062473329/1434218278", "profile_image_url": "http://pbs.twimg.com/profile_images/1591958226446213126/lOaklion_normal.jpg", "profile_image_url_https": "https://pbs.twimg.com/profile_images/1591958226446213126/lOaklion_normal.jpg", "profile_link_color": "FF0066", "profile_sidebar_border_color": "FFFFFF", "profile_sidebar_fill_color": "E6F6F9", "profile_text_color": "333333", "profile_use_background_image": true, "protected": true, "screen_name": "Uucky_Lee", "statuses_count": 42361, "time_zone": null, "translator_type": "regular", "url": "https://t.co/j80l9t44tU", "utc_offset": null, "verified": false, "withheld_in_countries": []}} \ No newline at end of file +{ + "@timestamp": "2022-12-03T22:41:03+00:00", + "contributors": null, + "coordinates": null, + "created_at": "Sat Dec 03 22:41:03 +0000 2022", + "display_text_range": [ + 0, + 118 + ], + "entities": { + "hashtags": [], + "media": [ + { + "display_url": "pic.twitter.com/CZTKmX68wh", + "expanded_url": "https://twitter.com/dodo/status/1599161556507365376/video/1", + "id": 1598448776582115328, + "id_str": "1598448776582115328", + "indices": [ + 95, + 118 + ], + "media_url": "http://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", + "media_url_https": "https://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", + "sizes": { + "large": { + "h": 1080, + "resize": "fit", + "w": 1080 + }, + "medium": { + "h": 1080, + "resize": "fit", + "w": 1080 + }, + "small": { + "h": 680, + "resize": "fit", + "w": 680 + }, + "thumb": { + "h": 150, + "resize": "crop", + "w": 150 + } + }, + "source_status_id": 1599161556507365376, + "source_status_id_str": "1599161556507365376", + "source_user_id": 1604444052, + "source_user_id_str": "1604444052", + "type": "photo", + "url": "https://t.co/CZTKmX68wh" + } + ], + "symbols": [], + "urls": [], + "user_mentions": [ + { + "id": 1604444052, + "id_str": "1604444052", + "indices": [ + 3, + 8 + ], + "name": "The Dodo", + "screen_name": "dodo" + }, + { + "id": 780516438113153025, + "id_str": "780516438113153025", + "indices": [ + 80, + 94 + ], + "name": "PlayforStrays", + "screen_name": "PlayforStrays" + } + ] + }, + "extended_entities": { + "media": [ + { + "additional_media_info": { + "description": "", + "embeddable": true, + "monetizable": true, + "source_user": { + "contributors_enabled": false, + "created_at": "Thu Jul 18 22:19:02 +0000 2013", + "default_profile": false, + "default_profile_image": false, + "description": "For animal people.", + "entities": { + "description": { + "urls": [] + }, + "url": { + "urls": [ + { + "display_url": "thedodo.com", + "expanded_url": "http://www.thedodo.com", + "indices": [ + 0, + 23 + ], + "url": "https://t.co/vdKLF4z50p" + } + ] + } + }, + "favourites_count": 20883, + "follow_request_sent": false, + "followers_count": 2632250, + "following": false, + "friends_count": 4446, + "geo_enabled": true, + "has_extended_profile": false, + "id": 1604444052, + "id_str": "1604444052", + "is_translation_enabled": true, + "is_translator": false, + "lang": null, + "listed_count": 7063, + "location": "New York, NY", + "name": "The Dodo", + "notifications": false, + "profile_background_color": "A0E6F9", + "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", + "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", + "profile_background_tile": true, + "profile_banner_url": "https://pbs.twimg.com/profile_banners/1604444052/1619619087", + "profile_image_url": "http://pbs.twimg.com/profile_images/1542905116168056832/3QZfoNql_normal.jpg", + "profile_image_url_https": "https://pbs.twimg.com/profile_images/1542905116168056832/3QZfoNql_normal.jpg", + "profile_link_color": "FA0011", + "profile_sidebar_border_color": "FFFFFF", + "profile_sidebar_fill_color": "DDEEF6", + "profile_text_color": "333333", + "profile_use_background_image": false, + "protected": false, + "screen_name": "dodo", + "statuses_count": 79958, + "time_zone": null, + "translator_type": "none", + "url": "https://t.co/vdKLF4z50p", + "utc_offset": null, + "verified": true, + "withheld_in_countries": [] + }, + "title": " Guy Finds Starving Dog On Deserted Island " + }, + "display_url": "pic.twitter.com/CZTKmX68wh", + "expanded_url": "https://twitter.com/dodo/status/1599161556507365376/video/1", + "id": 1598448776582115328, + "id_str": "1598448776582115328", + "indices": [ + 95, + 118 + ], + "media_url": "http://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", + "media_url_https": "https://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", + "sizes": { + "large": { + "h": 1080, + "resize": "fit", + "w": 1080 + }, + "medium": { + "h": 1080, + "resize": "fit", + "w": 1080 + }, + "small": { + "h": 680, + "resize": "fit", + "w": 680 + }, + "thumb": { + "h": 150, + "resize": "crop", + "w": 150 + } + }, + "source_status_id": 1599161556507365376, + "source_status_id_str": "1599161556507365376", + "source_user_id": 1604444052, + "source_user_id_str": "1604444052", + "type": "video", + "url": "https://t.co/CZTKmX68wh", + "video_info": { + "aspect_ratio": [ + 1, + 1 + ], + "duration_millis": 212212, + "variants": [ + { + "bitrate": 1280000, + "content_type": "video/mp4", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/720x720/mn336TwuCUiapYKo.mp4?tag=16" + }, + { + "bitrate": 832000, + "content_type": "video/mp4", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/540x540/c3ysrVHaOS3gS4pV.mp4?tag=16" + }, + { + "bitrate": 8768000, + "content_type": "video/mp4", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/1080x1080/uj5eNeYYAafmOFL1.mp4?tag=16" + }, + { + "bitrate": 432000, + "content_type": "video/mp4", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/320x320/2LKcsB380YiG24b8.mp4?tag=16" + }, + { + "content_type": "application/x-mpegURL", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/pl/8ThFK3LUK7Z5dwno.m3u8?tag=16&container=fmp4" + } + ] + } + } + ] + }, + "favorite_count": 0, + "favorited": false, + "full_text": "RT @dodo: This guy found a starving dog on a beach and knew what he had to do 💙 @playforstrays https://t.co/CZTKmX68wh", + "geo": null, + "id": 1599171888076722176, + "id_str": "1599171888076722176", + "in_reply_to_screen_name": null, + "in_reply_to_status_id": null, + "in_reply_to_status_id_str": null, + "in_reply_to_user_id": null, + "in_reply_to_user_id_str": null, + "is_quote_status": false, + "lang": "en", + "place": null, + "possibly_sensitive": false, + "retweet_count": 131, + "retweeted": false, + "retweeted_status": { + "contributors": null, + "coordinates": null, + "created_at": "Sat Dec 03 22:00:00 +0000 2022", + "display_text_range": [ + 0, + 84 + ], + "entities": { + "hashtags": [], + "media": [ + { + "display_url": "pic.twitter.com/CZTKmX68wh", + "expanded_url": "https://twitter.com/dodo/status/1599161556507365376/video/1", + "id": 1598448776582115328, + "id_str": "1598448776582115328", + "indices": [ + 85, + 108 + ], + "media_url": "http://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", + "media_url_https": "https://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", + "sizes": { + "large": { + "h": 1080, + "resize": "fit", + "w": 1080 + }, + "medium": { + "h": 1080, + "resize": "fit", + "w": 1080 + }, + "small": { + "h": 680, + "resize": "fit", + "w": 680 + }, + "thumb": { + "h": 150, + "resize": "crop", + "w": 150 + } + }, + "type": "photo", + "url": "https://t.co/CZTKmX68wh" + } + ], + "symbols": [], + "urls": [], + "user_mentions": [ + { + "id": 780516438113153025, + "id_str": "780516438113153025", + "indices": [ + 70, + 84 + ], + "name": "PlayforStrays", + "screen_name": "PlayforStrays" + } + ] + }, + "extended_entities": { + "media": [ + { + "additional_media_info": { + "description": "", + "embeddable": true, + "monetizable": true, + "title": " Guy Finds Starving Dog On Deserted Island " + }, + "display_url": "pic.twitter.com/CZTKmX68wh", + "expanded_url": "https://twitter.com/dodo/status/1599161556507365376/video/1", + "id": 1598448776582115328, + "id_str": "1598448776582115328", + "indices": [ + 85, + 108 + ], + "media_url": "http://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", + "media_url_https": "https://pbs.twimg.com/media/Fi7VTHnUAAE1wRT.jpg", + "sizes": { + "large": { + "h": 1080, + "resize": "fit", + "w": 1080 + }, + "medium": { + "h": 1080, + "resize": "fit", + "w": 1080 + }, + "small": { + "h": 680, + "resize": "fit", + "w": 680 + }, + "thumb": { + "h": 150, + "resize": "crop", + "w": 150 + } + }, + "type": "video", + "url": "https://t.co/CZTKmX68wh", + "video_info": { + "aspect_ratio": [ + 1, + 1 + ], + "duration_millis": 212212, + "variants": [ + { + "bitrate": 1280000, + "content_type": "video/mp4", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/720x720/mn336TwuCUiapYKo.mp4?tag=16" + }, + { + "bitrate": 832000, + "content_type": "video/mp4", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/540x540/c3ysrVHaOS3gS4pV.mp4?tag=16" + }, + { + "bitrate": 8768000, + "content_type": "video/mp4", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/1080x1080/uj5eNeYYAafmOFL1.mp4?tag=16" + }, + { + "bitrate": 432000, + "content_type": "video/mp4", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/vid/320x320/2LKcsB380YiG24b8.mp4?tag=16" + }, + { + "content_type": "application/x-mpegURL", + "url": "https://video.twimg.com/amplify_video/1598448776582115328/pl/8ThFK3LUK7Z5dwno.m3u8?tag=16&container=fmp4" + } + ] + } + } + ] + }, + "favorite_count": 1102, + "favorited": false, + "full_text": "This guy found a starving dog on a beach and knew what he had to do 💙 @playforstrays https://t.co/CZTKmX68wh", + "geo": null, + "id": 1599161556507365376, + "id_str": "1599161556507365376", + "in_reply_to_screen_name": null, + "in_reply_to_status_id": null, + "in_reply_to_status_id_str": null, + "in_reply_to_user_id": null, + "in_reply_to_user_id_str": null, + "is_quote_status": false, + "lang": "en", + "place": null, + "possibly_sensitive": false, + "retweet_count": 131, + "retweeted": false, + "source": "Twitter Media Studio", + "truncated": false, + "user": { + "contributors_enabled": false, + "created_at": "Thu Jul 18 22:19:02 +0000 2013", + "default_profile": false, + "default_profile_image": false, + "description": "For animal people.", + "entities": { + "description": { + "urls": [] + }, + "url": { + "urls": [ + { + "display_url": "thedodo.com", + "expanded_url": "http://www.thedodo.com", + "indices": [ + 0, + 23 + ], + "url": "https://t.co/vdKLF4z50p" + } + ] + } + }, + "favourites_count": 20883, + "follow_request_sent": false, + "followers_count": 2632250, + "following": false, + "friends_count": 4446, + "geo_enabled": true, + "has_extended_profile": false, + "id": 1604444052, + "id_str": "1604444052", + "is_translation_enabled": true, + "is_translator": false, + "lang": null, + "listed_count": 7063, + "location": "New York, NY", + "name": "The Dodo", + "notifications": false, + "profile_background_color": "A0E6F9", + "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", + "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", + "profile_background_tile": true, + "profile_banner_url": "https://pbs.twimg.com/profile_banners/1604444052/1619619087", + "profile_image_url": "http://pbs.twimg.com/profile_images/1542905116168056832/3QZfoNql_normal.jpg", + "profile_image_url_https": "https://pbs.twimg.com/profile_images/1542905116168056832/3QZfoNql_normal.jpg", + "profile_link_color": "FA0011", + "profile_sidebar_border_color": "FFFFFF", + "profile_sidebar_fill_color": "DDEEF6", + "profile_text_color": "333333", + "profile_use_background_image": false, + "protected": false, + "screen_name": "dodo", + "statuses_count": 79958, + "time_zone": null, + "translator_type": "none", + "url": "https://t.co/vdKLF4z50p", + "utc_offset": null, + "verified": true, + "withheld_in_countries": [] + } + }, + "source": "Twitter Web App", + "truncated": false, + "user": { + "contributors_enabled": false, + "created_at": "Sat Jan 05 08:10:03 +0000 2013", + "default_profile": false, + "default_profile_image": false, + "description": "UX。日常推为主,摸鱼up主、@HondaJOJO 鉴定过的傻、好奇、梦多、颈椎病十级、不耐冻、漆黑意志。喜欢逛超市和公园。每天给 @wzyboy 做饭。", + "entities": { + "description": { + "urls": [] + }, + "url": { + "urls": [ + { + "display_url": "uucky.me", + "expanded_url": "https://uucky.me", + "indices": [ + 0, + 23 + ], + "url": "https://t.co/j80l9t44tU" + } + ] + } + }, + "favourites_count": 9164, + "follow_request_sent": false, + "followers_count": 2336, + "following": true, + "friends_count": 963, + "geo_enabled": true, + "has_extended_profile": true, + "id": 1062473329, + "id_str": "1062473329", + "is_translation_enabled": false, + "is_translator": false, + "lang": null, + "listed_count": 67, + "location": "海女美術大学🍁", + "name": "@uucky@o3o.ca", + "notifications": true, + "profile_background_color": "DBE9ED", + "profile_background_image_url": "http://abs.twimg.com/images/themes/theme17/bg.gif", + "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme17/bg.gif", + "profile_background_tile": false, + "profile_banner_url": "https://pbs.twimg.com/profile_banners/1062473329/1434218278", + "profile_image_url": "http://pbs.twimg.com/profile_images/1591958226446213126/lOaklion_normal.jpg", + "profile_image_url_https": "https://pbs.twimg.com/profile_images/1591958226446213126/lOaklion_normal.jpg", + "profile_link_color": "FF0066", + "profile_sidebar_border_color": "FFFFFF", + "profile_sidebar_fill_color": "E6F6F9", + "profile_text_color": "333333", + "profile_use_background_image": true, + "protected": true, + "screen_name": "Uucky_Lee", + "statuses_count": 42361, + "time_zone": null, + "translator_type": "regular", + "url": "https://t.co/j80l9t44tU", + "utc_offset": null, + "verified": false, + "withheld_in_countries": [] + } +} From 1880bf6f59d7d9711d90e25dc2b3d8cc5077364f Mon Sep 17 00:00:00 2001 From: Zhuoyun Wei Date: Wed, 9 Aug 2023 01:55:31 -0700 Subject: [PATCH 2/5] test: add test case for user dict injection --- tests/conftest.py | 1 + tests/test_views.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 4041080..08dddfe 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,6 +34,7 @@ def es_index(es_host: str) -> str: tweet_files = [ here / 'fixtures/tweet_with_photo.json', here / 'fixtures/tweet_with_video.json', + here / 'fixtures/tweet_with_bare_user_dict.json', ] for tweet_file in tweet_files: tweet = json.loads(tweet_file.read_text()) diff --git a/tests/test_views.py b/tests/test_views.py index b320f6a..f3cdc77 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -59,3 +59,22 @@ def test_fs_media(self, client): client.application.config['T_MEDIA_FS_PATH'] = './media' resp = client.get(f'/tweet/{self.tweet_id}.html') assert f'/tweet/media/pbs.twimg.com/media/{self.media_filename}' in resp.text + + +class TestUserDictInjection: + tweet_id = '1676023376631197696' + screen_name = 'alan_blake' + name = 'Test Injection Name' + profile_image_url_https = 'https://example.com/profile.png' + + def test_injection(self, client): + user_dicts = {} + user_dicts[self.screen_name] = { + 'name': self.name, + 'profile_image_url_https': self.profile_image_url_https, + } + client.application.config['T_USER_DICTS'] = user_dicts + resp = client.get(f'/tweet/{self.tweet_id}.html') + assert f'
@{self.screen_name}
' in resp.text + assert f'
{self.name}
' in resp.text + assert f' Date: Wed, 9 Aug 2023 02:04:06 -0700 Subject: [PATCH 3/5] feat: inject user dicts --- ash.py | 6 ++++++ config.sample.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/ash.py b/ash.py index 5c1662a..b45b00e 100644 --- a/ash.py +++ b/ash.py @@ -481,6 +481,12 @@ def get_tweet(tweet_id, ext): else: pass + # User dict injection + if user_dicts := app.config.get('T_USER_DICTS'): + screen_name = tweet['user']['screen_name'] + if user_dict := user_dicts.get(screen_name): + tweet['user'].update(user_dict) + # Render HTML rendered = flask.render_template( 'tweet.html', diff --git a/config.sample.py b/config.sample.py index 45c4096..663dddf 100644 --- a/config.sample.py +++ b/config.sample.py @@ -32,3 +32,12 @@ class Config: # Default user to show on index #T_DEFAULT_USER = 'jack' + + # User dict injection + # For imported tweets that has minimal `user` dict, this can be used to suppliy additional keys + T_USER_DICTS = { + 'jack': { + 'name': 'Jack Dorsey', + 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1661201415899951105/azNjKOSH_400x400.jpg', + } + } From 0d38a591f30a0a61052b67955899c861f6d7c96a Mon Sep 17 00:00:00 2001 From: Zhuoyun Wei Date: Wed, 9 Aug 2023 02:05:04 -0700 Subject: [PATCH 4/5] test: update test case --- tests/test_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_views.py b/tests/test_views.py index f3cdc77..88ad871 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,7 +1,7 @@ class TestIndexView: def test_index(self, client): resp = client.get('/tweet/') - assert '

Number of Tweets: 2' in resp.text + assert '

Number of Tweets: 3' in resp.text assert 'wzyboy' in resp.text assert 'Uucky_Lee' in resp.text From 6a9796e3f2b88395dd66bd791d39663578a42082 Mon Sep 17 00:00:00 2001 From: Zhuoyun Wei Date: Wed, 9 Aug 2023 02:06:05 -0700 Subject: [PATCH 5/5] docs: fix typo --- config.sample.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.sample.py b/config.sample.py index 663dddf..9eb6f39 100644 --- a/config.sample.py +++ b/config.sample.py @@ -11,8 +11,8 @@ class Config: # filesystem: Media files are served from T_MEDIA_FS_PATH T_MEDIA_FROM = 'direct' - # You can also use mirror domains in case your Twitter account no longer exists - # This is just simple string substitution + # You can also use mirror domains in case your Twitter account no longer + # exists. This is just simple string substitution T_MEDIA_MIRRORS = { 'pbs.twimg.com': 'd1111111111.cloudfront.net/pbs.twimg.com', 'video.twimg.com': 'd1111111111.cloudfront.net/video.twimg.com', @@ -33,8 +33,8 @@ class Config: # Default user to show on index #T_DEFAULT_USER = 'jack' - # User dict injection - # For imported tweets that has minimal `user` dict, this can be used to suppliy additional keys + # For imported tweets that has minimal `user` dict, this can be used to + # inject additional keys. T_USER_DICTS = { 'jack': { 'name': 'Jack Dorsey',