Created
January 27, 2013 23:23
-
-
Save davidbgk/4651264 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
# -*- 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): | |
if __name__ == "__main__": | |
NoteBook().cmdloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Il y a une meilleure façon de le faire. ;)
À voir https://github.com/karlcow/notebook/blob/master/nb.py#L45-L59