-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_csv.py
58 lines (45 loc) · 2.21 KB
/
export_csv.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
import sqlite3
import pandas as pd
def main():
conn = sqlite3.connect("dbv3-core.db") # location of dbv3-core.db
cur = conn.cursor()
attachDB = "dbv3-index.db" # location of dbv3-index.db
cur.execute("ATTACH DATABASE ? AS db", [attachDB])
df = pd.read_sql_query('''SELECT A.blk blkid, B.blkhash, A.unixtime miningtime
FROM BlkTime
A INNER JOIN db.BlkID B
ON A.blk = B.id''',conn)
df.to_csv(r'blkinfo.csv', index=False)
df = pd.read_sql_query('''SELECT A.tx txid, B.txid txhash, A.blk blkid
FROM BlkTx
A INNER JOIN db.TxID B
ON A.tx = B.id''', conn)
df.to_csv(r'txinfo.csv', index=False)
df = pd.read_sql_query('''SELECT A.id addrtypeid, A.addrtype
FROM db.AddrTypeID A ''', conn)
df.to_csv(r'addrtype.csv', index=False)
df = pd.read_sql_query('''SELECT id addrid, addr,
CASE SUBSTR(addr, 1, 1)
WHEN '1' THEN 1
WHEN '3' THEN 2
ELSE 3
END addrtypeid,
(SELECT db.BlkID.id
FROM db.BlkID INNER JOIN BlkTx
ON BlkTx.blk = db.BlkID.id
WHERE BlkTx.tx = (
SELECT MIN(TxOut.tx)
FROM TxOut
WHERE TxOut.addr IN (
SELECT db.AddrID.id
FROM db.AddrID
WHERE db.AddrID.id = T.id))) blkid
FROM db.AddrID T''',conn)
df.to_csv(r'addrinfo.csv', index=False)
df = pd.read_sql_query('''SELECT tx txid, n, ptx ptxid, pn FROM TxIn''', conn)
df.to_csv(r'txin.csv', index=False)
df = pd.read_sql_query('''SELECT tx txid, n, addr addrid, btc FROM TxOut''', conn)
df.to_csv(r'txout.csv', index=False)
conn.close()
if __name__ == "__main__":
main()