Toot-Mastodon-CLI-TUI-clien.../toot/tui/utils.py

18 lines
400 B
Python
Raw Normal View History

2019-08-24 14:14:46 +02:00
import re
2019-08-27 14:34:51 +02:00
from datetime import datetime
2019-08-24 14:14:46 +02:00
HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')
def highlight_hashtags(line):
return [
("hashtag", p) if p.startswith("#") else p
for p in re.split(HASHTAG_PATTERN, line)
]
2019-08-27 14:34:51 +02:00
def parse_datetime(value):
"""Returns an aware datetime in local timezone"""
return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z").astimezone()