summaryrefslogtreecommitdiff
path: root/app/blog/parse.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
committerluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
commit518b2d618bc10f93cfa44a83715593b8358eb9ce (patch)
treea07993c3ae31bed42f32c0e00788989568790716 /app/blog/parse.py
parent4bae11bb25a8e3c43118891d17fd8e981ecf8dc6 (diff)
minor refactor to adoipt pep8 and pyflakes coding styles and clean up
some cruft that's been hangin round for years
Diffstat (limited to 'app/blog/parse.py')
-rwxr-xr-xapp/blog/parse.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/app/blog/parse.py b/app/blog/parse.py
index 27f5165..a1e3056 100755
--- a/app/blog/parse.py
+++ b/app/blog/parse.py
@@ -1,12 +1,14 @@
#!/usr/bin/python
-import os, datetime
+import os
+import datetime
from dateutil.parser import parse as dateparser
-from os.path import abspath,dirname
+from os.path import abspath, dirname
from django.core.exceptions import ObjectDoesNotExist
from blog.models import Entry
from django.conf import settings
+
def parse_file(filepath):
data = {}
contents = open(filepath).read()
@@ -15,13 +17,13 @@ def parse_file(filepath):
if line == '---':
break
else:
- k,v = line.split(':', 1)
+ k, v = line.split(':', 1)
data[k.strip()] = v.strip()
body = "\n".join(line.strip() for line in raw[1:])
data["body_markdown"] = body.split('---')[1]
return data
-"""
+"""
now I need a function to query the db for the title and date
if there's no entry then it's new and we add it and publish
What about edits though? Crap, edits. That means we need to check lastmod
@@ -30,23 +32,25 @@ from blog.parse import *
crawl_dir()
"""
+
+
def crawl_dir():
file_root = settings.POSTS_DIR
file_list = os.listdir(file_root)
- file_list = filter(lambda item: not (item.startswith('README') or item.startswith('updategithub.php') or item.startswith('.') or item.endswith('~')),file_list)
- for f in file_list:
- fpath = file_root+"/"+f
+ file_list = filter(lambda item: not (item.startswith('README') or item.startswith('updategithub.php') or item.startswith('.') or item.endswith('~')), file_list)
+ for f in file_list:
+ fpath = file_root + "/" + f
last_mod = datetime.datetime.fromtimestamp(os.path.getmtime(fpath))
- last_run = datetime.datetime.fromtimestamp(os.path.getmtime(abspath(dirname(__file__))+'/last_run'))
- if last_mod > last_run:
+ last_run = datetime.datetime.fromtimestamp(os.path.getmtime(abspath(dirname(__file__)) + '/last_run'))
+ if last_mod > last_run:
print "needs an update"
data = parse_file(fpath)
date = dateparser(data['pub_date'])
try:
- row = Entry.objects.get(title=str(data['title']),pub_date=date)
+ row = Entry.objects.get(title=str(data['title']), pub_date=date)
print row.title, date
except ObjectDoesNotExist:
print data['title'] + str(date) + " = not found"
- last_mod_dump = open(abspath(dirname(__file__))+'/last_run','w')
+ last_mod_dump = open(abspath(dirname(__file__)) + '/last_run', 'w')
print last_mod_dump
print >> last_mod_dump, str(datetime.datetime.now())