-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcivics.py
More file actions
73 lines (62 loc) · 1.95 KB
/
civics.py
File metadata and controls
73 lines (62 loc) · 1.95 KB
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
63
64
65
66
67
68
69
70
71
72
73
from government import Government
#from largest_city import LargestCity
from csv_writer import CsvWriter
import pprint
from country_utils import CountryUtils
'''
class Civics:
def __init__(self):
#self.cities = LargestCity()
self.leaders = Government()
def write_csv(self):
data = self.combine_data()
csv = CsvWriter(
'countries',
data,
headers = [
'Country',
'Country info',
'Most populous city',
'Head of government'
],
datestamp=True
)
csv.diff()
csv.archive()
def combine_data(self):
cities = {}#self.cities.data
leaders = self.leaders.data
combined = {}
pp = pprint.PrettyPrinter()
self.add_dicts(combined, cities, 'Most populous city')
self.add_dicts(combined, leaders, 'Head of government')
self.add_notes(combined)
return self.to_list(combined)
def add_dicts(self, target, src, key):
for nation, v in src.items():
if nation not in target:
target[nation] = {}
target[nation][key] = v
def add_notes(self, combined):
for nation, note in CountryUtils.NOTES.items():
combined[nation]['Country info'] = note
def to_list(self, combined):
data = []
for nation, nation_data in combined.items():
nation_dict = nation_data
nation_dict['Country'] = nation
data.append(nation_dict)
return data
Civics().write_csv()
'''
Government().write_csv()
'''
problems = ['Belarus', 'Bosnia and Herzegovina', 'Haiti', 'Sudan', 'Switzerland', 'Turkmenistan']
for nation in problems:
if nation in leaders:
print(f'{nation}: {leaders[nation]}')
else:
print(f'{nation} not in leaders!')
'''
#pp = pprint.PrettyPrinter()
#pp.pprint(leaders)