This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Depends on the OS X "say" command | |
import time, datetime, subprocess, math, sys | |
def say(s): | |
subprocess.call(['say', str(s)]) | |
def seconds_until(dt): | |
return time.mktime(dt.timetuple()) - time.time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Memcached cache backend" | |
from django.core.cache.backends import memcached | |
from django.utils.encoding import smart_unicode, smart_str | |
MIN_COMPRESS_LEN = 150000 | |
class CacheClass(memcached.CacheClass): | |
def add(self, key, value, timeout=None, min_compress_len=MIN_COMPRESS_LEN): | |
if isinstance(value, unicode): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import os | |
import subprocess | |
import logging | |
from django.conf import settings | |
logger = logging.getLogger('pagetracker.grabber') | |
def grab_page(url, outfile): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link href="http://propublica.github.com/timeline-setter/public/stylesheets/timeline-setter.css" rel="stylesheet" /> | |
<script src="http://propublica.github.com/timeline-setter/public/javascripts/vendor/jquery-min.js"></script> | |
<script src="http://propublica.github.com/timeline-setter/public/javascripts/vendor/underscore-min.js"></script> | |
<script src="http://propublica.github.com/timeline-setter/public/javascripts/timeline-setter.js"></script> | |
<script src="../js/date.js"></script> | |
<style> | |
#timeline_setter .TS-item_label a { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import xlrd | |
import xlwt | |
from optparse import OptionParser | |
import datetime | |
""" | |
Merges excel files with multiple sheets with identical header lines into |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls.defaults import * | |
from timelineit.views import * | |
from django.views.decorators.cache import cache_control,never_cache | |
urlpatterns = patterns('timelineit.views', | |
url(r'^desk/(?P<slug>[-\w\d]+)', | |
never_cache(timeline_preview), | |
name="timeline_preview"), | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import re | |
import requests | |
def get_page_tag(url, title_re=re.compile(r'<title>(.*?)</title>', re.UNICODE )): | |
""" | |
Retrieves the title tag from a given url (or actually any tag if you want..) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.files.temp import NamedTemporaryFile | |
def save_image_from_url(self): | |
""" | |
Save remote images from url to image field. | |
Requires python-requests | |
""" | |
r = requests.get(self.image_url) | |
if r.status_code == 200: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CachedModelResource(ModelResource): | |
def create_response(self, *args, **kwargs): | |
resp = super(CachedModelResource, self).create_response(*args, **kwargs) | |
resp['Cache-Control'] = "max-age=600" | |
return resp |
OlderNewer