From 377c8524ca9c32768eaefd149bb1c64971193aa4 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 5 Feb 2014 10:36:40 -0800 Subject: [PATCH] Updated docs from master --- docs/usage.rst | 2 +- jrnl/Journal.py | 5 +++-- jrnl/__init__.py | 2 +- jrnl/cli.py | 12 +++++++++--- jrnl/util.py | 18 ------------------ 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 6ef0f390..0b7f487f 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -56,7 +56,7 @@ Viewing jrnl -n 10 -will list you the ten latest entries, :: +will list you the ten latest entries (if you're lazy, ``jrnl -10`` will do the same), :: jrnl -from "last year" -until march diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 32fb8b20..b5d7a664 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -23,6 +23,7 @@ import hashlib import plistlib import pytz import uuid +import tzlocal class Journal(object): def __init__(self, name='default', **kwargs): @@ -333,7 +334,7 @@ class DayOne(Journal): try: timezone = pytz.timezone(dict_entry['Time Zone']) except (KeyError, pytz.exceptions.UnknownTimeZoneError): - timezone = pytz.timezone(util.get_local_timezone()) + timezone = tzlocal.get_localzone() date = dict_entry['Creation Date'] date = date + timezone.utcoffset(date) raw = dict_entry['Entry Text'] @@ -357,7 +358,7 @@ class DayOne(Journal): 'Creation Date': utc_time, 'Starred': entry.starred if hasattr(entry, 'starred') else False, 'Entry Text': entry.title+"\n"+entry.body, - 'Time Zone': util.get_local_timezone(), + 'Time Zone': str(tzlocal.get_localzone()), 'UUID': entry.uuid, 'Tags': [tag.strip(self.config['tagsymbols']) for tag in entry.tags] } diff --git a/jrnl/__init__.py b/jrnl/__init__.py index 8842f8ec..12c55ed0 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -8,7 +8,7 @@ jrnl is a simple journal application for your command line. from __future__ import absolute_import __title__ = 'jrnl' -__version__ = '1.7.9' +__version__ = '1.7.10' __author__ = 'Manuel Ebert' __license__ = 'MIT License' __copyright__ = 'Copyright 2013 - 2014 Manuel Ebert' diff --git a/jrnl/cli.py b/jrnl/cli.py index 1538352a..fe00977d 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -35,7 +35,7 @@ def parse_args(args=None): reading.add_argument('-until', '-to', dest='end_date', metavar="DATE", help='View entries before this date') reading.add_argument('-and', dest='strict', action="store_true", help='Filter by tags using AND (default: OR)') reading.add_argument('-starred', dest='starred', action="store_true", help='Show only starred entries') - reading.add_argument('-n', dest='limit', default=None, metavar="N", help='Shows the last n entries matching the filter', nargs="?", type=int) + reading.add_argument('-n', dest='limit', default=None, metavar="N", help="Shows the last n entries matching the filter. '-n 3' and '-3' have the same effect.", nargs="?", type=int) exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal') exporting.add_argument('--short', dest='short', action="store_true", help='Show only titles or line containing the search tags') @@ -119,13 +119,19 @@ def run(manual_args=None): util.prompt("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.") sys.exit(1) - - # If the first textual argument points to a journal file, # use this! journal_name = args.text[0] if (args.text and args.text[0] in config['journals']) else 'default' if journal_name is not 'default': args.text = args.text[1:] + # If the first remaining argument looks like e.g. '-3', interpret that as a limiter + if not args.limit and args.text and args.text[0].startswith("-"): + try: + args.limit = int(args.text[0].lstrip("-")) + args.text = args.text[1:] + except: + pass + journal_conf = config['journals'].get(journal_name) if type(journal_conf) is dict: # We can override the default config on a by-journal basis config.update(journal_conf) diff --git a/jrnl/util.py b/jrnl/util.py index 708150f0..4b252cbd 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -88,24 +88,6 @@ def yesno(prompt, default=True): raw = py23_input(prompt) return {'y': True, 'n': False}.get(raw.lower(), default) -def get_local_timezone(): - """Returns the Olson identifier of the local timezone. - In a happy world, tzlocal.get_localzone would do this, but there's a bug on OS X - that prevents that right now: https://github.com/regebro/tzlocal/issues/6""" - global __cached_tz - if not __cached_tz and "darwin" in sys.platform: - __cached_tz = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip() - if not __cached_tz or __cached_tz not in pytz.all_timezones_set: - link = os.readlink("/etc/localtime") - # This is something like /usr/share/zoneinfo/America/Los_Angeles. - # Find second / from right and take the substring - __cached_tz = link[link.rfind('/', 0, link.rfind('/'))+1:] - elif not __cached_tz: - __cached_tz = str(get_localzone()) - if not __cached_tz or __cached_tz not in pytz.all_timezones_set: - __cached_tz = "UTC" - return __cached_tz - def load_and_fix_json(json_path): """Tries to load a json object from a file. If that fails, tries to fix common errors (no or extra , at end of the line).