-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_ENS.py
57 lines (45 loc) · 1.55 KB
/
get_ENS.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
import os
import sqlite3
from google.cloud import bigquery
from eth_utils import to_checksum_address
def query_ENS():
client = bigquery.Client()
query_job = client.query(
"""
select * from ens-manager.names.reverse_records
"""
)
return query_job.result() # Waits for job to complete.
def create_contracts_table(DB):
conn = sqlite3.connect(DB)
cursor = conn.cursor()
try:
create_table = '''create table ENS(
id INTEGER PRIMARY KEY NOT NULL,
addr VARCHAR(50) NOT NULL,
name VARCHAR(50))'''
sql_create_addr_index = "create index addr_index on ENS(addr)"
cursor.execute(create_table)
cursor.execute(sql_create_addr_index)
except:
clean_table = "DELETE FROM ENS"
cursor.execute(clean_table)
cursor.close()
conn.commit()
conn.close()
def get_ENS_to_sqlite(DB):
create_contracts_table(DB)
conn = sqlite3.connect(DB)
cursor = conn.cursor()
ENS_list = query_ENS()
for ENS in ENS_list:
sql_insert_info = "insert into ENS (addr,name) values (?,?)"
cursor.execute(sql_insert_info, (ENS.addr , ENS.name))
# cursor.execute(sql_insert_info, (to_checksum_address(ENS.addr), ENS.name))
cursor.close()
conn.commit()
conn.close()
if __name__ == "__main__":
if not os.path.exists("./outputs/ENS/"):
os.makedirs("./outputs/ENS/")
get_ENS_to_sqlite(DB="./outputs/ENS/ENS.db")