-
Notifications
You must be signed in to change notification settings - Fork 6
/
iati_org.py
52 lines (41 loc) · 1.79 KB
/
iati_org.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
from datetime import datetime
timestamp=datetime.now().replace(microsecond=0).isoformat()
header_t="""
<iati-organisation version="1.01" last-updated-datetime="%s" xml:lang="en" default-currency="USD">
<iati-identifier>US-MCC-1</iati-identifier>
<ir:registry-record xmlns:ir="http://iatiregistry.org/ns/record#" xml:lang="en" file-id="US-MCC-1"
source-url="http://data.mcc.gov/raw/iati/organisation.xml" publisher-id="US-MCC-1"
publisher-role="Funding" contact-email="opendata@mcc.gov" donor-id="US-MCC-1" donor-type="10"
donor-country="US" title="MCC Organisation File" activity-period="All Periods"
last-updated-datetime="%s"
generated-datetime="%s" verification-status="1" format="xml" license="IATI" />
<name>Millennium Challenge Corporation</name>
"""
footer_t="""
</iati-organisation>
"""
budget_t="""
<total-budget>
<period-start iso-date="2010-04-01">01 April 2010</period-start>
<period-end iso-date="2011-03-31">31 March 2011</period-end>
<value value-date="2010-10-20">7800000000</value>
</total-budget>"""
country_budget_t="""
<recipient-country-budget>
<recipient-country code="ZW">Zimbabwe</recipient-country>
<period-start iso-date="2014-04-01">Start of Financial Year 2014/15</period-start>
<period-end iso-date="2015-03-31">End of Financial Year 2014/15</period-end>
<value currency="USD" value-date="2014-04-01">94000000</value>
</recipient-country-budget>"""
doc_t="""<document-link url="%s" format="%s">
<title>%s</title>
<category code="%s">%s</category>
</document-link>"""
fo=open("output/mcc-organisation.xml","w")
fo.write(header_t % (timestamp,timestamp,timestamp))
fi=open("source/documents.csv","rU")
for line in fi:
category, code,title,url,format=line.strip().split(" ")
fo.write(doc_t % (url, format, title, code, category))
fo.write("\n")
fo.write(footer_t)