Created
July 9, 2010 06:51
-
-
Save ecounysis/469157 to your computer and use it in GitHub Desktop.
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
import httplib, os, urllib, base64, datetime | |
folder = <<workfolder>> | |
url = "posterous.com" | |
user = <<userid>> | |
def file_contents(filename): | |
readfile = open(folder + "\\" + filename, 'r') | |
date = readfile.readline().strip('\n') | |
content = readfile.read() | |
content = content.replace("\n","<br/>") | |
readfile.close() | |
title = filename[0:filename.find('.')] | |
#print (title, date, content) | |
return (title,date,content) | |
def move_file(fn): | |
os.rename(folder + "\\" + fn, folder + "\\posted\\" + fn) | |
def post_to_posterous(ttt): | |
title = ttt[0] | |
date = ttt[1] | |
if (date == ""): | |
date = str(datetime.datetime.now()) | |
content = ttt[2] | |
body = urllib.urlencode({"body":content,"title":title,"date":date}) | |
headers = {"Content-type": "application/x-www-form-urlencoded"} | |
header_text = base64.encodestring(user + ":" + password) | |
header_text = "Basic " + header_text[:-1] | |
headers["Authorization"] = header_text | |
conn = httplib.HTTPConnection(url) | |
conn.request("POST", "/api/newpost", body, headers) | |
resp = conn.getresponse() | |
print resp.read() | |
conn.close() | |
password = raw_input('pw>>') | |
for f in os.listdir(folder): | |
if (f[f.find('.')+1:]=='post'): | |
post_to_posterous(file_contents(f)) | |
move_file(f) | |
raw_input('press enter to close') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment