-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
44 lines (38 loc) · 1.14 KB
/
utils.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
import json
import os
def autoSave():
global lsave
curr_time = time.time()
if(curr_time >= lsave + 300):
with open('infy', 'a+') as f:
f.write(str(data_infy))
with open('tcs', 'a+') as f:
f.write(str(data_tcs))
lsave = time.time()
# combiner()
print("AutoSaved at : " + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(lsave)))
def combiner(filepath,file_names):
for ticker in file_names:
if os.path.exists(filepath+"/"+ticker):
final = {}
with open(filepath+"/"+ticker, 'r') as f:
data = f.read()
data = data.replace("}{","}split{")
splittedData = data.split('split')
for dictionary in splittedData:
tmp = json.loads(dictionary.replace("'",'"'))
for key in tmp.keys():
final[key] = tmp[key]
with open(filepath+"/"+ticker, 'w') as fw:
fw.write(str(final))
def cleanse(ticker_data):
try:
for keys in ticker_data:
for attr in ticker_data[keys]:
if ticker_data[keys][attr] == "-":
ticker_data[keys][attr] = "0"
ticker_data[keys][attr] = ticker_data[keys][attr].replace(',', '')
except Exception as e:
print("{} : {}".format(attr, e))
finally:
return ticker_data