Skip to content

Instantly share code, notes, and snippets.

View mdornseif's full-sized avatar

Maximillian Dornseif mdornseif

View GitHub Profile
#!/usr/bin/env python
# encoding: utf-8
"""
paffrater.py - Dieses Progrtamm liesst Volksbank Kontoauszüge und konvertiert sie in OFX.
OFX wurde mit xero.com getestet.
Created by Maximillian Dornseif on 2010-06-05.
Copyright (c) 2010, 2013 HUDORA. All rights reserved.
"""
@mdornseif
mdornseif / Makefile
Last active December 27, 2015 08:59
Makefile snippet to ensure python code quality
# Dateien, die wir strenger checken.
STRICT_LINT_FILES= views/admin.py modules/beliza
# Alle Projektdateien
LINT_FILES= $(STRICT_LINT_FILES) *.py controllers/ modules/ views/ bin/import_rechnung.py
LINT_LINE_LENGTH= 110
LINT_FLAKE8_ARGS= --max-complexity=18 --builtins=_ --max-line-length=$(LINT_LINE_LENGTH)
GOOD_NAMES=_,setUp,application,fd,gaetk_replication_SQL_INSTANCE_NAME,gaetk_replication_SQL_DATABASE_NAME,gaetk_replication_SQL_QUEUE_NAME
def ig2adn(profile):
logging.debug(profile)
instagram_client = InstagramAPI(access_token=profile.ig_access_token)
try:
media, next = instagram_client.user_recent_media()
except InstagramAPIError, msg:
if 'The "access_token" provided is invalid.' in str(msg):
# profile.ig_access_token = None
# profile.put()
return
class UeCheckin2(gaetk.handler.BasicHandler):
def put(self, uuid):
key = "sekrit" # determined by some other process
bodyhash = base64.b64encode(hashlib.sha256(self.request.body).digest())
toBeSigned = "&".join([self.request.method, self.request.path, bodyhash])
signature = base64.b64encode(hmac.new(key, toBeSigned, hashlib.sha256).digest())
header = self.request.headers['Authorization']
typ, value = header.split()
if typ != 'X-Signature':
raise gaetk.handler.HTTP401_Unauthorized
@mdornseif
mdornseif / appengine_config.py
Created September 24, 2013 10:20
Limiting certain countries
class RateLimitTimeMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
if environ.get('HTTP_X_APPENGINE_COUNTRY', '??') in ['KW', 'CN']:
start_response('429 Too Many Requests', [('Content-type', 'text/html')])
return ["""<html><head><title>429 Too Many Requests, sorry...</title>
<style>body { font-family: verdana, arial, sans-serif; background-color: #fff; color: #000; }</style>
</head><body><div style="margin-left: 4em;"><h1>We're sorry...</h1>
#!/usr/bin/env python
# encoding: utf-8
import sys
def main():
if len(sys.argv) < 2:
sys.stderr.write('Usage: %s filename\n' % sys.argv[1])
sys.exit()
{
"meta": {
"code": 200
},
"data": {
"created_at": "2013-06-23T11:12:04Z",
"num_stars": 0,
"num_replies": 0,
"source": {
"link": "http:\/\/im-fluss.appspot.com",
{
"meta": {
"code": 200
},
"data": {
"created_at": "2013-06-09T21:35:09Z",
"num_stars": 1,
"num_replies": 0,
"source": {
"link": "http:\/\/im-fluss.appspot.com",
{
"meta": {
"code": 200
},
"data": {
"created_at": "2013-06-09T07:39:00Z",
"num_stars": 0,
"num_replies": 0,
"source": {
"link": "http:\/\/im-fluss.appspot.com",
"images": {
"low_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_6.jpg",
"width": 306,
"height": 306
},
"thumbnail": {
"url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_5.jpg",
"width": 150,
"height": 150