-
Notifications
You must be signed in to change notification settings - Fork 0
/
answering_machine.py
43 lines (31 loc) · 1.1 KB
/
answering_machine.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
import time
import collect_followers
import dropbox_api
import sql_api
import twitter_api
def main(tweet):
# Make connection to Twitter.
twitter = twitter_api.API()
t_username = tweet["t_username"]
followings = collect_followers.get_followings(t_username)
if followings == 'private':
twitter.reply_to_private(tweet["tweet_id"], t_username)
else:
followings = collect_followers.update_db(followings)
filename = collect_followers.export_followings(followings, t_username)
# Share to dropbox
dropbox = dropbox_api.API()
shared_file_url = dropbox.upload_file(filename)
# Reply to tweet with url.
twitter.reply_with_url(tweet["tweet_id"], shared_file_url, t_username)
sql = f'DELETE FROM queue WHERE t_username == "{t_username}"'
db.commit(sql)
if __name__ == "__main__":
# Make connection to SQL databse.
db = sql_api.DB()
while True:
tweet = db.select(f"SELECT * FROM queue ORDER BY timestamp LIMIT 1")
if tweet != []:
main(tweet[0])
else:
time.sleep(3)