Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
date_blob_re = re.compile("(?:^|\n)\\[([^\\]]+)\\] ")
last_entry_pos = 0
for match in date_blob_re.finditer(journal_txt):
date_blob = match.groups()[0]
try:
new_date = 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)
if new_date:
if entries:
entries[-1].text = journal_txt[last_entry_pos:match.start()]
last_entry_pos = match.end()
entries.append(Entry.Entry(self, date=new_date))
# If no entries were found, treat all the existing text as an entry made now
if not entries:
entries.append(Entry.Entry(self, date=time.parse("now")))
# Fill in the text of the last entry
entries[-1].text = journal_txt[last_entry_pos:]
for entry in entries:
entry._parse_text()
return entries
# UUIDs of the new entries against self.entries, updating the entries
# if the edited entries differ, and deleting entries from self.entries
# if they don't show up in the edited entries anymore.
# Initialise our current entry
entries = []
current_entry = None
for line in edited.splitlines():
# try to parse line as UUID => new entry begins
line = line.rstrip()
m = re.match("# *([a-f0-9]+) *$", line.lower())
if m:
if current_entry:
entries.append(current_entry)
current_entry = Entry.Entry(self)
current_entry.modified = False
current_entry.uuid = m.group(1).lower()
else:
date_blob_re = re.compile("^\\[[^\\]]+\\] ")
date_blob = date_blob_re.findall(line)
if date_blob:
date_blob = date_blob[0]
new_date = jrnl_time.parse(date_blob.strip(" []"))
if line.endswith("*"):
current_entry.starred = True
line = line[:-1]
current_entry.title = line[len(date_blob) - 1 :]
current_entry.date = new_date
elif current_entry:
current_entry.body += line + "\n"
filenames.append(os.path.join(root, filename))
self.entries = []
for filename in filenames:
with open(filename, "rb") as plist_entry:
try:
dict_entry = plistlib.readPlist(plist_entry)
except self.PLIST_EXCEPTIONS:
pass
else:
try:
timezone = pytz.timezone(dict_entry["Time Zone"])
except (KeyError, pytz.exceptions.UnknownTimeZoneError):
timezone = tzlocal.get_localzone()
date = dict_entry["Creation Date"]
date = date + timezone.utcoffset(date, is_dst=False)
entry = Entry.Entry(
self,
date,
text=dict_entry["Entry Text"],
starred=dict_entry["Starred"],
)
entry.uuid = dict_entry["UUID"]
entry._tags = [
self.config["tagsymbols"][0] + tag.lower()
for tag in dict_entry.get("Tags", [])
]
self.entries.append(entry)
self.sort()
return self
date_blob = match.groups()[0]
try:
new_date = 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)
if new_date:
if entries:
entries[-1].text = journal_txt[last_entry_pos:match.start()]
last_entry_pos = match.end()
entries.append(Entry.Entry(self, date=new_date))
# If no entries were found, treat all the existing text as an entry made now
if not entries:
entries.append(Entry.Entry(self, date=time.parse("now")))
# Fill in the text of the last entry
entries[-1].text = journal_txt[last_entry_pos:]
for entry in entries:
entry._parse_text()
return entries
for separator in ".?!":
sep_pos = raw.find(separator)
if 1 < sep_pos < title_end:
title_end = sep_pos
title = raw[:title_end+1]
body = raw[title_end+1:].strip()
if not date:
if title.find(":") > 0:
date = self.parse_date(title[:title.find(":")])
if date: # Parsed successfully, strip that from the raw text
title = title[title.find(":")+1:].strip()
if not date: # Still nothing? Meh, just live in the moment.
date = self.parse_date("now")
self.entries.append(Entry(self, date, title, body))
self.sort()
# long the date will be by constructing one
date_length = len(datetime.today().strftime(self.config['timeformat']))
# Initialise our current entry
entries = []
current_entry = None
for line in journal.splitlines():
try:
# try to parse line as date => new entry begins
new_date = datetime.strptime(line[:date_length], self.config['timeformat'])
# parsing successfull => save old entry and create new one
if new_date and current_entry:
entries.append(current_entry)
current_entry = Entry(self, date=new_date, title=line[date_length+1:])
except ValueError:
# Happens when we can't parse the start of the line as an date.
# In this case, just append line to our body.
current_entry.body += line + "\n"
# Append last entry
if current_entry:
entries.append(current_entry)
for entry in entries:
entry.parse_tags()
return entries