-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
45 lines (34 loc) · 1.1 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# import modules
import tweepy
import time
import os
# import dependencies
from weather import *
# authorize twitter app
def init():
"""Authorize twitter app using tweepy library"""
# ensure environment variables are set
if not os.environ.get("consumer_key"):
raise RuntimeError("consumer_key not set")
if not os.environ.get("consumer_secret"):
raise RuntimeError("consumer_secret not set")
auth = tweepy.OAuthHandler(os.environ.get("consumer_key"), os.environ.get("consumer_secret"))
auth.set_access_token(os.environ.get("access_token"), os.environ.get("access_token_secret"))
return tweepy.API(auth)
def main():
"""Run bot"""
# initialize bot
api = init()
while True:
# lookup for tweets
tweets = lookup()
# update twitter's account status
if tweets != None:
for tweet in tweets:
api.update_status(tweet)
# delay next tweet for 3 hours
time.sleep(10800)
if __name__ == "__main__":
main()