Created
December 12, 2013 21:45
-
-
Save younata/7936121 to your computer and use it in GitHub Desktop.
Very hacky blog script. I stuck it in cron, it gets run daily as me.
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/local/bin/python | |
from webhelpers.feedgenerator import Atom1Feed | |
import os | |
import datetime | |
def genPost(webRoot, homeDir): | |
f = open(homeDir + "flightSim/post1.html") | |
idx = f.read() | |
f.close() | |
bl = webRoot | |
fs = bl + "flightSim/" | |
blog = bl + "blog/" | |
footer = "<hr /><p><a href=\"/feed.atom\"><img src=\"http://upload.wikimedia.org/wikipedia/en/thumb/4/43/Feed-icon.svg/200px-Feed-icon.svg.png\" width=32px></img></a></p></body></html>" | |
for files in os.listdir(fs): | |
if files.endswith(".html"): | |
title = files[:-5] | |
s = idx % title | |
f = open(fs + files, "r") | |
toread = f.read() | |
f.close() | |
f = open(blog + files, "w") | |
f.write(s + "<hr />" + toread + footer) | |
f.close() | |
def generateAtomFeed(webRoot, homeDir): | |
feed = Atom1Feed(title="Rachel Brindle", link="http://younata.com/feed.atom", description="Rachel Brindle") | |
items = {} | |
bl = webRoot | |
fs = bl + "flightSim/" | |
f = open(homeDir + "flightSim/base1.html") | |
idx = f.read() | |
f.close() | |
for files in os.listdir(fs): | |
if files.endswith(".html"): | |
s = os.stat(fs + files).st_birthtime | |
items[s] = files | |
keys = sorted(items.keys(), reverse=True) | |
for i in keys: | |
s = os.stat(bl + "/flightSim/" + items[i]); | |
pubdate = datetime.datetime.fromtimestamp(i) | |
title = items[i].split("html")[0][:-1] | |
f = open(fs + items[i]) | |
data = f.read() | |
idx += "<hr /><a href=\"%s\"><h3>%s</h3></a>" % ("/blog/" + items[i], title) | |
idx += data | |
f.close() | |
feed.add_item(title=title, link="http://younata.com/blog/"+items[i], description=data, pubdate=pubdate, author="Rachel Brindle") | |
f = open (bl + "feed.atom", "w") | |
f.write(feed.writeString("utf-8")) | |
f.close() | |
idx += "<hr /><p><a href=\"/feed.atom\"><img src=\"http://upload.wikimedia.org/wikipedia/en/thumb/4/43/Feed-icon.svg/200px-Feed-icon.svg.png\" width=32px></img></a></p></body></html>" | |
f = open(bl + "index.html", "w") | |
f.write(idx) | |
f.close() | |
if __name__ == "__main__": | |
import sys | |
from os.path import expanduser | |
webRoot = sys.argv[1] | |
homeDir = expanduser("~") | |
generateAtomFeed(webRoot, homeDir); | |
genPost(webRoot, homeDir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment