Skip to content

Instantly share code, notes, and snippets.

@luke
luke / picloud_health_check.py
Created July 17, 2013 09:19
Quick and dirty script to check status of last 100 jobs on picloud.
import logging
import requests
import lxml.html
import collections
def picloud_health_check(username, password):
# setup session
session = requests.Session()
session.verify = False
@luke
luke / flask_ses_log_handler.py
Created June 25, 2013 10:28
Special log handler for use in Flask which sends emails using Amazon SES. Wraps stream handler using StringIO Configure with log level and trigger level (at which to send emails)
#!/usr/bin/env python
import string, logging
from logging import StreamHandler
from flask import g
import boto
import StringIO
DEFAULT_FORMAT = "%(asctime)s %(levelname)-5s %(message)s"
DEFAULT_SUBJECT = "FlaskBufferingSESHandler log"
@luke
luke / migrate_zerigo_to_route53.py
Last active February 6, 2016 19:44
Migration script for moving from Zerigo DNS to Amazon Route 53.
import logging
import zerigodns
import boto
from boto.route53.record import ResourceRecordSets
from boto.s3.website import RedirectLocation
# There is no API for these so we have to embed and lookup
# https://forums.aws.amazon.com/thread.jspa?threadID=116724
# http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
@luke
luke / bulkupsert.py
Last active February 15, 2025 06:26
I needed to upsert (insert or update) bajillions of records into postgresql. After trying various libs including upsert (which was slow as hell) I ended up doing a bit of research and trying 3 different methods. This one won. While I'm manually building the sql string no user data is passed in. Its loaded via the copy from statement as CSV. Call…
import logging
import cStringIO
import csv
DEBUG = False
def data2csv(data):
si = cStringIO.StringIO()
cw = csv.writer(si, delimiter='\t',lineterminator="\n")
for row in data: