-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathget_links_from_ep.py
executable file
·35 lines (26 loc) · 1.13 KB
/
get_links_from_ep.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
#!/usr/bin/env python3
import operator
from everypolitician import EveryPolitician
from lxml import etree
def output_file(country, legislature, filename):
data = EveryPolitician().country(country).legislature(legislature)
output_filename = "../members/{0}.xml".format(filename)
root = etree.Element("publicwhip")
sorted_people = sorted(data.popolo().persons, key=operator.attrgetter("name"))
for person in sorted_people:
parlparse_id = person.identifier_value("parlparse")
if parlparse_id is not None:
props = {}
if person.twitter:
props["twitter_username"] = person.twitter
if person.facebook:
props["facebook_page"] = person.facebook
if props:
props["id"] = parlparse_id
info = etree.Element("personinfo", props)
root.append(info)
et = etree.ElementTree(root)
et.write(output_filename, pretty_print=True)
output_file("UK", "Commons", "social-media-commons")
output_file("Scotland", "Parliament", "social-media-sp")
output_file("Northern-Ireland", "Assembly", "social-media-ni")