Skip to content

Instantly share code, notes, and snippets.

View breyten's full-sized avatar

Breyten Ernsting breyten

View GitHub Profile
@breyten
breyten / get_climates.py
Created August 9, 2016 09:37
Gets climate data from wikipedia country pages
#!/usr/bin/env python
import os
import sys
import re
from pprint import pprint
import json
from time import sleep
import requests
from BeautifulSoup import BeautifulSoup
@breyten
breyten / parse_big_xml.py
Last active June 8, 2016 11:36
Parsing big pretty printed XML files
import sys
import os
import re
import codecs
from lxml import etree
def parse_big_xml(filename, item_tag=u'item'):
with codecs.open(filename, 'r', 'utf-8') as in_file:
output = u''
@breyten
breyten / get_amsterdam_datapunt.sh
Created March 15, 2016 13:54
Get amsterdam datapoints
#!/bin/bash
for SET in `wget -q -O - 'https://api.datapunt.amsterdam.nl/gebieden/' |jq '.[]' |sed -e 's/"//g;'`; do
echo $SET
for PART in `wget -q -O - $SET |jq '.results[] |._links.self.href' |sed -e 's/"//g;'`; do
echo "* $PART"
wget -q -x $PART
done
done
@breyten
breyten / combine_results.py
Created August 28, 2015 14:28
combine_results.py
party_counts = sorted([
{'party': p, 'count': get_party_count(p, session)} for p in parties],
key=lambda x: x['count'])
pprint(party_counts)
all_people = politicians + executives
politician_counts = sorted([
{'politician': p, 'count': get_politician_count(p, session)} for p in all_people],
key=lambda x: x['count'])
@breyten
breyten / query_npo_backstage.py
Last active August 28, 2015 13:07
Query NPO backstage API for the name of a person.
#!/usr/bin/env python
import requests
from BeautifulSoup import BeautifulSoup
NPO_BACKSTAGE_BASE_URL = 'http://backstage-api.npo.nl'
NPO_BACKSTAGE_ENDPOINT_SEARCH = '/v0/search'
def get_politician_count(politician, session):
SEARCH_DATA = {
@breyten
breyten / get_dutch_politicians.py
Created August 28, 2015 12:53
Get dutch politicians (mps and executives)
#!/usr/bin/env python
import requests
from BeautifulSoup import BeautifulSoup
def get_politicians(session):
url = u'http://www.tweedekamer.nl/kamerleden/alle_kamerleden'
resp = session.get(url)
if resp.status_code != 200:
return None
@breyten
breyten / GithubNewIssueDefaults.js
Last active August 29, 2015 13:56
Make a new issue have sane defaults by setting a default milestone & assignee
// ==UserScript==
// @name GithubNewIssueDefaults
// @namespace http://yerb.net/
// @version 0.1
// @description Make a new issue have sane defaults -- milestone & assignee
// @match https://github.com/*/*/issues/new
// @copyright 2013, Breyten Ernsting
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
@breyten
breyten / bitcoin_hider.js
Last active December 31, 2015 20:09
Hide Bitcoin articlens on HN with TamperMonkey
// ==UserScript==
// @name HNBitcoinHider
// @namespace http://yerb.net/
// @version 0.1
// @description Hide bitcoin news items on Hacker News
// @match https://news.ycombinator.com*
// @copyright 2013, Breyten Ernsting
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
@breyten
breyten / middleware.py
Created December 11, 2013 11:49
Modify the locale middleware in python to not look at the HTTP_ACCEPT_LANGUAGE header (and just use the language specified in the settings or the user's preferences)
import os
import sys
import re
from django.utils import translation
from django.middleware.locale import LocaleMiddleware
class LocaleNoHTTPAcceptMiddleware(LocaleMiddleware):
def process_request(self, request):
request.LANGUAGE_CODE = translation.get_language()
@breyten
breyten / authentication.py
Created December 9, 2013 16:08
Middleware for Django to authenticate a user with an OAuth token
from pprint import pprint
import re
from django.conf import settings
from django.contrib.auth.models import User, check_password
from django.contrib.auth import authenticate, login
from apps.api.authentication import verify_access_token, OAuthError
class OAuth2Middleware( object ):