-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.py
56 lines (44 loc) · 1.97 KB
/
report.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
from cache import Cache
from helpers import sort
class Report(object):
def __init__(self, tid):
self.id = tid
self.cache = Cache(tid)
mp_list = self.cache.get().get('data', {}).get('attributes', {}).get('signatures_by_constituency', [])
self.mps = sort(mp_list)
country_list = self.cache.get().get('data', {}).get('attributes', {}).get('signatures_by_country', [])
self.countries = sort(country_list)
self.title = self.cache.get().get('data', {}).get('attributes', {}).get("action", "Not found")
def get_count(self):
return self.cache.get().get("data", {}).get("attributes", {})['signature_count']
def _search(self, query, queryset):
result = []
for item in queryset:
for check in [str(i).lower() for i in item.values()]:
if query.lower() in check:
result.append(item)
return result
def search_country(self, search):
return self._search(search, self.countries)
def search_mp(self, search):
return self._search(search, self.mps)
def print_countries(self, flist):
print("|{:-^40}+{:-^40}+{:-^20}|".format("Name", "Code", "Signature"))
for i in flist:
name = i.get("name", "N/A")
code = i.get("code", "NA")
signature = i.get("signature_count", -1)
try:
print("|{:^40}|{:^40}|{:^20}|".format(name, code, signature))
except:
print("|{:^40}|{:^40}|{:^20}|".format("NA", "NA", "NA"))
def print_mps(self, flist):
print("|{:-^40}+{:-^40}+{:-^20}|".format("Name", "MP", "Signature"))
for i in flist:
name = i.get("name", "N/A")
mp = i.get("mp", "NA")
signature = i.get("signature_count", -1)
try:
print("|{:^40}|{:^40}|{:^20}|".format(name, mp, signature))
except:
print("|{:^40}+{:^40}+{:^20}|".format("NA", "NA", "NA"))