-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathasterix.py
48 lines (34 loc) · 998 Bytes
/
asterix.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
import hashlib
import json
import os
from helpers import format_exp
from google.cloud import bigquery
# pip install --upgrade google-cloud-bigquery
# setting up gcloud sdk: https://cloud.google.com/sdk/docs/downloads-interactive
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'creds.json'
client = bigquery.Client()
with open('script.js') as f:
script = f.read()
query_job = client.query(
'''
create temp function parse(contract STRING)
returns ARRAY<STRING>
LANGUAGE js AS
"""
''' + script + '''
""";
SELECT addr, parse(contract)
FROM `showme-1389.eveem.contracts`
WHERE ver='v4' AND ARRAY_LENGTH(parse(contract)) > 0
''')
results = query_job.result()
for row in results:
addr = row[0]
print(addr) # contract address
for output in row[1]:
d = json.loads(output)
print(d['print'])
for line in d['offenders']:
print('^'+format_exp(line))
print()
print()