Skip to content

Instantly share code, notes, and snippets.

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "csv";
declare option output:csv "header=yes, separator=comma";
<csv>{
for $org in /iati-organisations/iati-organisation
return <record>
<organisation-identifier>{
if ($org/organisation-identifier)
then $org/organisation-identifier/text()
else $org/iati-identifier/text()
import os
import json
import requests
repos = requests.get('https://api.github.com/orgs/OpenDataServices/repos?per_page=200').json()
for repo in repos:
protection = requests.get(
"https://api.github.com/repos/OpenDataServices/{}/branches/master/protection".format(repo["name"]),
headers={"Authorization": "token {}".format(os.environ["GH_TOKEN"])},
@Bjwebb
Bjwebb / 0_xquery.xq
Last active February 28, 2024 22:38
<codelist><metadata/><codelist-items>{
for $org in /iati-organisations/iati-organisation
let $code := if ($org/organisation-identifier)
then $org/organisation-identifier/text()
else $org/iati-identifier/text()
return if ($code = $org/reporting-org/@ref/data()) then
<codelist-item>
<code>{$code}</code>
{if ($org/name/narrative)
then $org/name else
from lxml import etree
root = etree.parse('csvconv.xml')
for activity in root.findall('iati-activity'):
for transaction in activity.findall('transaction'):
if transaction.find('value').text is None:
activity.remove(transaction)
root.write('transactions_removed.xml')
@Bjwebb
Bjwebb / badfile.json
Last active May 6, 2020 09:19
Generate 340MB of invalid OCDS data by repeating a single bad release
{
"uri": "tmXf6cC4QU+lwO3O73T-ZvUX4qo2GMJ0Sd",
"publisher": {
"name": "ducimus recusandae"
},
"publishedDate": "4440-04-11T01:58:02.871Z",
"releases": [
{
"ocid": "et et tempora eos est",
"id": "facere",
{
"uri": "http://example.org/invalid_record.json",
"version": "1.1",
"publishedDate": "2019-09-18T17:56:21.078Z",
"publisher": {
"name": "A Publisher Name"
},
"records": [
{
"ocid": "EXAMPLE-0",
@Bjwebb
Bjwebb / schema_properties.py
Last active February 15, 2019 05:35
List the schema level properties used in a JSON schema
import os
import json
import jsonref
# From libcove/lib/common.py
class CustomJsonrefLoader(jsonref.JsonLoader):
'''This ref loader is only for use with the jsonref library
and NOT jsonschema.'''
def get_remote_json(self, uri, **kwargs):
<?xml version='1.0' encoding='UTF-8'?>
<!--This is example XML for the IATI activity standard. No reference to actual data, real organisations or development cooperation models is intended.-->
<!--iati-activities starts-->
<iati-activities generated-datetime="2014-09-10T07:15:37Z" version="2.03" linked-data-default="http://data.example.org/">
<!--iati-activity starts-->
<iati-activity xml:lang="en" default-currency="USD" last-updated-datetime="2014-09-10T07:15:37Z" humanitarian="1" linked-data-uri="http://data.example.org/123456789" hierarchy="1" budget-not-provided="1">
<!--iati-identifier starts-->
@last-updated-datetime @default-currency organisation-identifier name/narrative reporting-org/@ref reporting-org/@type reporting-org/@secondary-reporter reporting-org/narrative total-budget/0/@status total-budget/0/period-start/@iso-date total-budget/0/period-end/@iso-date total-budget/0/value total-budget/0/value/@currency total-budget/0/value/@value-date total-budget/0/budget-line/0/@ref total-budget/0/budget-line/0/value total-budget/0/budget-line/0/value/@currency total-budget/0/budget-line/0/value/@value-date total-budget/0/budget-line/0/narrative recipient-org-budget/0/@status recipient-org-budget/0/recipient-org/@ref recipient-org-budget/0/recipient-org/narrative recipient-org-budget/0/period-start/@iso-date recipient-org-budget/0/period-end/@iso-date recipient-org-budget/0/value recipient-org-budget/0/value/@currency recipient-org-budget/0/value/@value-date recipient-org-budget/0/budget-line/0/@ref recipient-org-budget/0/budget-line/0/value recipient-org-budget/0/budget-line/0/value/@currency recipien
@last-updated-datetime @default-currency @humanitarian @hierarchy @linked-data-uri @budget-not-provided iati-identifier reporting-org/@ref reporting-org/@type reporting-org/@secondary-reporter reporting-org/narrative title/narrative description/0/@type description/0/narrative participating-org/0/@ref participating-org/0/@type participating-org/0/@role participating-org/0/@activity-id participating-org/0/@crs-channel-code participating-org/0/narrative other-identifier/0/@ref other-identifier/0/@type other-identifier/0/owner-org/@ref other-identifier/0/owner-org/narrative activity-status/@code activity-date/0/@type activity-date/0/@iso-date activity-date/0/narrative contact-info/0/@type contact-info/0/organisation/narrative contact-info/0/department/narrative contact-info/0/person-name/narrative contact-info/0/job-title/narrative contact-info/0/telephone contact-info/0/email contact-info/0/website contact-info/0/mailing-address/0/narrative activity-scope/@code recipient-country/0/@code recipient-country/0/@perc