-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractor.py
57 lines (33 loc) · 1.36 KB
/
extractor.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
'''
SCRIPT-1 : Original Table data extract & delete
'''
#Importing Libraries
import MySQLdb
from datetime import datetime
startime=datetime.now()
#Creating a connection to database
conn=MySQLdb.connect(host='localhost',user='user',password='fill_as_per_requirement',db='graph_data')
#make changes to database user, password & db name.....a
cur=conn.cursor()
#Using Database
cur.execute('USE graph_data')
#Creating a Table and feeding all values in it....
cur.execute('CREATE TABLE IF NOT EXISTS avgprices_cleaner(timestamp BIGINT(30) UNIQUE,avg_price TEXT, from_sym TEXT, to_sym TEXT,utcdate TEXT , utctime TEXT)')
cur.execute('SELECT * FROM avgprices')
rows=cur.fetchall()
for row in rows:
timestamp=row[0]
unixtime=int((timestamp/1000))
utcdate=datetime.utcfromtimestamp(unixtime).strftime('%d-%m-%Y')
utctime=datetime.utcfromtimestamp(unixtime).strftime('%H:%M')
from_sym=row[1]
to_sym=row[2]
avg_price=row[3]
cur.execute("INSERT IGNORE INTO avgprices_cleaner(timestamp,utcdate,utctime,from_sym,to_sym,avg_price)\
VALUES (%s,%s,%s,%s,%s,%s)",(timestamp,utcdate,utctime,from_sym,to_sym,avg_price))
conn.commit() #very important step
cur.execute('TRUNCATE TABLE avgprices')
cur.close()
endtime=datetime.now()
print(endtime-startime)
#[written by AAYUSH GADIA]