aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-25 23:35:45 +0200
committerneodarz <neodarz@neodarz.net>2019-05-25 23:35:45 +0200
commit9335441fe7dc26bc76fe3aea363c76a218ae261b (patch)
treea75eb05cf55175f007c4fa5524c3c6fcb9c2efcb
parenta8e56413815123b4bb10f3ddd597f42d11c8ad46 (diff)
downloadmy_new_personal_website-9335441fe7dc26bc76fe3aea363c76a218ae261b.tar.xz
my_new_personal_website-9335441fe7dc26bc76fe3aea363c76a218ae261b.zip
Move current_datetime function to external file
-rwxr-xr-xpyblog13
-rw-r--r--utils/utils.py13
2 files changed, 16 insertions, 10 deletions
diff --git a/pyblog b/pyblog
index 1511dce4..b625f1c7 100755
--- a/pyblog
+++ b/pyblog
@@ -98,13 +98,6 @@ WHITE = ""
YELLOW = ""
RESET = ""
-def current_datetime():
- """Return the current datetime, complete with tzinfo.
-
- Precision is one second. Timezone is the local timezone.
- """
- return datetime.datetime.fromtimestamp(round(time.time()),
- dateutil.tz.tzlocal())
def generate_menu():
"""Generate menu."""
@@ -804,7 +797,7 @@ def generate_index_and_feed():
generate_notes_list()
rewrite_title()
- feed.updated_datetime = current_datetime()
+ feed.updated_datetime = utils.current_datetime()
feed.updated = ET.Element("updated")
feed.updated.text = feed.updated_datetime.isoformat()
@@ -1125,7 +1118,7 @@ def new_post(title):
On success.
"""
- date = current_datetime()
+ date = utils.current_datetime()
filename_date = date.strftime("%Y-%m-%d")
iso_date = date.isoformat()
display_date = "%s %d, %d" % (date.strftime("%B"), date.day, date.year)
@@ -1177,7 +1170,7 @@ def touch(filename):
# update timestamp in the metadata section of the post
whatchanged = io.StringIO()
- date = current_datetime()
+ date = utils.current_datetime()
iso_date = date.isoformat()
display_date = "%s %d, %d" % (date.strftime("%B"), date.day, date.year)
filename_date = date.strftime("%Y-%m-%d")
diff --git a/utils/utils.py b/utils/utils.py
index a76beb5d..bf3d4fbe 100644
--- a/utils/utils.py
+++ b/utils/utils.py
@@ -3,6 +3,10 @@
from contextlib import contextmanager
import colorama
+import time
+import datetime
+import dateutil.tz
+
@contextmanager
def init_colorama():
@@ -21,3 +25,12 @@ def init_colorama():
for color in colorama.Fore.__dict__:
exec("global {0}; {0} = ''".format(color))
colorama.deinit()
+
+
+def current_datetime():
+ """Return the current datetime, complete with tzinfo.
+
+ Precision is one second. Timezone is the local timezone.
+ """
+ return datetime.datetime.fromtimestamp(round(time.time()),
+ dateutil.tz.tzlocal())