Skip to content

Instantly share code, notes, and snippets.

@gfranxman
gfranxman / q.py
Created March 1, 2012 17:04
twisted q
from twisted.internet import reactor, protocol
from twisted.protocols import policies
from twisted.protocols import basic
import queue
WAITING = 'waiting'
COLLECTING = 'collecting'
IDLE = 'idle'
@gfranxman
gfranxman / mlb.py
Created June 18, 2013 20:24
mlb boxscores
#! /usr/bin/python
import urllib2
from datetime import datetime, timedelta
import simplejson as JSON
from pprint import pprint
import re
when = datetime.now() #- timedelta(days=1)
@gfranxman
gfranxman / hookedftp.py
Last active February 5, 2018 12:58
twisted ftp server with hook
"""
Twisted Sports FTP server, simple auth and post upload hook.
NOTE: In the spirit of doing it the hard way first, it now feels like I should have used
reactor.addWriter to install the HookFileWriter instead of these acrobatics.
Does the reactor really hold the filewriter for these tasks?
"""
from twisted.protocols.ftp import FTPFactory, FTPRealm, errnoToFailure
from twisted.cred.portal import Portal
$ curl https://api.spark.io/v1/devices/...DEVICE_TOKEN.../digitalwrite -d access_token=...ACCESS_TOKEN... -d params=D7,HIGH
{
"id": "48ff6f065067555023342387",
"name": "gerbils",
"last_app": null,
"connected": true,
"return_value": 1
}
*.pyc
@gfranxman
gfranxman / logwrapper.py
Created September 17, 2014 14:49
Python Logging Decorator
from functools import wraps
import logging
def arglist( *args, **kwargs ):
s = ""
for a in args:
s += repr(a) + ","
for k,v in kwargs.items():
s += "{k}={v}, ".format( k= k, v=repr(v) )
@gfranxman
gfranxman / gist:4d6e1e8543abc3c0d203
Last active August 29, 2015 14:09
celerybeat crontab
from django.conf import settings
settings.CELERY_APP.conf
settings.CELERY_APP.tasks
settings.CELERY_APP.conf['CELERYBEAT_SCHEDULE']
for k in settings.CELERY_APP.conf['CELERYBEAT_SCHEDULE']:
t = settings.CELERY_APP.conf['CELERYBEAT_SCHEDULE'][k]
print t['schedule'], t['task']
...
<crontab: 0 */12 * * * (m/h/d/dM/MY)> proxypages.tasks.refresh_twice_daily
<crontab: 0 */4 * * * (m/h/d/dM/MY)> proxypages.tasks.refresh_four_hour
# source this code in a Bash shell
# and run like django-post-payload '{"a": "b"}'
# you can set the credentials by exporting DJANGO_USER and DJANGO_PASSWORD
django-post-payload() {
local TARGET=http://ws.somesite.com/some/service/endpoint/
local PAYLOAD=$1
#"{\"asd\": \"asd\"}"
local LOGIN=http://ws.somesite.com/login/
#
import inspect
class ReprFromInit( object ):
def __repr__( self ):
args = inspect.getargspec( self.__class__.__init__ ).args
path = "{modulename}.{classname}".format( modulename=self.__class__.__module__, classname=self.__class__.__name__ )
argstrs = []
for arg in args[1:]: # skip self
for argname in [ arg, "_"+arg, '' ]:
if hasattr( self, argname ):
break
@gfranxman
gfranxman / doit
Created April 15, 2015 19:17
my pypi pub process
# build
python setup.py sdist
python setup.py bdist_wheel
read
#register with test system
# python setup.py register -r pypitest
# read
# upload to test system