-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRest_test.py
71 lines (30 loc) · 1.22 KB
/
Rest_test.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
import json
import requests
Transactions = []
runningbal = []
start = 1
z = 0
j = 0
#Requests all pages of the Bench API aka p.1-4 and prints them
while start < 5:
i = str(start)
url = "http://resttest.bench.co/transactions/" + i + ".json"
r = requests.get(url)
data = json.loads(r.text)
goods_only = data.get('transactions') #this makes sure it only pulls the 'transactions' key from the dict, and not the date or page #
Transactions.append(goods_only)
start += 1
#Cleans up the transaction data into legible format
print "\n" + "Your monthly statement for December 2013:" + "\n"
while z < 4:
for d in Transactions[z]:
clean_format = "Date: " + d['Date'] + " | " "Amount: " + d['Amount'] + " | " "Company: " + d['Company'] + " | " "Ledger: " + d['Ledger']
print clean_format
z += 1
#Time to calculate the running balance
while j < 4: #index starts at 0 and there are only 4 pages
allthenums = [float(inner_dict['Amount']) for inner_dict in Transactions[j]] #grabs values of the key 'Amount' within the list nested in Transactions as a float
pageBalance = sum(allthenums)
runningbal.append(pageBalance)
j += 1
print "\n" + "Your current balance on this credit card is: $" + str(sum(runningbal))