-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproposals.py
63 lines (53 loc) · 2.88 KB
/
proposals.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
#!/usr/bin/env python3
import requests
import json
import toml
config = toml.load("proposals.toml")
def sendTelegramMessage(message):
url = f"https://api.telegram.org/bot{config['telegram']['token']}/sendMessage?chat_id={config['telegram']['chat_id']}&text={message}"
headers = { 'Accept': 'application/json' }
data = requests.get(url, headers=headers, timeout=5).text
def debugPrint(output):
if config['loglevel'].upper() == "DEBUG":
print(output)
for status in config['status']:
debugPrint(f"Proposals with status {status}")
for network in config['networks']:
debugPrint(f" For netowrk {network}")
url = f"{config['networks'][network]['lcd']}/cosmos/gov/{config['networks'][network]['sdkVersion']}/proposals?proposal_status={config['status'][status]}"
debugPrint(f"{url}")
headers = { 'Accept': 'application/json' }
try:
data = requests.get(url, headers=headers, timeout=5).text
except:
print(f"Unable to get data for network {network}, please check manually")
sendTelegramMessage(f"Unable to get data for network {network}, please check manually")
continue
proposals=json.loads(data)
if "proposals" in proposals.keys():
for proposal in proposals['proposals']:
if config['networks'][network]['sdkVersion'] == "v1":
proposalId = proposal['id']
elif config['networks'][network]['sdkVersion'] == "v1beta1":
proposalId = proposal['proposal_id']
if config['networks'][network]['cosmosPrefix'] == "true":
cosmosPrefix = "cosmos/"
else:
cosmosPrefix = ""
url = f"{config['networks'][network]['lcd']}/{cosmosPrefix}gov/{config['networks'][network]['sdkVersion']}/proposals/{proposalId}/votes/{config['networks'][network]['voter']}"
debugPrint(url)
data = requests.get(url, headers=headers, timeout=5).text
vote_data = json.loads(data)
try:
vote = vote_data[config['networks'][network]['voteTag']]['options'][0]['option']
except:
vote = "DID_NOT_VOTE"
message=f"There is a proposal for {network.upper()} network on which {config['networks'][network]['pretyName']} DID NOT vote\n\nProposal ID: {proposalId} -> {config['networks'][network]['proposalLink']}/{proposalId}"
debugPrint(message)
sendTelegramMessage(message)
debugPrint(f" Porposal {proposalId} -> {vote}")
else:
print(f" Something wrong checking proposals for {network}. Please check manually")
sendTelegramMessage(f" Something wrong checking proposals for {network}. Please check manually")
continue
debugPrint("\n")