-
Notifications
You must be signed in to change notification settings - Fork 0
/
julia-trancou.py
80 lines (62 loc) · 2.09 KB
/
julia-trancou.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import tweepy
from datetime import datetime
from os import environ
# Define API keys
CONSUMER_KEY = environ['CONSUMER_KEY']
CONSUMER_SECRET = environ['CONSUMER_SECRET']
ACCESS_KEY = environ['ACCESS_KEY']
ACCESS_SECRET = environ['ACCESS_SECRET']
# Set id for my personal account
PERSONAL_ID = environ['PERSONAL_ID']
dropped_out = False
# Define date for last post
file = open("last-post-day.txt", "r+")
last_post_day = int(file.read())
# Define a calendar array to print out the months by their names in Portuguese
CALENDAR = [
'',
'Janeiro',
'Fevereiro',
'Março',
'Abril',
'Maio',
'Junho',
'Julho',
'Agosto',
'Setembro',
'Outubro',
'Novembro',
'Dezembro']
# Authenticate to Twitter using the defined constants
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
now = datetime.today()
# Create messages object
messages = api.get_direct_messages()
# This function is the one to be called every day to post my twitter
def tweet_college_status():
# Only post tweet if last update was made the day before
if (now.day != last_post_day):
if dropped_out == False:
api.update_status("Julia não trancou a faculdade até o dia " +
str(now.day) + " de " + CALENDAR[now.month] + ".")
if dropped_out == True:
api.update_status("Julia trancou a faculdade.")
print("Tweeting status...")
# Save time to environment variable
file.seek(0)
file.write(str(now.day))
else:
print("Status was already updated today.")
for message in messages:
# Check if message was sent by my personal account
if message.message_create['sender_id'] == PERSONAL_ID:
# Check if the answer "yes" was given from my personal account
if message.message_create['message_data']['text'] == "yes" or message.message_create['message_data']['text'] == "y":
dropped_out = True
tweet_college_status()
break
tweet_college_status()
break
file.close()