diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitsyblog/utils.py	Sat Sep 12 16:06:57 2009 -0400
@@ -0,0 +1,29 @@
+"""utlity functions for bitsyblog"""
+
+import datetime
+import os
+import urllib
+import urllib2
+
+# format to uniquely label blog posts
+timeformat = ( 'YYYY', 'MM', 'DD', 'HH', 'MM', 'SS' )
+timestamp = '%Y%m%d%H%M%S' # strftime representation
+
+def validate_css(css):
+    """use a webservice to determine if the argument is valid css"""    
+    url = 'http://jigsaw.w3.org/css-validator/validator?text=%s'
+    url = url % urllib.quote_plus(css)
+    foo = urllib2.urlopen(url)
+    text = foo.read()
+    return not 'We found the following errors' in text
+
+def date(datestamp):
+    datestamp = os.path.split(datestamp)[-1]
+    retval = []
+    for i in timeformat:
+        retval.append(int(datestamp[:len(i)]))
+        datestamp = datestamp[len(i):]
+    return datetime.datetime(*retval)
+
+def datestamp(date):
+    return date.strftime(timestamp)