Skip to content

Instantly share code, notes, and snippets.

View jbothma's full-sized avatar

JD Bothma jbothma

View GitHub Profile
@jbothma
jbothma / voter turnout 2016.sql
Created May 9, 2017 11:49
BAD voter turnout 2016
BEGIN;
CREATE TEMPORARY TABLE municipal_election
(
province TEXT,
muni TEXT,
ward TEXT,
votingdistrict TEXT,
votingstationname TEXT,
registeredvoters TEXT,
@jbothma
jbothma / municipal-elections.sql
Last active May 4, 2017 13:51
Import party votes per geographic area for 2016 municipal elections to wazimap ZA
-- Remove BOM for psql \copy
-- sed -i '/^\s*$/d' *
-- Remove blank lines for psql \copy
-- sed -i '1s/^\xEF\xBB\xBF//' *
BEGIN;
CREATE TEMPORARY TABLE municipal_election
(
province TEXT,
@jbothma
jbothma / import2016mapit.sql
Last active April 26, 2017 08:59
Wazimap ZA 2016 demarcation names import from Mapit (code4sa/OpenUp)
BEGIN;
CREATE TEMPORARY TABLE geos2016
(
geo_level TEXT,
geo_code TEXT,
name TEXT,
parent_code TEXT,
parent_level TEXT
) ON COMMIT DROP;
@jbothma
jbothma / flatten.py
Created March 29, 2017 13:08
Flatten/denormalise nested json objects in jsonlines input file to a flat CSV.
import fileinput
import json
import sys
import csv
from copy import copy
fieldnames = [
'regno',
'name',
'status',
@jbothma
jbothma / kzn_lawsoc_spider.py
Last active February 16, 2017 12:55
Scrapy Spider to scrape HTML table with identifiers in first column and related links on same and subsequent rows
"""
(KwaZulu-Natal Provincial Gazette v.1 no.1 published 2007-05-03)
Last gazette before it seems to be
"KwaZulu-Natal Provincial Provincial Gazette 6553 2007-04-26"
"""
from datetime import datetime
from gazettescrape.items import GazetteItem
from scrapy import Request
{
"name": "GRO_DOH_Citizen_Survey",
"title": "GRO - DOH Citizen Survey",
"sms_keyword": "GRO_DOH_Citizen_Survey",
"default_language": "default",
"version": "1.0",
"id_string": "GRO_DOH_Citizen_Survey",
"type": "survey",
"children": [
{
@jbothma
jbothma / README.md
Last active November 28, 2016 17:06
Geo Coordinate parsing challenge

Capital Spending by Municipalities in South Africa

The SA36 tables from the MFMA website by the South African National Treasury contain geographic coordinates of locations of assets where the municipality is spending on capital.

These coordinates are supplied as free text. We're trying to parse them into Decimal Degrees and store them in dedicated Latitude and Longitude columns, as shown in parsed_coordinates.csv below.

Would you like to help?

The regexes used to parse these so far can be found in the script below:

How we built Open Gazettes

Government gazettes are valuable entities in and of themselves. They’ve been consumed, published and archived in this form for centuries. This is why before building the resource, we needed to have some of what additional value we could provide. The majority of poeple who use gazettes tend to be lawyers, librarians and special interest groups. So, we asked ourselves, “How can gazettes be made available to the general public in a way that helps them to participate in policy-making and governance?”

Currently, government gazettes still look like they’re produced on the printing presses of the 1800s. Their text flows neatly from page to page, and whether it’s a 50-word liquidation notice, or a 400-page green paper, it will be published in the same format as gazettes always have been.

Perhaps when we started publishing gazettes, even before the Union and the Republic of South Africa, the newspaper format made sense; but today people consume information in very different ways and a

@jbothma
jbothma / gist:e3223120364a7093cb1bfd9cacc16950
Created October 4, 2016 19:43
pyconza2016 code4sa codebridge
title
- hello
- who am I
code4sa
- tech
- informed decision making
. for positive social change
codebridge
@jbothma
jbothma / gist:14f7b8a9b2f6a305ad0e1fcbdf61b385
Created August 13, 2016 16:00
CPT <30 days 2015-2016 month 9
municipal_finance=> select l.code, l.label, customer_group_code, l30_amount from aged_debtor_facts f, aged_debtor_items l where f.item_code = l.code and demarcation_code = 'CPT' and financial_year = 2016 and financial_period = 09 and amount_type_code = 'ACT' order by position_in_return_form limit 30;
code | label | customer_group_code | l30_amount
------+----------------------------------------------------------------------+---------------------+------------
1100 | Debtors Age Analysis By Income Source | | 0
1100 | Debtors Age Analysis By Income Source | 2290 | 0
1100 | Debtors Age Analysis By Income Source | 2301 | 0
1100 | Debtors Age Analysis By Income Source | 2401 | 0
1200 | Trade and Other Receivables from Exchang