Use voussoirkit timetools.

This commit is contained in:
voussoir 2022-11-06 22:48:59 -08:00
parent ca3766ea1b
commit a514ed5ff3
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
5 changed files with 21 additions and 24 deletions

View file

@ -329,13 +329,6 @@ def make_atom_feed(objects, feed_title, feed_link, feed_id) -> bs4.BeautifulSoup
return soup return soup
def now():
'''
Return the current UTC datetime object.
'''
n = datetime.datetime.now(tz=datetime.timezone.utc)
return n
def parse_unit_string(s) -> typing.Union[int, float, None]: def parse_unit_string(s) -> typing.Union[int, float, None]:
''' '''
Try to parse the string as an int, float, or bytestring, or hms. Try to parse the string as an int, float, or bytestring, or hms.

View file

@ -22,6 +22,7 @@ from voussoirkit import sentinel
from voussoirkit import spinal from voussoirkit import spinal
from voussoirkit import sqlhelpers from voussoirkit import sqlhelpers
from voussoirkit import stringtools from voussoirkit import stringtools
from voussoirkit import timetools
from voussoirkit import vlogging from voussoirkit import vlogging
from voussoirkit import worms from voussoirkit import worms
@ -122,7 +123,7 @@ class GroupableMixin(metaclass=abc.ABCMeta):
data = { data = {
'parentid': self.id, 'parentid': self.id,
'memberid': member.id, 'memberid': member.id,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
} }
self.photodb.insert(table=self.group_table, pairs=data) self.photodb.insert(table=self.group_table, pairs=data)
@ -336,7 +337,7 @@ class Album(ObjectBase, GroupableMixin):
data = { data = {
'albumid': self.id, 'albumid': self.id,
'directory': path.absolute_path, 'directory': path.absolute_path,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
} }
self.photodb.insert(table='album_associated_directories', pairs=data) self.photodb.insert(table='album_associated_directories', pairs=data)
@ -383,7 +384,7 @@ class Album(ObjectBase, GroupableMixin):
data = { data = {
'albumid': self.id, 'albumid': self.id,
'photoid': photo.id, 'photoid': photo.id,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
} }
self.photodb.insert(table='album_photo_rel', pairs=data) self.photodb.insert(table='album_photo_rel', pairs=data)
@ -975,12 +976,12 @@ class Photo(ObjectBase):
data = { data = {
'photoid': self.id, 'photoid': self.id,
'tagid': tag.id, 'tagid': tag.id,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
} }
self.photodb.insert(table='photo_tag_rel', pairs=data) self.photodb.insert(table='photo_tag_rel', pairs=data)
data = { data = {
'id': self.id, 'id': self.id,
'tagged_at': helpers.now().timestamp(), 'tagged_at': timetools.now().timestamp(),
} }
self.photodb.update(table=Photo, pairs=data, where_key='id') self.photodb.update(table=Photo, pairs=data, where_key='id')
@ -1382,7 +1383,7 @@ class Photo(ObjectBase):
data = { data = {
'id': self.id, 'id': self.id,
'tagged_at': helpers.now().timestamp(), 'tagged_at': timetools.now().timestamp(),
} }
self.photodb.update(table=Photo, pairs=data, where_key='id') self.photodb.update(table=Photo, pairs=data, where_key='id')
@ -1401,7 +1402,7 @@ class Photo(ObjectBase):
data = { data = {
'id': self.id, 'id': self.id,
'tagged_at': helpers.now().timestamp(), 'tagged_at': timetools.now().timestamp(),
} }
self.photodb.update(table=Photo, pairs=data, where_key='id') self.photodb.update(table=Photo, pairs=data, where_key='id')
@ -1671,7 +1672,7 @@ class Tag(ObjectBase, GroupableMixin):
data = { data = {
'name': synname, 'name': synname,
'mastername': self.name, 'mastername': self.name,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
} }
self.photodb.insert(table='tag_synonyms', pairs=data) self.photodb.insert(table='tag_synonyms', pairs=data)

View file

@ -25,6 +25,7 @@ from voussoirkit import ratelimiter
from voussoirkit import spinal from voussoirkit import spinal
from voussoirkit import sqlhelpers from voussoirkit import sqlhelpers
from voussoirkit import stringtools from voussoirkit import stringtools
from voussoirkit import timetools
from voussoirkit import vlogging from voussoirkit import vlogging
from voussoirkit import worms from voussoirkit import worms
@ -113,7 +114,7 @@ class PDBAlbumMixin:
'id': album_id, 'id': album_id,
'title': title, 'title': title,
'description': description, 'description': description,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
'thumbnail_photo': None, 'thumbnail_photo': None,
'author_id': author_id, 'author_id': author_id,
} }
@ -205,7 +206,7 @@ class PDBBookmarkMixin:
'id': bookmark_id, 'id': bookmark_id,
'title': title, 'title': title,
'url': url, 'url': url,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
'author_id': author_id, 'author_id': author_id,
} }
self.insert(table=objects.Bookmark, pairs=data) self.insert(table=objects.Bookmark, pairs=data)
@ -359,7 +360,7 @@ class PDBPhotoMixin:
'id': photo_id, 'id': photo_id,
'filepath': filepath.absolute_path, 'filepath': filepath.absolute_path,
'override_filename': None, 'override_filename': None,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
'tagged_at': None, 'tagged_at': None,
'author_id': author_id, 'author_id': author_id,
'searchhidden': searchhidden, 'searchhidden': searchhidden,
@ -993,7 +994,7 @@ class PDBTagMixin:
'id': tag_id, 'id': tag_id,
'name': tagname, 'name': tagname,
'description': description, 'description': description,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
'author_id': author_id, 'author_id': author_id,
} }
self.insert(table=objects.Tag, pairs=data) self.insert(table=objects.Tag, pairs=data)
@ -1163,7 +1164,7 @@ class PDBUserMixin:
'username': username, 'username': username,
'password': hashed_password, 'password': hashed_password,
'display_name': display_name, 'display_name': display_name,
'created': helpers.now().timestamp(), 'created': timetools.now().timestamp(),
} }
self.insert(table=objects.User, pairs=data) self.insert(table=objects.User, pairs=data)

View file

@ -1,6 +1,7 @@
import flask; from flask import request import flask; from flask import request
from voussoirkit import flasktools from voussoirkit import flasktools
from voussoirkit import timetools
import etiquette import etiquette
@ -26,7 +27,7 @@ def get_dbdump():
with common.P.transaction: with common.P.transaction:
binary = common.P.database_filepath.read('rb') binary = common.P.database_filepath.read('rb')
now = etiquette.helpers.now().strftime('%Y-%m-%d_%H-%M-%S') now = timetools.now().strftime('%Y-%m-%d_%H-%M-%S')
download_as = f'etiquette {now}.db' download_as = f'etiquette {now}.db'
outgoing_headers = { outgoing_headers = {
'Content-Type': 'application/octet-stream', 'Content-Type': 'application/octet-stream',

View file

@ -5,6 +5,7 @@ import werkzeug.datastructures
from voussoirkit import cacheclass from voussoirkit import cacheclass
from voussoirkit import flasktools from voussoirkit import flasktools
from voussoirkit import passwordy from voussoirkit import passwordy
from voussoirkit import timetools
import etiquette import etiquette
@ -107,7 +108,7 @@ class Session:
self.user = user self.user = user
self.ip_address = request.remote_addr self.ip_address = request.remote_addr
self.user_agent = request.headers.get('User-Agent', '') self.user_agent = request.headers.get('User-Agent', '')
self.last_activity = etiquette.helpers.now() self.last_activity = timetools.now()
def __repr__(self): def __repr__(self):
if self.user: if self.user:
@ -116,9 +117,9 @@ class Session:
return f'Session {self.token} for anonymous' return f'Session {self.token} for anonymous'
def expired(self): def expired(self):
now = etiquette.helpers.now() now = timetools.now()
age = now - self.last_activity age = now - self.last_activity
return age.seconds > SESSION_MAX_AGE return age.seconds > SESSION_MAX_AGE
def maintain(self): def maintain(self):
self.last_activity = etiquette.helpers.now() self.last_activity = timetools.now()