-
Notifications
You must be signed in to change notification settings - Fork 0
/
octopus-saving-sessions.py
49 lines (40 loc) · 1.03 KB
/
octopus-saving-sessions.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
#!/usr/bin/env python3
import requests
import json
import sys
email = "[email protected]"
password = "your_password"
account = "A-AAAAAAAA" # Octopus account number
url = 'https://api.octopus.energy/v1/graphql/'
query = 'mutation krakenTokenAuthentication{ obtainKrakenToken(input: {email: "%s", password: "%s"}) { token } }' % (email, password)
r = requests.post(url, json={'query': query})
if r.status_code != 200:
print("Failed")
sys.exit(1)
auth = json.loads(r.text)
token = auth['data']['obtainKrakenToken']['token']
jwt = "JWT %s" % token
query = """query {
savingSessions {
account(accountNumber: "%s") {
hasJoinedCampaign
joinedEvents {
eventId
startAt
endAt
}
}
}
octoPoints {
account(accountNumber: "%s") {
currentPointsInWallet
}
}
}""" % (account, account)
headers = {"Authorization": jwt}
r = requests.post(url, headers=headers, json={'query': query})
if r.status_code != 200:
print("Failed")
sys.exit(1)
sessions = json.loads(r.text)
print(json.dumps(sessions, indent=4))