[{"data":1,"prerenderedAt":1198},["ShallowReactive",2],{"tag-twitter":3},[4],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"date":11,"layout":12,"subtitle":10,"image":13,"optimized_image":13,"category":14,"tags":15,"author":19,"paginate":7,"body":20,"_type":1192,"_id":1193,"_source":1194,"_file":1195,"_stem":1196,"_extension":1197},"/posts/how-to-create-a-twitter-bot","posts",false,"","How to create a Twitter bot","Step by step creation of a twitter bot","2020-12-06T11:00:00.000Z","post","/assets/img/uploads/twitter.jpg","algorithms",[16,17,18],"bots","twitter","python","jaimedearcos",{"type":21,"children":22,"toc":1181},"root",[23,32,45,58,66,73,79,91,164,176,388,393,412,418,423,433,565,571,595,601,734,740,745,765,1131,1142,1146,1152,1172,1175],{"type":24,"tag":25,"props":26,"children":28},"element","h2",{"id":27},"_1-request-your-developer-account-create-your-first-app",[29],{"type":30,"value":31},"text","1. Request your developer account & create your first app",{"type":24,"tag":33,"props":34,"children":35},"p",{},[36,38],{"type":30,"value":37},"The first step of building twitter bots is to request access to developer features, this can be done easily\nin ",{"type":24,"tag":39,"props":40,"children":43},"a",{"href":41,"target":42},"developer.twitter.com","_blank",[44],{"type":30,"value":41},{"type":24,"tag":33,"props":46,"children":47},{},[48,50,56],{"type":30,"value":49},"Once you have fill the form to request access, you can log in the ",{"type":24,"tag":51,"props":52,"children":53},"strong",{},[54],{"type":30,"value":55},"twitter console",{"type":30,"value":57}," to retrieve the access keys:",{"type":24,"tag":33,"props":59,"children":60},{},[61],{"type":24,"tag":62,"props":63,"children":65},"img",{"alt":8,"src":64},"/assets/img/uploads/twitter-dashboard.png",[],{"type":24,"tag":33,"props":67,"children":68},{},[69],{"type":24,"tag":62,"props":70,"children":72},{"alt":8,"src":71},"/assets/img/uploads/twitter-tokens.png",[],{"type":24,"tag":25,"props":74,"children":76},{"id":75},"_2-set-up-dev-environment",[77],{"type":30,"value":78},"2. Set-up dev environment",{"type":24,"tag":33,"props":80,"children":81},{},[82,84,89],{"type":30,"value":83},"We are going to use ",{"type":24,"tag":51,"props":85,"children":86},{},[87],{"type":30,"value":88},"Tweepy",{"type":30,"value":90},", a python library to facilitate the communication with twitter API. To create the python\nenvironment and install Tweepy we need to execute the following commands:",{"type":24,"tag":92,"props":93,"children":97},"pre",{"className":94,"code":95,"language":96,"meta":8,"style":8},"language-bash shiki shiki-themes github-dark github-light","python3 -m venv venv\nsource ./venv/bin/activate\npip install tweepy\n","bash",[98],{"type":24,"tag":99,"props":100,"children":101},"code",{"__ignoreMap":8},[102,131,145],{"type":24,"tag":103,"props":104,"children":107},"span",{"class":105,"line":106},"line",1,[108,114,120,126],{"type":24,"tag":103,"props":109,"children":111},{"style":110},"--shiki-default:#B392F0;--shiki-light:#6F42C1",[112],{"type":30,"value":113},"python3",{"type":24,"tag":103,"props":115,"children":117},{"style":116},"--shiki-default:#79B8FF;--shiki-light:#005CC5",[118],{"type":30,"value":119}," -m",{"type":24,"tag":103,"props":121,"children":123},{"style":122},"--shiki-default:#9ECBFF;--shiki-light:#032F62",[124],{"type":30,"value":125}," venv",{"type":24,"tag":103,"props":127,"children":128},{"style":122},[129],{"type":30,"value":130}," venv\n",{"type":24,"tag":103,"props":132,"children":134},{"class":105,"line":133},2,[135,140],{"type":24,"tag":103,"props":136,"children":137},{"style":116},[138],{"type":30,"value":139},"source",{"type":24,"tag":103,"props":141,"children":142},{"style":122},[143],{"type":30,"value":144}," ./venv/bin/activate\n",{"type":24,"tag":103,"props":146,"children":148},{"class":105,"line":147},3,[149,154,159],{"type":24,"tag":103,"props":150,"children":151},{"style":110},[152],{"type":30,"value":153},"pip",{"type":24,"tag":103,"props":155,"children":156},{"style":122},[157],{"type":30,"value":158}," install",{"type":24,"tag":103,"props":160,"children":161},{"style":122},[162],{"type":30,"value":163}," tweepy\n",{"type":24,"tag":33,"props":165,"children":166},{},[167,169,174],{"type":30,"value":168},"After that we need to create our first python script to verify keys and environment (",{"type":24,"tag":51,"props":170,"children":171},{},[172],{"type":30,"value":173},"test-credentials.py",{"type":30,"value":175},")",{"type":24,"tag":92,"props":177,"children":180},{"className":178,"code":179,"language":18,"meta":8,"style":8},"language-python shiki shiki-themes github-dark github-light","import tweepy\n\n# Authentication\nauth = tweepy.OAuthHandler(\"CONSUMER_API_KEY\", \"CONSUMER_API_SECRET\")\nauth.set_access_token(\"ACCESS_TOKEN\", \"ACCESS_TOKEN_SECRET\")\napi = tweepy.API(auth)\n\ntry:\n    api.verify_credentials()\n    print(\"Authentication OK\")\nexcept:\n    print(\"Error during authentication\")\n",[181],{"type":24,"tag":99,"props":182,"children":183},{"__ignoreMap":8},[184,198,207,216,255,282,300,308,322,331,354,367],{"type":24,"tag":103,"props":185,"children":186},{"class":105,"line":106},[187,193],{"type":24,"tag":103,"props":188,"children":190},{"style":189},"--shiki-default:#F97583;--shiki-light:#D73A49",[191],{"type":30,"value":192},"import",{"type":24,"tag":103,"props":194,"children":196},{"style":195},"--shiki-default:#E1E4E8;--shiki-light:#24292E",[197],{"type":30,"value":163},{"type":24,"tag":103,"props":199,"children":200},{"class":105,"line":133},[201],{"type":24,"tag":103,"props":202,"children":204},{"emptyLinePlaceholder":203},true,[205],{"type":30,"value":206},"\n",{"type":24,"tag":103,"props":208,"children":209},{"class":105,"line":147},[210],{"type":24,"tag":103,"props":211,"children":213},{"style":212},"--shiki-default:#6A737D;--shiki-light:#6A737D",[214],{"type":30,"value":215},"# Authentication\n",{"type":24,"tag":103,"props":217,"children":219},{"class":105,"line":218},4,[220,225,230,235,240,245,250],{"type":24,"tag":103,"props":221,"children":222},{"style":195},[223],{"type":30,"value":224},"auth ",{"type":24,"tag":103,"props":226,"children":227},{"style":189},[228],{"type":30,"value":229},"=",{"type":24,"tag":103,"props":231,"children":232},{"style":195},[233],{"type":30,"value":234}," tweepy.OAuthHandler(",{"type":24,"tag":103,"props":236,"children":237},{"style":122},[238],{"type":30,"value":239},"\"CONSUMER_API_KEY\"",{"type":24,"tag":103,"props":241,"children":242},{"style":195},[243],{"type":30,"value":244},", ",{"type":24,"tag":103,"props":246,"children":247},{"style":122},[248],{"type":30,"value":249},"\"CONSUMER_API_SECRET\"",{"type":24,"tag":103,"props":251,"children":252},{"style":195},[253],{"type":30,"value":254},")\n",{"type":24,"tag":103,"props":256,"children":258},{"class":105,"line":257},5,[259,264,269,273,278],{"type":24,"tag":103,"props":260,"children":261},{"style":195},[262],{"type":30,"value":263},"auth.set_access_token(",{"type":24,"tag":103,"props":265,"children":266},{"style":122},[267],{"type":30,"value":268},"\"ACCESS_TOKEN\"",{"type":24,"tag":103,"props":270,"children":271},{"style":195},[272],{"type":30,"value":244},{"type":24,"tag":103,"props":274,"children":275},{"style":122},[276],{"type":30,"value":277},"\"ACCESS_TOKEN_SECRET\"",{"type":24,"tag":103,"props":279,"children":280},{"style":195},[281],{"type":30,"value":254},{"type":24,"tag":103,"props":283,"children":285},{"class":105,"line":284},6,[286,291,295],{"type":24,"tag":103,"props":287,"children":288},{"style":195},[289],{"type":30,"value":290},"api ",{"type":24,"tag":103,"props":292,"children":293},{"style":189},[294],{"type":30,"value":229},{"type":24,"tag":103,"props":296,"children":297},{"style":195},[298],{"type":30,"value":299}," tweepy.API(auth)\n",{"type":24,"tag":103,"props":301,"children":303},{"class":105,"line":302},7,[304],{"type":24,"tag":103,"props":305,"children":306},{"emptyLinePlaceholder":203},[307],{"type":30,"value":206},{"type":24,"tag":103,"props":309,"children":311},{"class":105,"line":310},8,[312,317],{"type":24,"tag":103,"props":313,"children":314},{"style":189},[315],{"type":30,"value":316},"try",{"type":24,"tag":103,"props":318,"children":319},{"style":195},[320],{"type":30,"value":321},":\n",{"type":24,"tag":103,"props":323,"children":325},{"class":105,"line":324},9,[326],{"type":24,"tag":103,"props":327,"children":328},{"style":195},[329],{"type":30,"value":330},"    api.verify_credentials()\n",{"type":24,"tag":103,"props":332,"children":334},{"class":105,"line":333},10,[335,340,345,350],{"type":24,"tag":103,"props":336,"children":337},{"style":116},[338],{"type":30,"value":339},"    print",{"type":24,"tag":103,"props":341,"children":342},{"style":195},[343],{"type":30,"value":344},"(",{"type":24,"tag":103,"props":346,"children":347},{"style":122},[348],{"type":30,"value":349},"\"Authentication OK\"",{"type":24,"tag":103,"props":351,"children":352},{"style":195},[353],{"type":30,"value":254},{"type":24,"tag":103,"props":355,"children":357},{"class":105,"line":356},11,[358,363],{"type":24,"tag":103,"props":359,"children":360},{"style":189},[361],{"type":30,"value":362},"except",{"type":24,"tag":103,"props":364,"children":365},{"style":195},[366],{"type":30,"value":321},{"type":24,"tag":103,"props":368,"children":370},{"class":105,"line":369},12,[371,375,379,384],{"type":24,"tag":103,"props":372,"children":373},{"style":116},[374],{"type":30,"value":339},{"type":24,"tag":103,"props":376,"children":377},{"style":195},[378],{"type":30,"value":344},{"type":24,"tag":103,"props":380,"children":381},{"style":122},[382],{"type":30,"value":383},"\"Error during authentication\"",{"type":24,"tag":103,"props":385,"children":386},{"style":195},[387],{"type":30,"value":254},{"type":24,"tag":33,"props":389,"children":390},{},[391],{"type":30,"value":392},"Run the script by executing:",{"type":24,"tag":92,"props":394,"children":396},{"className":94,"code":395,"language":96,"meta":8,"style":8},"python test-credentials.py  \n",[397],{"type":24,"tag":99,"props":398,"children":399},{"__ignoreMap":8},[400],{"type":24,"tag":103,"props":401,"children":402},{"class":105,"line":106},[403,407],{"type":24,"tag":103,"props":404,"children":405},{"style":110},[406],{"type":30,"value":18},{"type":24,"tag":103,"props":408,"children":409},{"style":122},[410],{"type":30,"value":411}," test-credentials.py\n",{"type":24,"tag":25,"props":413,"children":415},{"id":414},"_3-playing-with-the-api",[416],{"type":30,"value":417},"3. Playing with the API",{"type":24,"tag":33,"props":419,"children":420},{},[421],{"type":30,"value":422},"Tweepy provides a really simple way to retrieve/create twitter information.",{"type":24,"tag":424,"props":425,"children":427},"h3",{"id":426},"retrieve-your-timeline",[428],{"type":24,"tag":51,"props":429,"children":430},{},[431],{"type":30,"value":432},"Retrieve your timeline",{"type":24,"tag":92,"props":434,"children":436},{"className":178,"code":435,"language":18,"meta":8,"style":8},"# ...\n\n# Retrieve timeline\ntimeline = api.home_timeline()\nfor tweet in timeline:\n    print(f\"{tweet.user.name} said {tweet.text}\")\n",[437],{"type":24,"tag":99,"props":438,"children":439},{"__ignoreMap":8},[440,448,455,463,480,503],{"type":24,"tag":103,"props":441,"children":442},{"class":105,"line":106},[443],{"type":24,"tag":103,"props":444,"children":445},{"style":212},[446],{"type":30,"value":447},"# ...\n",{"type":24,"tag":103,"props":449,"children":450},{"class":105,"line":133},[451],{"type":24,"tag":103,"props":452,"children":453},{"emptyLinePlaceholder":203},[454],{"type":30,"value":206},{"type":24,"tag":103,"props":456,"children":457},{"class":105,"line":147},[458],{"type":24,"tag":103,"props":459,"children":460},{"style":212},[461],{"type":30,"value":462},"# Retrieve timeline\n",{"type":24,"tag":103,"props":464,"children":465},{"class":105,"line":218},[466,471,475],{"type":24,"tag":103,"props":467,"children":468},{"style":195},[469],{"type":30,"value":470},"timeline ",{"type":24,"tag":103,"props":472,"children":473},{"style":189},[474],{"type":30,"value":229},{"type":24,"tag":103,"props":476,"children":477},{"style":195},[478],{"type":30,"value":479}," api.home_timeline()\n",{"type":24,"tag":103,"props":481,"children":482},{"class":105,"line":257},[483,488,493,498],{"type":24,"tag":103,"props":484,"children":485},{"style":189},[486],{"type":30,"value":487},"for",{"type":24,"tag":103,"props":489,"children":490},{"style":195},[491],{"type":30,"value":492}," tweet ",{"type":24,"tag":103,"props":494,"children":495},{"style":189},[496],{"type":30,"value":497},"in",{"type":24,"tag":103,"props":499,"children":500},{"style":195},[501],{"type":30,"value":502}," timeline:\n",{"type":24,"tag":103,"props":504,"children":505},{"class":105,"line":284},[506,510,514,519,524,529,534,539,544,548,553,557,561],{"type":24,"tag":103,"props":507,"children":508},{"style":116},[509],{"type":30,"value":339},{"type":24,"tag":103,"props":511,"children":512},{"style":195},[513],{"type":30,"value":344},{"type":24,"tag":103,"props":515,"children":516},{"style":189},[517],{"type":30,"value":518},"f",{"type":24,"tag":103,"props":520,"children":521},{"style":122},[522],{"type":30,"value":523},"\"",{"type":24,"tag":103,"props":525,"children":526},{"style":116},[527],{"type":30,"value":528},"{",{"type":24,"tag":103,"props":530,"children":531},{"style":195},[532],{"type":30,"value":533},"tweet.user.name",{"type":24,"tag":103,"props":535,"children":536},{"style":116},[537],{"type":30,"value":538},"}",{"type":24,"tag":103,"props":540,"children":541},{"style":122},[542],{"type":30,"value":543}," said ",{"type":24,"tag":103,"props":545,"children":546},{"style":116},[547],{"type":30,"value":528},{"type":24,"tag":103,"props":549,"children":550},{"style":195},[551],{"type":30,"value":552},"tweet.text",{"type":24,"tag":103,"props":554,"children":555},{"style":116},[556],{"type":30,"value":538},{"type":24,"tag":103,"props":558,"children":559},{"style":122},[560],{"type":30,"value":523},{"type":24,"tag":103,"props":562,"children":563},{"style":195},[564],{"type":30,"value":254},{"type":24,"tag":424,"props":566,"children":568},{"id":567},"publish-a-new-tweet",[569],{"type":30,"value":570},"Publish a new tweet",{"type":24,"tag":92,"props":572,"children":574},{"className":178,"code":573,"language":18,"meta":8,"style":8},"api.update_status(\"Hello World from Tweepy\")\n",[575],{"type":24,"tag":99,"props":576,"children":577},{"__ignoreMap":8},[578],{"type":24,"tag":103,"props":579,"children":580},{"class":105,"line":106},[581,586,591],{"type":24,"tag":103,"props":582,"children":583},{"style":195},[584],{"type":30,"value":585},"api.update_status(",{"type":24,"tag":103,"props":587,"children":588},{"style":122},[589],{"type":30,"value":590},"\"Hello World from Tweepy\"",{"type":24,"tag":103,"props":592,"children":593},{"style":195},[594],{"type":30,"value":254},{"type":24,"tag":424,"props":596,"children":598},{"id":597},"retrieve-info-of-any-user",[599],{"type":30,"value":600},"Retrieve info of any user",{"type":24,"tag":92,"props":602,"children":604},{"className":178,"code":603,"language":18,"meta":8,"style":8},"user = api.get_user(\"JaimeDeArcos\")\n\nprint(\"User details:\")\nprint(user)\n\nprint(\"Last 20 Followers:\")\nfor follower in user.followers():\n    print(follower.name)\n",[605],{"type":24,"tag":99,"props":606,"children":607},{"__ignoreMap":8},[608,634,641,662,674,681,701,722],{"type":24,"tag":103,"props":609,"children":610},{"class":105,"line":106},[611,616,620,625,630],{"type":24,"tag":103,"props":612,"children":613},{"style":195},[614],{"type":30,"value":615},"user ",{"type":24,"tag":103,"props":617,"children":618},{"style":189},[619],{"type":30,"value":229},{"type":24,"tag":103,"props":621,"children":622},{"style":195},[623],{"type":30,"value":624}," api.get_user(",{"type":24,"tag":103,"props":626,"children":627},{"style":122},[628],{"type":30,"value":629},"\"JaimeDeArcos\"",{"type":24,"tag":103,"props":631,"children":632},{"style":195},[633],{"type":30,"value":254},{"type":24,"tag":103,"props":635,"children":636},{"class":105,"line":133},[637],{"type":24,"tag":103,"props":638,"children":639},{"emptyLinePlaceholder":203},[640],{"type":30,"value":206},{"type":24,"tag":103,"props":642,"children":643},{"class":105,"line":147},[644,649,653,658],{"type":24,"tag":103,"props":645,"children":646},{"style":116},[647],{"type":30,"value":648},"print",{"type":24,"tag":103,"props":650,"children":651},{"style":195},[652],{"type":30,"value":344},{"type":24,"tag":103,"props":654,"children":655},{"style":122},[656],{"type":30,"value":657},"\"User details:\"",{"type":24,"tag":103,"props":659,"children":660},{"style":195},[661],{"type":30,"value":254},{"type":24,"tag":103,"props":663,"children":664},{"class":105,"line":218},[665,669],{"type":24,"tag":103,"props":666,"children":667},{"style":116},[668],{"type":30,"value":648},{"type":24,"tag":103,"props":670,"children":671},{"style":195},[672],{"type":30,"value":673},"(user)\n",{"type":24,"tag":103,"props":675,"children":676},{"class":105,"line":257},[677],{"type":24,"tag":103,"props":678,"children":679},{"emptyLinePlaceholder":203},[680],{"type":30,"value":206},{"type":24,"tag":103,"props":682,"children":683},{"class":105,"line":284},[684,688,692,697],{"type":24,"tag":103,"props":685,"children":686},{"style":116},[687],{"type":30,"value":648},{"type":24,"tag":103,"props":689,"children":690},{"style":195},[691],{"type":30,"value":344},{"type":24,"tag":103,"props":693,"children":694},{"style":122},[695],{"type":30,"value":696},"\"Last 20 Followers:\"",{"type":24,"tag":103,"props":698,"children":699},{"style":195},[700],{"type":30,"value":254},{"type":24,"tag":103,"props":702,"children":703},{"class":105,"line":302},[704,708,713,717],{"type":24,"tag":103,"props":705,"children":706},{"style":189},[707],{"type":30,"value":487},{"type":24,"tag":103,"props":709,"children":710},{"style":195},[711],{"type":30,"value":712}," follower ",{"type":24,"tag":103,"props":714,"children":715},{"style":189},[716],{"type":30,"value":497},{"type":24,"tag":103,"props":718,"children":719},{"style":195},[720],{"type":30,"value":721}," user.followers():\n",{"type":24,"tag":103,"props":723,"children":724},{"class":105,"line":310},[725,729],{"type":24,"tag":103,"props":726,"children":727},{"style":116},[728],{"type":30,"value":339},{"type":24,"tag":103,"props":730,"children":731},{"style":195},[732],{"type":30,"value":733},"(follower.name)\n",{"type":24,"tag":25,"props":735,"children":737},{"id":736},"creating-your-first-bot-follow-anyone-who-follows-you",[738],{"type":30,"value":739},"Creating your first bot - Follow anyone who follows you",{"type":24,"tag":33,"props":741,"children":742},{},[743],{"type":30,"value":744},"In this example we are going to create a bot which:",{"type":24,"tag":746,"props":747,"children":748},"ul",{},[749,755,760],{"type":24,"tag":750,"props":751,"children":752},"li",{},[753],{"type":30,"value":754},"Retrieve the list of your followers",{"type":24,"tag":750,"props":756,"children":757},{},[758],{"type":30,"value":759},"Check if you're already following them",{"type":24,"tag":750,"props":761,"children":762},{},[763],{"type":30,"value":764},"If not, start following",{"type":24,"tag":92,"props":766,"children":768},{"className":178,"code":767,"language":18,"meta":8,"style":8},"import tweepy, time\n\n# Authentication\nauth = tweepy.OAuthHandler(\"CONSUMER_API_KEY\", \"CONSUMER_API_SECRET\")\nauth.set_access_token(\"ACCESS_TOKEN\", \"ACCESS_TOKEN_SECRET\")\napi = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)\n\n# Verify authentication\ntry:\n    api.verify_credentials()\n    print(\"Authentication OK\")\nexcept:\n    print(\"Error during authentication\")\n\nwhile True:\n    # Retrieve followers\n    for follower in tweepy.Cursor(api.followers).items():\n        if not follower.following:\n            print(\"New Follower -> {}\".format(follower.name))\n            follower.follow()\n    # Sleep for 2 minutes \n    time.sleep(120)\n\n",[769],{"type":24,"tag":99,"props":770,"children":771},{"__ignoreMap":8},[772,784,791,798,829,852,904,911,919,930,937,956,967,987,995,1013,1022,1044,1063,1095,1104,1113],{"type":24,"tag":103,"props":773,"children":774},{"class":105,"line":106},[775,779],{"type":24,"tag":103,"props":776,"children":777},{"style":189},[778],{"type":30,"value":192},{"type":24,"tag":103,"props":780,"children":781},{"style":195},[782],{"type":30,"value":783}," tweepy, time\n",{"type":24,"tag":103,"props":785,"children":786},{"class":105,"line":133},[787],{"type":24,"tag":103,"props":788,"children":789},{"emptyLinePlaceholder":203},[790],{"type":30,"value":206},{"type":24,"tag":103,"props":792,"children":793},{"class":105,"line":147},[794],{"type":24,"tag":103,"props":795,"children":796},{"style":212},[797],{"type":30,"value":215},{"type":24,"tag":103,"props":799,"children":800},{"class":105,"line":218},[801,805,809,813,817,821,825],{"type":24,"tag":103,"props":802,"children":803},{"style":195},[804],{"type":30,"value":224},{"type":24,"tag":103,"props":806,"children":807},{"style":189},[808],{"type":30,"value":229},{"type":24,"tag":103,"props":810,"children":811},{"style":195},[812],{"type":30,"value":234},{"type":24,"tag":103,"props":814,"children":815},{"style":122},[816],{"type":30,"value":239},{"type":24,"tag":103,"props":818,"children":819},{"style":195},[820],{"type":30,"value":244},{"type":24,"tag":103,"props":822,"children":823},{"style":122},[824],{"type":30,"value":249},{"type":24,"tag":103,"props":826,"children":827},{"style":195},[828],{"type":30,"value":254},{"type":24,"tag":103,"props":830,"children":831},{"class":105,"line":257},[832,836,840,844,848],{"type":24,"tag":103,"props":833,"children":834},{"style":195},[835],{"type":30,"value":263},{"type":24,"tag":103,"props":837,"children":838},{"style":122},[839],{"type":30,"value":268},{"type":24,"tag":103,"props":841,"children":842},{"style":195},[843],{"type":30,"value":244},{"type":24,"tag":103,"props":845,"children":846},{"style":122},[847],{"type":30,"value":277},{"type":24,"tag":103,"props":849,"children":850},{"style":195},[851],{"type":30,"value":254},{"type":24,"tag":103,"props":853,"children":854},{"class":105,"line":284},[855,859,863,868,874,878,883,887,892,896,900],{"type":24,"tag":103,"props":856,"children":857},{"style":195},[858],{"type":30,"value":290},{"type":24,"tag":103,"props":860,"children":861},{"style":189},[862],{"type":30,"value":229},{"type":24,"tag":103,"props":864,"children":865},{"style":195},[866],{"type":30,"value":867}," tweepy.API(auth, ",{"type":24,"tag":103,"props":869,"children":871},{"style":870},"--shiki-default:#FFAB70;--shiki-light:#E36209",[872],{"type":30,"value":873},"wait_on_rate_limit",{"type":24,"tag":103,"props":875,"children":876},{"style":189},[877],{"type":30,"value":229},{"type":24,"tag":103,"props":879,"children":880},{"style":116},[881],{"type":30,"value":882},"True",{"type":24,"tag":103,"props":884,"children":885},{"style":195},[886],{"type":30,"value":244},{"type":24,"tag":103,"props":888,"children":889},{"style":870},[890],{"type":30,"value":891},"wait_on_rate_limit_notify",{"type":24,"tag":103,"props":893,"children":894},{"style":189},[895],{"type":30,"value":229},{"type":24,"tag":103,"props":897,"children":898},{"style":116},[899],{"type":30,"value":882},{"type":24,"tag":103,"props":901,"children":902},{"style":195},[903],{"type":30,"value":254},{"type":24,"tag":103,"props":905,"children":906},{"class":105,"line":302},[907],{"type":24,"tag":103,"props":908,"children":909},{"emptyLinePlaceholder":203},[910],{"type":30,"value":206},{"type":24,"tag":103,"props":912,"children":913},{"class":105,"line":310},[914],{"type":24,"tag":103,"props":915,"children":916},{"style":212},[917],{"type":30,"value":918},"# Verify authentication\n",{"type":24,"tag":103,"props":920,"children":921},{"class":105,"line":324},[922,926],{"type":24,"tag":103,"props":923,"children":924},{"style":189},[925],{"type":30,"value":316},{"type":24,"tag":103,"props":927,"children":928},{"style":195},[929],{"type":30,"value":321},{"type":24,"tag":103,"props":931,"children":932},{"class":105,"line":333},[933],{"type":24,"tag":103,"props":934,"children":935},{"style":195},[936],{"type":30,"value":330},{"type":24,"tag":103,"props":938,"children":939},{"class":105,"line":356},[940,944,948,952],{"type":24,"tag":103,"props":941,"children":942},{"style":116},[943],{"type":30,"value":339},{"type":24,"tag":103,"props":945,"children":946},{"style":195},[947],{"type":30,"value":344},{"type":24,"tag":103,"props":949,"children":950},{"style":122},[951],{"type":30,"value":349},{"type":24,"tag":103,"props":953,"children":954},{"style":195},[955],{"type":30,"value":254},{"type":24,"tag":103,"props":957,"children":958},{"class":105,"line":369},[959,963],{"type":24,"tag":103,"props":960,"children":961},{"style":189},[962],{"type":30,"value":362},{"type":24,"tag":103,"props":964,"children":965},{"style":195},[966],{"type":30,"value":321},{"type":24,"tag":103,"props":968,"children":970},{"class":105,"line":969},13,[971,975,979,983],{"type":24,"tag":103,"props":972,"children":973},{"style":116},[974],{"type":30,"value":339},{"type":24,"tag":103,"props":976,"children":977},{"style":195},[978],{"type":30,"value":344},{"type":24,"tag":103,"props":980,"children":981},{"style":122},[982],{"type":30,"value":383},{"type":24,"tag":103,"props":984,"children":985},{"style":195},[986],{"type":30,"value":254},{"type":24,"tag":103,"props":988,"children":990},{"class":105,"line":989},14,[991],{"type":24,"tag":103,"props":992,"children":993},{"emptyLinePlaceholder":203},[994],{"type":30,"value":206},{"type":24,"tag":103,"props":996,"children":998},{"class":105,"line":997},15,[999,1004,1009],{"type":24,"tag":103,"props":1000,"children":1001},{"style":189},[1002],{"type":30,"value":1003},"while",{"type":24,"tag":103,"props":1005,"children":1006},{"style":116},[1007],{"type":30,"value":1008}," True",{"type":24,"tag":103,"props":1010,"children":1011},{"style":195},[1012],{"type":30,"value":321},{"type":24,"tag":103,"props":1014,"children":1016},{"class":105,"line":1015},16,[1017],{"type":24,"tag":103,"props":1018,"children":1019},{"style":212},[1020],{"type":30,"value":1021},"    # Retrieve followers\n",{"type":24,"tag":103,"props":1023,"children":1025},{"class":105,"line":1024},17,[1026,1031,1035,1039],{"type":24,"tag":103,"props":1027,"children":1028},{"style":189},[1029],{"type":30,"value":1030},"    for",{"type":24,"tag":103,"props":1032,"children":1033},{"style":195},[1034],{"type":30,"value":712},{"type":24,"tag":103,"props":1036,"children":1037},{"style":189},[1038],{"type":30,"value":497},{"type":24,"tag":103,"props":1040,"children":1041},{"style":195},[1042],{"type":30,"value":1043}," tweepy.Cursor(api.followers).items():\n",{"type":24,"tag":103,"props":1045,"children":1047},{"class":105,"line":1046},18,[1048,1053,1058],{"type":24,"tag":103,"props":1049,"children":1050},{"style":189},[1051],{"type":30,"value":1052},"        if",{"type":24,"tag":103,"props":1054,"children":1055},{"style":189},[1056],{"type":30,"value":1057}," not",{"type":24,"tag":103,"props":1059,"children":1060},{"style":195},[1061],{"type":30,"value":1062}," follower.following:\n",{"type":24,"tag":103,"props":1064,"children":1066},{"class":105,"line":1065},19,[1067,1072,1076,1081,1086,1090],{"type":24,"tag":103,"props":1068,"children":1069},{"style":116},[1070],{"type":30,"value":1071},"            print",{"type":24,"tag":103,"props":1073,"children":1074},{"style":195},[1075],{"type":30,"value":344},{"type":24,"tag":103,"props":1077,"children":1078},{"style":122},[1079],{"type":30,"value":1080},"\"New Follower -> ",{"type":24,"tag":103,"props":1082,"children":1083},{"style":116},[1084],{"type":30,"value":1085},"{}",{"type":24,"tag":103,"props":1087,"children":1088},{"style":122},[1089],{"type":30,"value":523},{"type":24,"tag":103,"props":1091,"children":1092},{"style":195},[1093],{"type":30,"value":1094},".format(follower.name))\n",{"type":24,"tag":103,"props":1096,"children":1098},{"class":105,"line":1097},20,[1099],{"type":24,"tag":103,"props":1100,"children":1101},{"style":195},[1102],{"type":30,"value":1103},"            follower.follow()\n",{"type":24,"tag":103,"props":1105,"children":1107},{"class":105,"line":1106},21,[1108],{"type":24,"tag":103,"props":1109,"children":1110},{"style":212},[1111],{"type":30,"value":1112},"    # Sleep for 2 minutes \n",{"type":24,"tag":103,"props":1114,"children":1116},{"class":105,"line":1115},22,[1117,1122,1127],{"type":24,"tag":103,"props":1118,"children":1119},{"style":195},[1120],{"type":30,"value":1121},"    time.sleep(",{"type":24,"tag":103,"props":1123,"children":1124},{"style":116},[1125],{"type":30,"value":1126},"120",{"type":24,"tag":103,"props":1128,"children":1129},{"style":195},[1130],{"type":30,"value":254},{"type":24,"tag":33,"props":1132,"children":1133},{},[1134,1136],{"type":30,"value":1135},"Simple, right? now you can improve the script with whatever use case you need. This script could be running locally or\nmaybe you would deploy it on any provider of your choice ",{"type":24,"tag":1137,"props":1138,"children":1139},"em",{},[1140],{"type":30,"value":1141},"(AWS, Azure, google cloud...)",{"type":24,"tag":1143,"props":1144,"children":1145},"hr",{},[],{"type":24,"tag":25,"props":1147,"children":1149},{"id":1148},"references-links",[1150],{"type":30,"value":1151},"References & links",{"type":24,"tag":746,"props":1153,"children":1154},{},[1155,1162],{"type":24,"tag":750,"props":1156,"children":1157},{},[1158],{"type":24,"tag":39,"props":1159,"children":1160},{"href":41},[1161],{"type":30,"value":41},{"type":24,"tag":750,"props":1163,"children":1164},{},[1165],{"type":24,"tag":39,"props":1166,"children":1170},{"href":1167,"rel":1168},"https://www.tweepy.org/",[1169],"nofollow",[1171],{"type":30,"value":88},{"type":24,"tag":1143,"props":1173,"children":1174},{},[],{"type":24,"tag":1176,"props":1177,"children":1178},"style",{},[1179],{"type":30,"value":1180},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}",{"title":8,"searchDepth":133,"depth":133,"links":1182},[1183,1184,1185,1190,1191],{"id":27,"depth":133,"text":31},{"id":75,"depth":133,"text":78},{"id":414,"depth":133,"text":417,"children":1186},[1187,1188,1189],{"id":426,"depth":147,"text":432},{"id":567,"depth":147,"text":570},{"id":597,"depth":147,"text":600},{"id":736,"depth":133,"text":739},{"id":1148,"depth":133,"text":1151},"markdown","content:posts:how-to-create-a-twitter-bot.md","content","posts/how-to-create-a-twitter-bot.md","posts/how-to-create-a-twitter-bot","md",1790510065414]