mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-06 16:26:13 +02:00
Merge branch 'develop' of https://github.com/jrnl-org/jrnl into jrnl-org-develop
This commit is contained in:
commit
d0055e040b
143 changed files with 4998 additions and 488 deletions
|
@ -1,6 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from datetime import datetime
|
||||
import datetime
|
||||
import fnmatch
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
@ -80,35 +78,35 @@ class DayOne(Journal.Journal):
|
|||
entry.creator_device_agent = dict_entry["Creator"][
|
||||
"Device Agent"
|
||||
]
|
||||
except:
|
||||
except: # noqa: E722
|
||||
pass
|
||||
try:
|
||||
entry.creator_generation_date = dict_entry["Creator"][
|
||||
"Generation Date"
|
||||
]
|
||||
except:
|
||||
except: # noqa: E722
|
||||
entry.creator_generation_date = date
|
||||
try:
|
||||
entry.creator_host_name = dict_entry["Creator"]["Host Name"]
|
||||
except:
|
||||
except: # noqa: E722
|
||||
pass
|
||||
try:
|
||||
entry.creator_os_agent = dict_entry["Creator"]["OS Agent"]
|
||||
except:
|
||||
except: # noqa: E722
|
||||
pass
|
||||
try:
|
||||
entry.creator_software_agent = dict_entry["Creator"][
|
||||
"Software Agent"
|
||||
]
|
||||
except:
|
||||
except: # noqa: E722
|
||||
pass
|
||||
try:
|
||||
entry.location = dict_entry["Location"]
|
||||
except:
|
||||
except: # noqa: E722
|
||||
pass
|
||||
try:
|
||||
entry.weather = dict_entry["Weather"]
|
||||
except:
|
||||
except: # noqa: E722
|
||||
pass
|
||||
self.entries.append(entry)
|
||||
self.sort()
|
||||
|
@ -118,7 +116,7 @@ class DayOne(Journal.Journal):
|
|||
"""Writes only the entries that have been modified into plist files."""
|
||||
for entry in self.entries:
|
||||
if entry.modified:
|
||||
utc_time = datetime.utcfromtimestamp(
|
||||
utc_time = datetime.datetime.utcfromtimestamp(
|
||||
time.mktime(entry.date.timetuple())
|
||||
)
|
||||
|
||||
|
|
5
jrnl/Entry.py
Executable file → Normal file
5
jrnl/Entry.py
Executable file → Normal file
|
@ -1,9 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
import datetime
|
||||
import re
|
||||
|
||||
import ansiwrap
|
||||
|
@ -15,7 +14,7 @@ from .color import highlight_tags_with_background_color
|
|||
class Entry:
|
||||
def __init__(self, journal, date=None, text="", starred=False):
|
||||
self.journal = journal # Reference to journal mainly to access its config
|
||||
self.date = date or datetime.now()
|
||||
self.date = date or datetime.datetime.now()
|
||||
self.text = text
|
||||
self._title = None
|
||||
self._body = None
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
@ -135,7 +134,9 @@ class Journal:
|
|||
for match in date_blob_re.finditer(journal_txt):
|
||||
date_blob = match.groups()[0]
|
||||
try:
|
||||
new_date = datetime.strptime(date_blob, self.config["timeformat"])
|
||||
new_date = datetime.datetime.strptime(
|
||||
date_blob, self.config["timeformat"]
|
||||
)
|
||||
except ValueError:
|
||||
# Passing in a date that had brackets around it
|
||||
new_date = time.parse(date_blob, bracketed=True)
|
||||
|
@ -219,7 +220,10 @@ class Journal:
|
|||
|
||||
# If strict mode is on, all tags have to be present in entry
|
||||
tagged = self.search_tags.issubset if strict else self.search_tags.intersection
|
||||
excluded = lambda tags: len([tag for tag in tags if tag in excluded_tags]) > 0
|
||||
|
||||
def excluded(tags):
|
||||
return 0 < len([tag for tag in tags if tag in excluded_tags])
|
||||
|
||||
if contains:
|
||||
contains_lower = contains.casefold()
|
||||
|
||||
|
@ -348,7 +352,7 @@ class LegacyJournal(Journal):
|
|||
"""Parses a journal that's stored in a string and returns a list of entries"""
|
||||
# Entries start with a line that looks like 'date title' - let's figure out how
|
||||
# long the date will be by constructing one
|
||||
date_length = len(datetime.today().strftime(self.config["timeformat"]))
|
||||
date_length = len(datetime.datetime.today().strftime(self.config["timeformat"]))
|
||||
|
||||
# Initialise our current entry
|
||||
entries = []
|
||||
|
@ -358,7 +362,7 @@ class LegacyJournal(Journal):
|
|||
line = line.rstrip()
|
||||
try:
|
||||
# try to parse line as date => new entry begins
|
||||
new_date = datetime.strptime(
|
||||
new_date = datetime.datetime.strptime(
|
||||
line[:date_length], self.config["timeformat"]
|
||||
)
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
import re
|
||||
from string import punctuation
|
||||
from string import whitespace
|
||||
|
|
|
@ -41,7 +41,7 @@ def make_yaml_valid_dict(input: list) -> dict:
|
|||
|
||||
# yaml compatible strings are of the form Key:Value
|
||||
yamlstr = YAML_SEPARATOR.join(input)
|
||||
runtime_modifications = yaml.load(yamlstr, Loader=yaml.FullLoader)
|
||||
runtime_modifications = yaml.load(yamlstr, Loader=yaml.SafeLoader)
|
||||
|
||||
return runtime_modifications
|
||||
|
||||
|
@ -140,7 +140,7 @@ def verify_config_colors(config):
|
|||
def load_config(config_path):
|
||||
"""Tries to load a config file from YAML."""
|
||||
with open(config_path) as f:
|
||||
return yaml.load(f, Loader=yaml.FullLoader)
|
||||
return yaml.load(f, Loader=yaml.SafeLoader)
|
||||
|
||||
|
||||
def is_config_json(config_path):
|
||||
|
|
|
@ -26,7 +26,7 @@ def get_text_from_editor(config, template=""):
|
|||
|
||||
try:
|
||||
subprocess.call(split_args(config["editor"]) + [tmpfile])
|
||||
except Exception as e:
|
||||
except FileNotFoundError as e:
|
||||
error_msg = f"""
|
||||
{ERROR_COLOR}{str(e)}{RESET_COLOR}
|
||||
|
||||
|
|
|
@ -22,25 +22,24 @@ class JrnlError(Exception):
|
|||
|
||||
def _get_error_message(self, **kwargs):
|
||||
error_messages = {
|
||||
"ConfigDirectoryIsFile": textwrap.dedent(
|
||||
"""
|
||||
"ConfigDirectoryIsFile": """
|
||||
The path to your jrnl configuration directory is a file, not a directory:
|
||||
|
||||
{config_directory_path}
|
||||
|
||||
Removing this file will allow jrnl to save its configuration.
|
||||
"""
|
||||
),
|
||||
"LineWrapTooSmallForDateFormat": textwrap.dedent(
|
||||
"""
|
||||
The provided linewrap value of {config_linewrap} is too small by {columns} columns
|
||||
to display the timestamps in the configured time format for journal {journal}.
|
||||
""",
|
||||
"LineWrapTooSmallForDateFormat": """
|
||||
The provided linewrap value of {config_linewrap} is too small by
|
||||
{columns} columns to display the timestamps in the configured time
|
||||
format for journal {journal}.
|
||||
|
||||
You can avoid this error by specifying a linewrap value that is larger by at least {columns} in the configuration file or by using --config-override at the command line
|
||||
"""
|
||||
),
|
||||
You can avoid this error by specifying a linewrap value that is larger
|
||||
by at least {columns} in the configuration file or by using
|
||||
--config-override at the command line
|
||||
""",
|
||||
}
|
||||
|
||||
return error_messages[self.error_type].format(**kwargs)
|
||||
|
||||
pass
|
||||
msg = error_messages[self.error_type].format(**kwargs)
|
||||
msg = textwrap.dedent(msg)
|
||||
return msg
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -26,7 +26,7 @@ class Template:
|
|||
def from_file(cls, filename):
|
||||
with open(filename) as f:
|
||||
front_matter, body = f.read().strip("-\n").split("---", 2)
|
||||
front_matter = yaml.load(front_matter, Loader=yaml.FullLoader)
|
||||
front_matter = yaml.load(front_matter, Loader=yaml.SafeLoader)
|
||||
template = cls(body)
|
||||
template.__dict__.update(front_matter)
|
||||
return template
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
22
jrnl/time.py
22
jrnl/time.py
|
@ -1,11 +1,11 @@
|
|||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
from datetime import datetime
|
||||
import datetime
|
||||
|
||||
FAKE_YEAR = 9999
|
||||
DEFAULT_FUTURE = datetime(FAKE_YEAR, 12, 31, 23, 59, 59)
|
||||
DEFAULT_PAST = datetime(FAKE_YEAR, 1, 1, 0, 0)
|
||||
DEFAULT_FUTURE = datetime.datetime(FAKE_YEAR, 12, 31, 23, 59, 59)
|
||||
DEFAULT_PAST = datetime.datetime(FAKE_YEAR, 1, 1, 0, 0)
|
||||
|
||||
|
||||
def __get_pdt_calendar():
|
||||
|
@ -27,7 +27,7 @@ def parse(
|
|||
"""Parses a string containing a fuzzy date and returns a datetime.datetime object"""
|
||||
if not date_str:
|
||||
return None
|
||||
elif isinstance(date_str, datetime):
|
||||
elif isinstance(date_str, datetime.datetime):
|
||||
return date_str
|
||||
|
||||
# Don't try to parse anything with 6 or less characters and was parsed from the existing journal.
|
||||
|
@ -44,7 +44,9 @@ def parse(
|
|||
|
||||
date = dateparse(date_str, default=default_date)
|
||||
if date.year == FAKE_YEAR:
|
||||
date = datetime(datetime.now().year, date.timetuple()[1:6])
|
||||
date = datetime.datetime(
|
||||
datetime.datetime.now().year, date.timetuple()[1:6]
|
||||
)
|
||||
else:
|
||||
year_present = True
|
||||
flag = 1 if date.hour == date.minute == 0 else 2
|
||||
|
@ -52,7 +54,7 @@ def parse(
|
|||
except Exception as e:
|
||||
if e.args[0] == "day is out of range for month":
|
||||
y, m, d, H, M, S = default_date.timetuple()[:6]
|
||||
default_date = datetime(y, m, d - 1, H, M, S)
|
||||
default_date = datetime.datetime(y, m, d - 1, H, M, S)
|
||||
else:
|
||||
calendar = __get_pdt_calendar()
|
||||
date, flag = calendar.parse(date_str)
|
||||
|
@ -60,26 +62,26 @@ def parse(
|
|||
if not flag: # Oops, unparsable.
|
||||
try: # Try and parse this as a single year
|
||||
year = int(date_str)
|
||||
return datetime(year, 1, 1)
|
||||
return datetime.datetime(year, 1, 1)
|
||||
except ValueError:
|
||||
return None
|
||||
except TypeError:
|
||||
return None
|
||||
|
||||
if flag == 1: # Date found, but no time. Use the default time.
|
||||
date = datetime(
|
||||
date = datetime.datetime(
|
||||
*date[:3],
|
||||
hour=23 if inclusive else default_hour or 0,
|
||||
minute=59 if inclusive else default_minute or 0,
|
||||
second=59 if inclusive else 0
|
||||
)
|
||||
else:
|
||||
date = datetime(*date[:6])
|
||||
date = datetime.datetime(*date[:6])
|
||||
|
||||
# Ugly heuristic: if the date is more than 4 weeks in the future, we got the year wrong.
|
||||
# Rather then this, we would like to see parsedatetime patched so we can tell it to prefer
|
||||
# past dates
|
||||
dt = datetime.now() - date
|
||||
dt = datetime.datetime.now() - date
|
||||
if dt.days < -28 and not year_present:
|
||||
date = date.replace(date.year - 1)
|
||||
return date
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue