Created
March 8, 2013 05:18
-
-
Save bentsai/5114365 to your computer and use it in GitHub Desktop.
dayoneposter
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 dropboxclient | |
import urllib | |
import webbrowser | |
import datetime | |
def get_log_files(logdir): | |
client = dropboxclient.get_client() | |
metadata = client.metadata(logdir) | |
print metadata | |
files = [] | |
for item in metadata['contents']: | |
file_path = item['path'] | |
file_contents = client.get_file(file_path).read() | |
date = datetime.datetime.strptime(item['modified'], '%a, %d %b %Y %H:%M:%S +0000') | |
files.append({ | |
'Entry Text': file_contents, | |
'Creation Date': date | |
}) | |
return files | |
def post_to_dayone(content): | |
text = content.encode('utf-8') | |
text = urllib.quote(text, safe='') | |
urlstring = 'dayone://post?entry=' + text | |
print urlstring | |
webbrowser.open(urlstring) | |
if __name__ == '__main__': | |
content_list = get_log_files('/Log/') | |
for content in content_list: | |
print 'File: ', content['Entry Text'] | |
print 'Created: ', content['Creation Date'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment