#6430: display response nicely in tabular format

This commit is contained in:
PCoder 2019-08-20 11:50:27 +05:30
parent c3c9ba4a72
commit 0b838b0172

View file

@ -2,6 +2,7 @@ import urllib.request
import json
import sys
from pyotp import TOTP
from tabulate import tabulate
UNGLEICH_PAY_SERVER_URL = "https://pay.ungleich.ch"
@ -55,4 +56,11 @@ class ungleichPay(object):
print(str(uerr))
sys.exit(2)
response_json = json.loads(response.read().decode('utf-8'))
print(response_json["data"])
if (response_json['response'] == 'success'):
data = response_json["data"]
rows = [(x['email'], x['vm_count']) for x in data]
headers = ["email", "vm_count"]
print(tabulate(rows, headers))
else:
print("An error occurred.")
print(response_json["message"])