Skip to content

Commit 724a66b

Browse files
committed
better output for consumptionDetailByCycle
1 parent 7b724e0 commit 724a66b

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

simyo/simyo.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,30 @@ def consumptionDetailByCycle(billCycleCount=1):
233233
result = api_request(URL)
234234
if VERBOSE: print result + "\n"
235235

236-
data = convert(json.loads(result)['response']['consumptionDetailByCycleList'])
237-
pp = pprint.PrettyPrinter(indent=4)
238-
pp.pprint(data)
236+
data = json.loads(result)
237+
startDate=data['response']['consumptionDetailByCycleList'][0]['startDate']
238+
endDate=data['response']['consumptionDetailByCycleList'][0]['endDate']
239+
start = epoch2date(startDate)
240+
end = epoch2date(endDate)
241+
print "\nPeriodo de " + start + " a " + end + "\n"
242+
243+
for day in data['response']['consumptionDetailByCycleList'][0]['consumptionsByDay']:
244+
date = epoch2date(day['date'])
245+
totalCharge = float(day['totalCharge'])
246+
print "{0} charge: {1}".format(date, totalCharge)
247+
if 'data' in day:
248+
print "\tdata: {0:.2f} MB ({1} EUR)".format(day['data']['count']/1024.0/1024.0, float(day['data']['chargeTotal']))
249+
else:
250+
print "\tdata: 0 MB (0 EUR)"
251+
if 'voice' in day:
252+
hms = datetime.timedelta(seconds=day['voice']['count'])
253+
print "\tvoice: {0} ({1} EUR)".format (hms, float(day['voice']['chargeTotal']))
254+
else:
255+
print "\tvoice: 0:00:00 (0 EUR)"
256+
if 'sms' in day:
257+
print "\tsms: {0} ({1} EUR)".format (day['sms']['count'], float(day['sms']['chargeTotal']))
258+
else:
259+
print "\tsms: 0 (0 EUR)"
239260

240261
def frequentNumbers():
241262
month=billCycle # Parameter month is mandatory

0 commit comments

Comments
 (0)