-
Notifications
You must be signed in to change notification settings - Fork 43
/
health.py
97 lines (68 loc) · 3.08 KB
/
health.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from datetime import datetime
from utils import get_env, verify_env_vars, env_vars, get_env_vars, Telegram, Venmo
from dotenv import load_dotenv
def main(now):
load_dotenv()
date = now.strftime("%B %d, %Y")
time = now.strftime("%H:%M%p")
print(f'🕘 Monthly health check running on {date} at {time}.\n')
print("🔍 Verifying environment variables...")
numOfExpected = 7
envVarsAreDefined = verify_env_vars(env_vars, numOfExpected)
if envVarsAreDefined:
print(f'✅ Found all {numOfExpected} environment variables.\n')
else:
print('❌ Failed to verify environment variables.\n')
access_token, chat_id, bot_token, *tail = get_env_vars(env_vars)
venmo = Venmo(access_token)
telegram = Telegram(bot_token, chat_id)
print("🤑 Verifying Venmo client is working...")
userId = venmo.get_user_id_by_username("Jordan-Mishlove")
if userId:
print('✅ Venmo client is working as expected.\n')
else:
print('❌ Failed to get userId using Venmo client.\n')
returnedUserId = bool(userId)
if envVarsAreDefined and returnedUserId:
print('✅ Everything looks good in the health check')
message = """Hello old sport! 👋
Checking in from your Monthly Venmo script.
According to my calculations, everything looks in order.
You money should be requested per usual this month.
Cheerio!
— Efron 🤵🏻♂️
"""
telegram.send_message(message)
elif envVarsAreDefined:
print('❌ Venmo client might not be working. 1/2 checks failed in health script.')
message = """Oh hello old sport...
As you can tell by the hesitation in my voice (or rather writing...), I don't have great news.
According to my calculations, the environment variables in your Monthly Venmo script are working, but the Venmo client isn't.
If I were smarter, I would fix it myself, but you know, I'm just an assistant. That's beyond my paygrade.
Good luck fixing it!
— Efron 🤵🏻♂️
"""
telegram.send_message(message)
elif returnedUserId:
print('❌ Envrionment variables check did not pass. 1/2 checks failed in health script.')
message = """It's me again, old sport...
As you can tell by the hesitation in my voice (or rather writing), I don't have great news.
According to my calculations, the Venmo client in your Monthly Venmo script is working, but there is a problem with the environment variables.
You know this stuff is beyond my level of expertise. I'll defer to you, sir.
Good luck!
— Efron 🤵🏻♂️
"""
telegram.send_message(message)
else:
print('❌ Venmo client and environment variables did not pass. 2/2 checks failed in health script.')
message = """Oh dear...
I thought the other day was bad, but this is worse.
According to my calculations, the Venmo client and the environment variables are both failing in your Monthly Venmo script.
I have no idea what could be wrong. I promise I didn't break it.
You may want to go to GitHub and take a look.
— Efron 🤵🏻♂️
"""
telegram.send_message(message)
# Grab current date and passing in when running function
now = datetime.now()
main(now)