comparison bitsyblog/utils.py @ 0:e3823be6a423

initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
author k0s <k0scist@gmail.com>
date Sat, 12 Sep 2009 16:06:57 -0400
parents
children 794dac65c9b6
comparison
equal deleted inserted replaced
-1:000000000000 0:e3823be6a423
1 """utlity functions for bitsyblog"""
2
3 import datetime
4 import os
5 import urllib
6 import urllib2
7
8 # format to uniquely label blog posts
9 timeformat = ( 'YYYY', 'MM', 'DD', 'HH', 'MM', 'SS' )
10 timestamp = '%Y%m%d%H%M%S' # strftime representation
11
12 def validate_css(css):
13 """use a webservice to determine if the argument is valid css"""
14 url = 'http://jigsaw.w3.org/css-validator/validator?text=%s'
15 url = url % urllib.quote_plus(css)
16 foo = urllib2.urlopen(url)
17 text = foo.read()
18 return not 'We found the following errors' in text
19
20 def date(datestamp):
21 datestamp = os.path.split(datestamp)[-1]
22 retval = []
23 for i in timeformat:
24 retval.append(int(datestamp[:len(i)]))
25 datestamp = datestamp[len(i):]
26 return datetime.datetime(*retval)
27
28 def datestamp(date):
29 return date.strftime(timestamp)