{"id":43063,"date":"2022-10-31T18:48:00","date_gmt":"2022-10-31T09:48:00","guid":{"rendered":"https:\/\/happy-man.jp\/?p=43063"},"modified":"2022-10-30T14:30:10","modified_gmt":"2022-10-30T05:30:10","slug":"post-43063","status":"publish","type":"post","link":"https:\/\/happy-man.jp\/?p=43063","title":{"rendered":"Twitter\u306e\u30d5\u30a9\u30ed\u30fc&#038;RT\u30ad\u30e3\u30f3\u30da\u30fc\u30f3\u306b\u81ea\u52d5\u53c2\u52a0\u3057\u3066\u307f\u305f\u304f\u306a\u3063\u305f\u306e\u3067python+tweepy\u30b3\u30fc\u30c9\u3067\u3084\u3063\u3066\u307f\u305f"},"content":{"rendered":"<p>\u6c17\u306b\u306a\u308b\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u30ea\u30b9\u30c8\u30a4\u30f3\u306e\u30b3\u30fc\u30c9\u3092\u30d1\u30af\u3063\u305f\u3089\u3001\u3053\u3063\u3061\u3082\u51fa\u6765\u308b\u3093\u3058\u3083\u7121\u3044\u304b\uff1f\u3068\u3084\u3063\u3066\u307f\u305f\u3002<\/p>\n<p>\u3053\u306e\u30cd\u30bf\u306f\u3042\u3063\u3061\u3053\u3063\u3061\u3067\u8ee2\u304c\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3001\u540c\u3058\u4e8b\u3092\u8003\u3048\u3066\u3044\u308b\u4eba\u304c\u591a\u3044\u3088\u3046\u3060\u3002<\/p>\n<p>\u307e\u3042\u305d\u3046\u8a00\u3046\u308f\u3051\u3067\u3084\u3063\u3066\u307f\u308b\u3002<\/p>\n<p><a href=\"https:\/\/happy-man.jp\/?p=43058\">Twitter\u3067\u3044\u308d\u3093\u306a\u60c5\u5831\u3092\u96c6\u3081\u305f\u3044\u306e\u3067\u3001\u81ea\u52d5\u30d5\u30a9\u30ed\u30fc\u3068\u30ea\u30b9\u30c8\u30a4\u30f3\u3092python+tweepy\u30b3\u30fc\u30c9\u3092\u30d1\u30af\u3063\u3066\u307f\u305f &#8211; happyman web<\/a><\/p>\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code><\/code><\/pre>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code>import tweepy\r\nimport time\r\n# API\u60c5\u5831\uff08API1.1\uff09\u3092\u8a18\u5165\r\nconsumer_key=' '\r\nconsumer_secret=' '\r\nACCESS_TOKEN=' '\r\nACCESS_TOKEN_SECRET=' '\r\n\r\n#API\u3000V1.1\u8a8d\u8a3c\r\nauth = tweepy.OAuthHandler(\"consumer_key\",\"consumer_secret\")\r\nauth.set_access_token(\"ACCESS_TOKEN\",\"ACCESS_TOKEN_SECRET\")\r\napi = tweepy.API(auth) \r\n\r\n#\u691c\u7d22\u3057\u305f\u3044\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u3044\u308c\u308b\u3002\u3082\u3057\u304f\u306f\u306fOR\u306b\u3057\u3066\u3084\u308c\u3070\u826f\u3044\u307f\u305f\u3044\u3002\r\nquery = \"\u3000\u3092RT\u3068\u304b\u3000\u8272\u3005\u8003\u3048\u3066\u5165\u308c\u308b\u3002\u30d5\u30a3\u30eb\u30bf\u30fc\u3082\u3057\u305f\u65b9\u304c\u826f\u3055\u305d\u3046\u3002\" \r\n\r\n#CRON\u3067\u5b9a\u671f\u7684\u306b\u52d5\u304b\u3059\u306e\u3067\u30d0\u30f3\u5bfe\u7b56\u306b\u30ab\u30a6\u30f3\u30c8\u5c11\u306a\u3081\u306b\u3057\u305f\u3002\r\n#\u691c\u7d22\u65b9\u6cd5\u306f\u65b0\u3057\u3044\u3082\u306e\uff08recent\uff09\u3001\u4eba\u6c17\u306a\u3082\u306e\uff08popular\uff09\u3068\u6df7\u5728\u578b\uff08mixed\uff09\u304c\u3042\u308b\u3089\u3057\u3044\u3002\r\nresults = api.search_tweets(q=query,result_type='mixed',count=10)\r\n\r\n#\u5b9f\u884c\r\nfor result in results:\r\n \u3000\u3000#\u691c\u7d22\u7d50\u679c\u3067\u30e6\u30fc\u30b6\u30fc\u3092\u62bd\u51fa\r\n \u3000\u3000screen_name = result.user.screen_name\r\n \u3000\u3000print('@' + screen_name + '\u3092\u30d5\u30a9\u30ed\u30fc\u51e6\u7406\u4e2d...')\r\n \u3000\u3000for i in range(3): #RateLimit\u306b\u304b\u304b\u3063\u305f\u30893\u56de\u307e\u3067\u30ea\u30c8\u30e9\u30a4\r\n \u3000\u3000\u3000\u3000try:\r\n \u3000\u3000\u3000\u3000\u3000\u3000if result.lang == 'ja':\u3000#\u65e5\u672c\u8a9e\u30e6\u30fc\u30b6\u30fc\u304b\u3069\u3046\u304b\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\r\n \u3000\u3000\u3000\u3000\u3000\u3000\u3000api.create_friendship(screen_name=screen_name)\u3000#\u30d5\u30a9\u30ed\u30fc\u3059\u308b\r\n \u3000\u3000\u3000\u3000\u3000\u3000\u3000api.add_list_member(screen_name=screen_name,list_id=\"\u30ea\u30b9\u30c8\u756a\u53f7\") #\u30ea\u30b9\u30c8\u306b\u305d\u306e\u30c4\u30a4\u30fc\u30c8\u306e\u30e6\u30fc\u30b6\u540d\u3092\u8ffd\u52a0\u3059\u308b\r\n \u3000\u3000\u3000\u3000\u3000\u3000\u3000print('@' + screen_name + '\u3055\u3093\u306e\u30d5\u30a9\u30ed\u30fc\u306b\u6210\u529f\u3057\u307e\u3057\u305f\u3002')\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u3000\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000try: \r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000api.retweet(tweet_id) #\u30ea\u30c4\u30a4\u30fc\u30c8\u3057\u3066\u3084\u308b\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 except\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000Exception as e: print(e)\r\n \u3000\u3000\u3000\u3000\u3000\u3000else:\r\n \u3000\u3000\u3000\u3000\u3000\u3000\u3000print('@' + screen_name + '\u3055\u3093\u306f\u65e5\u672c\u8a9e\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002') \r\n\r\n\u3000\u3000\u3000\u3000\u3000\u3000except tweepy.TweepError as e:\u3000#\u30a8\u30e9\u30fc\u306f\u3053\u3063\u3061\u3067\u51e6\u7406\uff08\u3053\u306e\u8fba\u306e\u7406\u89e3\u304c\u307e\u3060\u3067\u304d\u3066\u306a\u3044\uff09\r\n \u3000\u3000\u3000\u3000\u3000\u3000if e.reason == \"[{'message': 'Rate limit exceeded', 'code': 88}]\":\r\n \u3000\u3000\u3000\u3000\u3000\u3000\u3000print(e)\r\n \u3000\u3000\u3000\u3000\u3000\u3000\u3000time.sleep(15 * 60) #15\u5206\u5f85\u6a5f\r\n \u3000\u3000\u3000\u3000\u3000\u3000else:\r\n \u3000\u3000\u3000\u3000\u3000\u3000\u3000break\r\n \u3000\u3000\u3000else:\r\n \u3000\u3000\u3000\u3000time.sleep(5)\u3000#5\u79d2\u304a\u304f\r\n\u3000\u3000\u3000\u3000\u3000break<\/code><\/pre>\n<\/div>\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code><\/code><\/pre>\n<p style=\"font-family: Helvetica, Arial, sans-serif; white-space: normal;\">\u30ea\u30c4\u30a4\u30fc\u30c8\u306e\u90e8\u5206\u306f\u30ea\u30c4\u30a4\u30fc\u30c8\u304c\u4f55\u5ea6\u3082\u51fa\u6765\u306a\u304f\u3066\u843d\u3061\u308b\u306e\u3067\u3001\u300cexcept Exception as e:\u300d\u3067\u9003\u304c\u3057\u3066\u307f\u305f\u3002<\/p>\n<p style=\"font-family: Helvetica, Arial, sans-serif; white-space: normal;\">\u3053\u306e\u30cd\u30bf\u306f\u691c\u7d22\u30ef\u30fc\u30c9\u3068\u30d5\u30a3\u30eb\u30bf\u30fc\u304c\u5de5\u592b\u304c\u8981\u308b\u3088\u3046\u3067\u3001\u30d5\u30a3\u30c3\u30b7\u30f3\u30b0\u30a2\u30ab\u30a6\u30f3\u30c8\u307e\u3067\u62fe\u3063\u3066\u30ea\u30c4\u30a4\u30fc\u30c8\u3057\u3066\u3057\u307e\u3044\u304b\u306d\u306a\u3044\u306e\u3067\u3001\u306a\u304b\u306a\u304b\u96e3\u3057\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6c17\u306b\u306a\u308b\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u30ea\u30b9\u30c8\u30a4\u30f3\u306e\u30b3\u30fc\u30c9\u3092\u30d1\u30af\u3063\u305f\u3089\u3001\u3053\u3063\u3061\u3082\u51fa\u6765\u308b\u3093\u3058\u3083\u7121\u3044\u304b\uff1f\u3068\u3084\u3063\u3066\u307f\u305f\u3002 \u3053\u306e\u30cd\u30bf\u306f\u3042\u3063\u3061\u3053\u3063\u3061\u3067\u8ee2\u304c\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3001\u540c\u3058\u4e8b\u3092\u8003\u3048\u3066\u3044\u308b\u4eba\u304c\u591a\u3044\u3088\u3046\u3060\u3002 \u307e\u3042\u305d\u3046\u8a00\u3046\u308f\u3051\u3067\u3084\u3063\u3066\u307f\u308b\u3002  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"_lightning_design_setting":[],"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[31,27,141,142],"tags":[],"class_list":["post-43063","post","type-post","status-publish","format-standard","hentry","category-linux-mint","category-liva","category-python","category-tweepy"],"jetpack_publicize_connections":[],"jetpack-related-posts":[{"id":43058,"url":"https:\/\/happy-man.jp\/?p=43058","url_meta":{"origin":43063,"position":0},"title":"Twitter\u3067\u3044\u308d\u3093\u306a\u60c5\u5831\u3092\u96c6\u3081\u305f\u3044\u306e\u3067\u3001\u81ea\u52d5\u30d5\u30a9\u30ed\u30fc\u3068\u30ea\u30b9\u30c8\u30a4\u30f3\u3092python+tweepy\u30b3\u30fc\u30c9\u3092\u30d1\u30af\u3063\u3066\u307f\u305f","author":"happyman","date":"2022\u5e7410\u670830\u65e5","format":false,"excerpt":"\u3053\u3046\u3044\u3046\u3053\u3068\u3092Twitter\u3067\u3084\u308b\u3068\u30a2\u30ab\u30a6\u30f3\u30c8BAN\u306b\u306a\u308b\u306e\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u304c\u3001TL\u304b\u3089\u3044\u308d\u3093\u306a\u60c5\u5831\u3092\u2026","rel":"","context":"Linux mint","block_context":{"text":"Linux mint","link":"https:\/\/happy-man.jp\/?cat=31"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":42929,"url":"https:\/\/happy-man.jp\/?p=42929","url_meta":{"origin":43063,"position":1},"title":"LIVA\u541b\uff08liva-c0-2g-32g-w-os\uff09\u3092\u4f7f\u3063\u3066Python+tweepy\u3092\u3084\u3063\u3066\u307f\u308b","author":"happyman","date":"2022\u5e7410\u670817\u65e5","format":false,"excerpt":"Python\u3092\u4f7f\u3063\u3066Twitter\u3092\u30a2\u30ec\u30b3\u30ec\u3067\u304d\u308b\u306a\u3093\u3066\u8a71\u3092\u805e\u3044\u3066\u3044\u305f\u306e\u3067\u3001\u3061\u3087\u3063\u3068\u904a\u3093\u3067\u307f\u3088\u3046\u304b\u3068\u2026","rel":"","context":"Linux mint","block_context":{"text":"Linux mint","link":"https:\/\/happy-man.jp\/?cat=31"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2022\/10\/6604e22a49d3d4d78dd57e33923cfd54.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2022\/10\/6604e22a49d3d4d78dd57e33923cfd54.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2022\/10\/6604e22a49d3d4d78dd57e33923cfd54.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2022\/10\/6604e22a49d3d4d78dd57e33923cfd54.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":42959,"url":"https:\/\/happy-man.jp\/?p=42959","url_meta":{"origin":43063,"position":2},"title":"LIVA\u541b\uff08LINUX MINT\uff09\u304b\u3089Python+tweepy+cron\u3067\u6642\u5831\u3092\u304a\u77e5\u3089\u305b\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f","author":"happyman","date":"2022\u5e7410\u670819\u65e5","format":false,"excerpt":"cron\u3067\u6240\u5b9a\u306e\u6642\u9593\u306b\u30c4\u30a4\u30fc\u30c8\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3089\u6b32\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002 LIVA\u541b\uff08LINUX MIN\u2026","rel":"","context":"Linux mint","block_context":{"text":"Linux mint","link":"https:\/\/happy-man.jp\/?cat=31"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2022\/10\/SnapCrab_NoName_2022-10-16_12-53-46_No-00.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2022\/10\/SnapCrab_NoName_2022-10-16_12-53-46_No-00.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2022\/10\/SnapCrab_NoName_2022-10-16_12-53-46_No-00.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2022\/10\/SnapCrab_NoName_2022-10-16_12-53-46_No-00.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":43070,"url":"https:\/\/happy-man.jp\/?p=43070","url_meta":{"origin":43063,"position":3},"title":"Twitter\u3067\u3001\u81ea\u52d5\u30ea\u30d7\u30e9\u30a4\uff08V2\uff09\u3057\u305f\u304f\u306a\u3063\u305f\u306e\u3067\u3001Python+tweepy\u3067\u3084\u3063\u3066\u307f\u305f\u3002","author":"happyman","date":"2022\u5e7411\u67081\u65e5","format":false,"excerpt":"\u3044\u307e\u307e\u3067\u4e00\u65b9\u901a\u884c\u306b\u8a71\u3059\u308b\u3060\u3051\u3060\u3063\u305f\u300c\u306f\u3074\u305e\u3046\u300d\u541b\u306a\u3093\u3060\u304c\u3001\u30ea\u30d7\u30e9\u30a4\u3057\u3066\u304d\u305f\u3089\u4f55\u304b\u8fd4\u4e8b\u3092\u3057\u305f\u304f\u306a\u3063\u305f\u306e\u2026","rel":"","context":"Linux mint","block_context":{"text":"Linux mint","link":"https:\/\/happy-man.jp\/?cat=31"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":43105,"url":"https:\/\/happy-man.jp\/?p=43105","url_meta":{"origin":43063,"position":4},"title":"\u306f\u3074\u305e\u3046\u541b\u3067Tweepy\u81ea\u52d5\u30ea\u30d7\u30e9\u30a4\uff08V2\uff09\u3059\u308b\u5185\u5bb9\u3092\u307b\u3093\u306e\u3061\u3087\u3063\u3068\u3060\u3051\u8ce2\u304f\u3057\u3066\u307f\u305f","author":"happyman","date":"2022\u5e7411\u67086\u65e5","format":false,"excerpt":"\u306f\u3074\u305e\u3046\u541b\uff08@haptweepy\uff09\u306b\u4f55\u304b\u8a71\u3057\u304b\u3051\u305f\u3089\u8fd4\u4e8b\u3092\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002 Twitter\u3067\u3001\u81ea\u52d5\u2026","rel":"","context":"Linux mint","block_context":{"text":"Linux mint","link":"https:\/\/happy-man.jp\/?cat=31"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":43738,"url":"https:\/\/happy-man.jp\/?p=43738","url_meta":{"origin":43063,"position":5},"title":"TwitterAPI\u7121\u6599\u30b5\u30dd\u30fc\u30c8\u3092\u5168\u9762\u505c\u6b62\u3059\u308b\u3089\u3057\u3044\u306e\u3067\u3001Tweepy\u3092\u4f7f\u3063\u3066\u3044\u308b\u306f\u3074\u305e\u3046\u541b\u306f\u304a\u4ea1\u304f\u306a\u308a\u306b\u306a\u308b\u3088\u3046\u3060\u3002","author":"happyman","date":"2023\u5e742\u67084\u65e5","format":false,"excerpt":"\u3042\u3041\u3053\u308c\u304c\u6765\u308b\u3068\u3001\u307e\u3042\u304a\u3058\u3055\u3093\u306e\u304a\u53cb\u9054\u306f\u505c\u6b62\u3057\u3066\u3057\u307e\u3046\u306a\u3002 Twitter\u30012\u67089\u65e5\u4ee5\u964d\u300cTwitt\u2026","rel":"","context":"Python","block_context":{"text":"Python","link":"https:\/\/happy-man.jp\/?cat=141"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2023\/02\/SnapCrab_NoName_2023-2-4_6-1-9_No-00.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2023\/02\/SnapCrab_NoName_2023-2-4_6-1-9_No-00.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/happy-man.jp\/wp-content\/uploads\/2023\/02\/SnapCrab_NoName_2023-2-4_6-1-9_No-00.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/happy-man.jp\/index.php?rest_route=\/wp\/v2\/posts\/43063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/happy-man.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/happy-man.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/happy-man.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/happy-man.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=43063"}],"version-history":[{"count":6,"href":"https:\/\/happy-man.jp\/index.php?rest_route=\/wp\/v2\/posts\/43063\/revisions"}],"predecessor-version":[{"id":43069,"href":"https:\/\/happy-man.jp\/index.php?rest_route=\/wp\/v2\/posts\/43063\/revisions\/43069"}],"wp:attachment":[{"href":"https:\/\/happy-man.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/happy-man.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=43063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/happy-man.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=43063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}