-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (49 loc) · 1.61 KB
/
main.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
import requests
import os
SPIN_URL = 'https://api.chrono.gg/quest/spin'
COINS_URL = 'https://api.chrono.gg/account/coins'
def spinCoin(jwt):
response = requests.get(
SPIN_URL,
headers={
'Authorization': jwt,
},
)
if response.status_code == 200:
resp = response.json()
gain = resp['quest']['value']+resp['quest']['bonus']
chest_gain = resp['chest']['base']+resp['chest']['bonus'] if len(resp['chest']) else 0
msg = 'spun coin for a total of {} points'.format(gain)
if chest_gain > 0:
msg += ' plus {} from a chest'.format(chest_gain)
print(msg)
getCoins(jwt)
elif response.status_code == 420:
print('spin is still in cooldown')
elif response.status_code == 404:
print('token invalid')
else:
print('unhandled status code returned. Please check logs')
def getCoins(jwt):
response = requests.get(
COINS_URL,
headers={
'Authorization': jwt,
},
)
if response.status_code == 200:
balance = response.json()['balance']
print(f'current balance: {balance}')
elif response.status_code == 404:
print('token invalid')
else:
print(f'Unhandled status code returned. Raw response: {response}')
def importEnvVars():
jwt = os.getenv('JWT_TOKEN')
if jwt is None or jwt == "":
raise Exception('Environment variable JWT_TOKEN missing')
return jwt
def lambda_handler(event, context):
jwt = importEnvVars()
print(f'Lambda started. Environment variable JWT_TOKEN: {jwt}')
spinCoin(jwt)