-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_pub_vs_pri.py
62 lines (52 loc) · 2.54 KB
/
transaction_pub_vs_pri.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
59
60
61
62
#====================================================================================================#
#******************************* HOW TO RUN? **************************************************** #
# python3 transaction_pub_vs_pri.py <path to the input json file> <path to the output file> #
#*************************************************************************************************** #
# Example: #
#python3 transaction_pub_vs_pri.py /Users/rajattan/venmo/dummy.json ./transactions_date_wise.txt #
#====================================================================================================#
import sys
import json
transactions = 0
transactions_date_wise = {}
min_date_wise = {}
max_date_wise = {}
if(len(sys.argv) != 3):
print("==========================================================================")
print("SORRY!! Please provide the path to the INPUT json file and the OUTPUT file")
print("==========================================================================")
print("Example: python3 transaction_pub_vs_pri.py ./dummy.json ./output.txt ")
print("==========================================================================")
sys.exit()
f = open(sys.argv[1])
outputfile = open(sys.argv[2],"w")
for line in f:
data = json.loads(line)
transactions = transactions + 1
try:
if(data is None or data['created_time'] is None or data['payment_id'] is None):
continue
datetime = str(data['created_time'])
date = datetime.split("T")
payment_id = int(str(data['payment_id']))
if(date[0] not in transactions_date_wise):
transactions_date_wise[date[0]] = 0
max_date_wise[date[0]] = payment_id
min_date_wise[date[0]] = payment_id
else:
if(payment_id > max_date_wise[date[0]]):
max_date_wise[date[0]] = payment_id
if(payment_id < min_date_wise[date[0]]):
min_date_wise[date[0]] = payment_id
transactions_date_wise[date[0]] = transactions_date_wise[date[0]] + 1
except:
continue
f.close()
outputfile.write("DATE #TRANSACTIONS #MIN_ID #MAX_ID\n")
for k,v in sorted(transactions_date_wise.items()):
try:
outputfile.write(str(k) + " " + str(v) + " " + str(min_date_wise[k]) + " " + str(max_date_wise[k]) + "\n")
except:
continue
outputfile.write("TOTAL NUMBER OF TRANSACTIONS ARE :" + str(transactions))
outputfile.close()