Last active
June 4, 2019 09:21
-
-
Save nnao45/7f606911d2715b4f29ebb7725a5da7ae to your computer and use it in GitHub Desktop.
validate_twitter_stream_message.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate serde; | |
extern crate serde_json as sjson; | |
extern crate twitter_stream_message; | |
use twitter_stream_message::StreamMessage; | |
fn main() { | |
let data = r#" | |
{ | |
"created_at": "Tue Jun 04 09:04:39 +0000 2019", | |
"id": 1135834739275735000, | |
"id_str": "1135834739275735040", | |
"text": "RT @GRANDPA1345: พ่อคนนี้ชอบดูดๆครับดูกันน่ะ https://t.co/ahwlt9Xmq1", | |
"source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>", | |
"truncated": false, | |
"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, | |
"in_reply_to_screen_name": null, | |
"user": { | |
"id": 1122047043306811400, | |
"id_str": "1122047043306811392", | |
"name": "PSARN", | |
"screen_name": "PSARN2", | |
"location": null, | |
"url": null, | |
"description": "6เชน", | |
"translator_type": "none", | |
"protected": false, | |
"verified": false, | |
"followers_count": 1, | |
"friends_count": 81, | |
"listed_count": 0, | |
"favourites_count": 0, | |
"statuses_count": 18, | |
"created_at": "Sat Apr 27 07:57:16 +0000 2019", | |
"utc_offset": null, | |
"time_zone": null, | |
"geo_enabled": false, | |
"lang": null, | |
"contributors_enabled": false, | |
"is_translator": false, | |
"profile_background_color": "F5F8FA", | |
"profile_background_image_url": "", | |
"profile_background_image_url_https": "", | |
"profile_background_tile": false, | |
"profile_link_color": "1DA1F2", | |
"profile_sidebar_border_color": "C0DEED", | |
"profile_sidebar_fill_color": "DDEEF6", | |
"profile_text_color": "333333", | |
"profile_use_background_image": true, | |
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png", | |
"profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png", | |
"default_profile": true, | |
"default_profile_image": false, | |
"following": null, | |
"follow_request_sent": null, | |
"notifications": null | |
}, | |
"geo": null, | |
"coordinates": null, | |
"place": null, | |
"contributors": null, | |
"retweeted_status": { | |
"created_at": "Wed Nov 21 04:27:43 +0000 2018", | |
"id": 1065099412035129300, | |
"id_str": "1065099412035129345", | |
"text": "พ่อคนนี้ชอบดูดๆครับดูกันน่ะ https://t.co/ahwlt9Xmq1", | |
"display_text_range": [ | |
0, | |
27 | |
], | |
"source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>", | |
"truncated": false, | |
"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, | |
"in_reply_to_screen_name": null, | |
"user": { | |
"id": 858856007975395300, | |
"id_str": "858856007975395328", | |
"name": "ชอบคนแก่ๆเพราะว่าคนแก่ๆน่ารักมากๆ", | |
"screen_name": "GRANDPA1345", | |
"location": "ประเทศไทย", | |
"url": null, | |
"description": "ชอบคนแก่บ้านๆครับ", | |
"translator_type": "none", | |
"protected": false, | |
"verified": false, | |
"followers_count": 38548, | |
"friends_count": 840, | |
"listed_count": 106, | |
"favourites_count": 564, | |
"statuses_count": 3371, | |
"created_at": "Mon May 01 01:30:03 +0000 2017", | |
"utc_offset": null, | |
"time_zone": null, | |
"geo_enabled": true, | |
"lang": null, | |
"contributors_enabled": false, | |
"is_translator": false, | |
"profile_background_color": "F5F8FA", | |
"profile_background_image_url": "", | |
"profile_background_image_url_https": "", | |
"profile_background_tile": false, | |
"profile_link_color": "1DA1F2", | |
"profile_sidebar_border_color": "C0DEED", | |
"profile_sidebar_fill_color": "DDEEF6", | |
"profile_text_color": "333333", | |
"profile_use_background_image": true, | |
"profile_image_url": "http://pbs.twimg.com/profile_images/1107946296017477632/RDTeVVll_normal.jpg", | |
"profile_image_url_https": "https://pbs.twimg.com/profile_images/1107946296017477632/RDTeVVll_normal.jpg", | |
"profile_banner_url": "https://pbs.twimg.com/profile_banners/858856007975395328/1552990049", | |
"default_profile": true, | |
"default_profile_image": false, | |
"following": null, | |
"follow_request_sent": null, | |
"notifications": null | |
}, | |
"geo": null, | |
"coordinates": null, | |
"place": null, | |
"contributors": null, | |
"is_quote_status": false, | |
"quote_count": 1, | |
"reply_count": 4, | |
"retweet_count": 310, | |
"favorite_count": 676, | |
"entities": { | |
"hashtags": [], | |
"urls": [], | |
"user_mentions": [], | |
"symbols": [], | |
"media": [ | |
{ | |
"id": 1065098839592300500, | |
"id_str": "1065098839592300545", | |
"indices": [ | |
28, | |
51 | |
], | |
"additional_media_info": { | |
"monetizable": false | |
}, | |
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/1065098839592300545/pu/img/txjuUc_xNElETCv9.jpg", | |
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/1065098839592300545/pu/img/txjuUc_xNElETCv9.jpg", | |
"url": "https://t.co/ahwlt9Xmq1", | |
"display_url": "pic.twitter.com/ahwlt9Xmq1", | |
"expanded_url": "https://twitter.com/Nitinai12436455/status/1065099412035129345/video/1", | |
"type": "photo", | |
"sizes": { | |
"thumb": { | |
"w": 150, | |
"h": 150, | |
"resize": "crop" | |
}, | |
"small": { | |
"w": 378, | |
"h": 680, | |
"resize": "fit" | |
}, | |
"large": { | |
"w": 400, | |
"h": 720, | |
"resize": "fit" | |
}, | |
"medium": { | |
"w": 400, | |
"h": 720, | |
"resize": "fit" | |
} | |
} | |
} | |
] | |
}, | |
"extended_entities": { | |
"media": [ | |
{ | |
"id": 1065098839592300500, | |
"id_str": "1065098839592300545", | |
"indices": [ | |
28, | |
51 | |
], | |
"additional_media_info": { | |
"monetizable": false | |
}, | |
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/1065098839592300545/pu/img/txjuUc_xNElETCv9.jpg", | |
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/1065098839592300545/pu/img/txjuUc_xNElETCv9.jpg", | |
"url": "https://t.co/ahwlt9Xmq1", | |
"display_url": "pic.twitter.com/ahwlt9Xmq1", | |
"expanded_url": "https://twitter.com/Nitinai12436455/status/1065099412035129345/video/1", | |
"type": "video", | |
"video_info": { | |
"aspect_ratio": [ | |
5, | |
9 | |
], | |
"duration_millis": 88000, | |
"variants": [ | |
{ | |
"bitrate": 256000, | |
"content_type": "video/mp4", | |
"url": "https://video.twimg.com/ext_tw_video/1065098839592300545/pu/vid/180x324/D8807XBbFBajvrK_.mp4?tag=5" | |
}, | |
{ | |
"bitrate": 832000, | |
"content_type": "video/mp4", | |
"url": "https://video.twimg.com/ext_tw_video/1065098839592300545/pu/vid/400x720/sMjzNdshzwbCbnAB.mp4?tag=5" | |
}, | |
{ | |
"content_type": "application/x-mpegURL", | |
"url": "https://video.twimg.com/ext_tw_video/1065098839592300545/pu/pl/d5qE6i5h_mjI5poS.m3u8?tag=5" | |
} | |
] | |
}, | |
"sizes": { | |
"thumb": { | |
"w": 150, | |
"h": 150, | |
"resize": "crop" | |
}, | |
"small": { | |
"w": 378, | |
"h": 680, | |
"resize": "fit" | |
}, | |
"large": { | |
"w": 400, | |
"h": 720, | |
"resize": "fit" | |
}, | |
"medium": { | |
"w": 400, | |
"h": 720, | |
"resize": "fit" | |
} | |
} | |
} | |
] | |
}, | |
"favorited": false, | |
"retweeted": false, | |
"possibly_sensitive": false, | |
"filter_level": "low", | |
"lang": "th" | |
}, | |
"is_quote_status": false, | |
"quote_count": 0, | |
"reply_count": 0, | |
"retweet_count": 0, | |
"favorite_count": 0, | |
"entities": { | |
"hashtags": [], | |
"urls": [], | |
"user_mentions": [ | |
{ | |
"screen_name": "GRANDPA1345", | |
"name": "ชอบคนแก่ๆเพราะว่าคนแก่ๆน่ารักมากๆ", | |
"id": 858856007975395300, | |
"id_str": "858856007975395328", | |
"indices": [ | |
3, | |
15 | |
] | |
} | |
], | |
"symbols": [], | |
"media": [ | |
{ | |
"id": 1065098839592300500, | |
"id_str": "1065098839592300545", | |
"indices": [ | |
45, | |
68 | |
], | |
"additional_media_info": { | |
"monetizable": false | |
}, | |
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/1065098839592300545/pu/img/txjuUc_xNElETCv9.jpg", | |
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/1065098839592300545/pu/img/txjuUc_xNElETCv9.jpg", | |
"url": "https://t.co/ahwlt9Xmq1", | |
"display_url": "pic.twitter.com/ahwlt9Xmq1", | |
"expanded_url": "https://twitter.com/Nitinai12436455/status/1065099412035129345/video/1", | |
"type": "photo", | |
"sizes": { | |
"thumb": { | |
"w": 150, | |
"h": 150, | |
"resize": "crop" | |
}, | |
"small": { | |
"w": 378, | |
"h": 680, | |
"resize": "fit" | |
}, | |
"large": { | |
"w": 400, | |
"h": 720, | |
"resize": "fit" | |
}, | |
"medium": { | |
"w": 400, | |
"h": 720, | |
"resize": "fit" | |
} | |
}, | |
"source_status_id": 1065099412035129300, | |
"source_status_id_str": "1065099412035129345", | |
"source_user_id": 858856007975395300, | |
"source_user_id_str": "858856007975395328" | |
} | |
] | |
}, | |
"extended_entities": { | |
"media": [ | |
{ | |
"id": 1065098839592300500, | |
"id_str": "1065098839592300545", | |
"indices": [ | |
45, | |
68 | |
], | |
"additional_media_info": { | |
"monetizable": false | |
}, | |
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/1065098839592300545/pu/img/txjuUc_xNElETCv9.jpg", | |
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/1065098839592300545/pu/img/txjuUc_xNElETCv9.jpg", | |
"url": "https://t.co/ahwlt9Xmq1", | |
"display_url": "pic.twitter.com/ahwlt9Xmq1", | |
"expanded_url": "https://twitter.com/Nitinai12436455/status/1065099412035129345/video/1", | |
"type": "video", | |
"video_info": { | |
"aspect_ratio": [ | |
5, | |
9 | |
], | |
"duration_millis": 88000, | |
"variants": [ | |
{ | |
"bitrate": 256000, | |
"content_type": "video/mp4", | |
"url": "https://video.twimg.com/ext_tw_video/1065098839592300545/pu/vid/180x324/D8807XBbFBajvrK_.mp4?tag=5" | |
}, | |
{ | |
"bitrate": 832000, | |
"content_type": "video/mp4", | |
"url": "https://video.twimg.com/ext_tw_video/1065098839592300545/pu/vid/400x720/sMjzNdshzwbCbnAB.mp4?tag=5" | |
}, | |
{ | |
"content_type": "application/x-mpegURL", | |
"url": "https://video.twimg.com/ext_tw_video/1065098839592300545/pu/pl/d5qE6i5h_mjI5poS.m3u8?tag=5" | |
} | |
] | |
}, | |
"sizes": { | |
"thumb": { | |
"w": 150, | |
"h": 150, | |
"resize": "crop" | |
}, | |
"small": { | |
"w": 378, | |
"h": 680, | |
"resize": "fit" | |
}, | |
"large": { | |
"w": 400, | |
"h": 720, | |
"resize": "fit" | |
}, | |
"medium": { | |
"w": 400, | |
"h": 720, | |
"resize": "fit" | |
} | |
}, | |
"source_status_id": 1065099412035129300, | |
"source_status_id_str": "1065099412035129345", | |
"source_user_id": 858856007975395300, | |
"source_user_id_str": "858856007975395328" | |
} | |
] | |
}, | |
"favorited": false, | |
"retweeted": false, | |
"possibly_sensitive": false, | |
"filter_level": "low", | |
"lang": "th", | |
"timestamp_ms": "1559639079289" | |
} | |
"#; | |
match sjson::from_str(data) { | |
Ok(StreamMessage::Tweet(tweet)) => { | |
println!( | |
"On {}, @{} tweeted: {:?}", | |
tweet.created_at, tweet.user.screen_name, tweet.text | |
); | |
}, | |
Err(e) => println!("maybe error occured, error: {:?}", e), | |
_ => println!("maybe error occured, but i dont know"), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment