Skip to content

Instantly share code, notes, and snippets.

View leighmacdonald's full-sized avatar

Leigh MacDonald leighmacdonald

View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from transmissionrpc import Client, DEFAULT_PORT
"""
Simple script to clean out torrents that are no longer registered with
a tracker.
"""
RM_MESSAGES = {
# -*- coding: utf-8 -*-
"""
"""
from __future__ import unicode_literals, absolute_import
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
from urllib import urlopen
import time
class BaseReleaseKey(object):
"""
Basic info for a release used to make a unique identifier for a release name
"""
def __init__(self, release_name, name, release_key=None, media_type=constants.MEDIA_UNKNOWN):
self.release_name = release_name
self.name = name
self.release_key = release_key if release_key else name
self.media_type = media_type
@leighmacdonald
leighmacdonald / memoize.py
Created June 4, 2013 07:29
Python memoize with dogpile
from dogpile.cache import make_region
# Define basic in memory caches
user = make_region().configure('dogpile.cache.memory', expiration_time=300)
ip = make_region().configure('dogpile.cache.memory', expiration_time=300)
def memoize(cache_region, ttl=300, ttl_ignore=False):
""" Memoized value cache decorator with expiration TTL support.
-- MySQL dump 10.13 Distrib 5.1.61, for redhat-linux-gnu (x86_64)
--
-- Host: localhost Database: geo
-- ------------------------------------------------------
-- Server version 5.1.61
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
@leighmacdonald
leighmacdonald / regions.csv
Created June 8, 2012 03:04
Region Mappings
AD 02 Canillo
AD 03 Encamp
AD 04 La Massana
AD 05 Ordino
AD 06 Sant Julia de Loria
AD 07 Andorra la Vella
AD 08 Escaldes-Engordany
AE 01 Abu Dhabi
AE 02 Ajman
AE 03 Dubai
@leighmacdonald
leighmacdonald / countries.csv
Created June 8, 2012 02:59
Country Mappings
A1 Anonymous Proxy
A2 Satellite Provider
O1 Other Country
AD Andorra
AE United Arab Emirates
AF Afghanistan
AG Antigua and Barbuda
AI Anguilla
AL Albania
AM Armenia
@leighmacdonald
leighmacdonald / import_geo.py
Created June 7, 2012 19:46
MaxMind normalized Import Script
#!/usr/bin/python
from __future__ import print_function
from sys import exit
from logging import getLogger, DEBUG, INFO, basicConfig
from urllib2 import urlopen, HTTPError
from urllib import urlretrieve
from gzip import open as gzopen
from datetime import datetime
from collections import defaultdict
from zipfile import ZipFile, is_zipfile
@leighmacdonald
leighmacdonald / cc.py
Created December 26, 2011 20:41
Object Cache state
class CachedContent(object):
"""
Keep track of a objects cache state. This is meant to prevent useless database calls primarily
"""
def __init__(self, mutable_keys=(), strict_keys=False):
""" Initially set the cache to a clean state
:param mutable_keys: List of valid mutable property names
:type mutable_keys: iterable
:param strict_keys: Check for key validity