Skip to content

Instantly share code, notes, and snippets.

@davidbgk
Created January 27, 2013 23:23
Show Gist options
  • Save davidbgk/4651264 to your computer and use it in GitHub Desktop.
Save davidbgk/4651264 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import datetime
import os.path
import logging
import cmd
import doko
ROOT_FOLDER = "notes"
NOTE_FILENAME = "notes.md"
class NoteBook(cmd.Cmd):
"""Simple cli notebook."""
prompt = "log> "
def precmd(self, line):
# What is the date path NOW
notepath = "{root_folder}/{date_path}/{note_filename}".format(
root_folder=ROOT_FOLDER,
date_path=datetime.date.today().strftime('%Y/%m/%d'),
note_filename=NOTE_FILENAME
)
# if the directory of the note doesn't exist, create it.
notedir = os.path.dirname(notepath)
if not os.path.exists(notedir):
os.makedirs(notedir)
# if the file for notes today doesn't exist, create it.
logging.basicConfig(filename=notepath,
level=logging.INFO,
format='%(asctime)s - %(message)s')
return cmd.Cmd.precmd(self, line)
def default(self, line):
if line:
if line == u'location':
location = doko.location()
print u'LOCATION', location
logging.info("Location: {latitude}, {longitude}".format(
latitude=location.latitude,
longitude=location.longitude
))
else:
print datetime.date.today().isoformat(), line
logging.info(line)
def do_EOF(self, line):
return True
def postloop(self):
print
if __name__ == "__main__":
NoteBook().cmdloop()
@karlcow
Copy link

karlcow commented Jan 28, 2013

Il y a une meilleure façon de le faire. ;)
À voir https://github.com/karlcow/notebook/blob/master/nb.py#L45-L59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment