-
Notifications
You must be signed in to change notification settings - Fork 4
/
populate_genesis_objkts.py
103 lines (93 loc) · 3.61 KB
/
populate_genesis_objkts.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
98
99
100
101
102
103
from pytezos import Key
from pytezos import pytezos
from pytezos.rpc.node import RpcError
from pytezos.operation.result import OperationResult
from decimal import Decimal
import datetime
import os
import time
import os.path
import requests
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
# The ID and range of a sample spreadsheet.
FOUNTAIN_SPREADSHEET_ID = '1fcMoCMw44mZvA2qR84Bdxfi90b0AEfINflPdiBqU3kg'
FOUNTAIN_RANGE_NAME = 'Form Responses 1!A2:I'
# Address: tz1UqhPnVXdPccrVsa5khscwCLHTF2Q2CAer
key = Key.from_encoded_key(os.environ['TEIA_FOUNTAIN_KEY'], os.environ['TEIA_FOUNTAIN_PASS'])
pytezos = pytezos.using(shell='mainnet', key=key)
acct_id = pytezos.key.public_key_hash()
acct = pytezos.account()
def get_genesis(acct_id):
url = f'https://api.tzkt.io/v1/bigmaps/522/keys?sort.asc=id&value.issuer={acct_id}&limit=1'
r = requests.get(url)
if r.status_code != 200:
time.sleep(1)
return get_genesis(acct_id)
data = r.json()
if len(data) > 0:
return data[0]['key']
return ''
def store_results(service, row_num, objkt_id):
values = [
[ "https://www.hicetnunc.xyz/objkt/%s" % objkt_id ]
]
body = { 'values': values }
range_name = 'Form Responses 1!I%s:I%s' % (row_num, row_num)
#print(range_name)
result = service.spreadsheets().values().update(
spreadsheetId=FOUNTAIN_SPREADSHEET_ID, range=range_name,
valueInputOption='USER_ENTERED', body=body).execute()
print('{0} cells updated.'.format(result.get('updatedCells')))
def main():
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
service = build('sheets', 'v4', credentials=creds)
# Call the Sheets API
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=FOUNTAIN_SPREADSHEET_ID,
range=FOUNTAIN_RANGE_NAME).execute()
values = result.get('values', [])
if not values:
print('No data found.')
else:
row_num = 1
for row in values:
row_num += 1
if row[1] == '':
break
#print(row)
address = row[1].strip()
approved = len(row) >= 8
#print('%s, %s' % (address, approved))
if approved:
if len(row[7]) == 0:
continue
if len(row) >= 9:
if len(row[8]) > 0:
continue
objkt = get_genesis(address)
if objkt:
print('%s minted %s' % (address, objkt))
store_results(service, row_num, objkt)
if __name__ == '__main__':
main()