Skip to content

Instantly share code, notes, and snippets.

@flagranterror
Created September 12, 2014 12:01
Show Gist options
  • Save flagranterror/3f52a9fead3718e02607 to your computer and use it in GitHub Desktop.
Save flagranterror/3f52a9fead3718e02607 to your computer and use it in GitHub Desktop.
!/usr/bin/env python
import os
import json
from sys import argv
from time import strftime
def firstrun():
x = {}
x['jf'] = raw_input("File name?: ")
x['use_date'] = raw_input("Use date stamp [y/n]?: ")
return x
try:
if os.environ.get('LOCALAPPDATA'):
cf = os.path.join(os.environ['LOCALAPPDATA'], '_pyjot.conf')
elif os.environ.get('HOME'):
cf = os.path.join(os.environ['HOME'], '.pyjot.conf')
else:
raise Exception("Something went wrong.")
except Exception as e:
print "Couldn't determine config file location"
exit(1)
print cf
try:
if os.path.exists(cf):
fh = open(cf, 'r')
config = json.load(fh)
else:
fh = open(cf, 'w')
ic = firstrun()
config = {'journal_file': ic['jf'], 'use_date': ic['use_date']}
json.dump(config, fh)
except:
print "Couldn't deserialize config"
finally:
fh.close()
try:
if config['use_date'].lower() == 'y':
pre = strftime("%Y-%m-%d-")
journal = os.path.join(os.path.dirname(config['journal_file']),
pre + os.path.basename(config['journal_file']))
jf = open(journal, 'a')
except:
print "Couldn't open journal.\n"
entry = str(strftime('%m/%d/%y, %I:%M %p:'))
entry += "\n"
for word in argv[1:]:
entry += word + ' '
entry += "\n\n------\n"
jf.write(entry)
jf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment