Use voussoirkit timetools.
This commit is contained in:
		
							parent
							
								
									ca3766ea1b
								
							
						
					
					
						commit
						a514ed5ff3
					
				
					 5 changed files with 21 additions and 24 deletions
				
			
		|  | @ -329,13 +329,6 @@ def make_atom_feed(objects, feed_title, feed_link, feed_id) -> bs4.BeautifulSoup | |||
| 
 | ||||
|     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]: | ||||
|     ''' | ||||
|     Try to parse the string as an int, float, or bytestring, or hms. | ||||
|  |  | |||
|  | @ -22,6 +22,7 @@ from voussoirkit import sentinel | |||
| from voussoirkit import spinal | ||||
| from voussoirkit import sqlhelpers | ||||
| from voussoirkit import stringtools | ||||
| from voussoirkit import timetools | ||||
| from voussoirkit import vlogging | ||||
| from voussoirkit import worms | ||||
| 
 | ||||
|  | @ -122,7 +123,7 @@ class GroupableMixin(metaclass=abc.ABCMeta): | |||
|         data = { | ||||
|             'parentid': self.id, | ||||
|             'memberid': member.id, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.photodb.insert(table=self.group_table, pairs=data) | ||||
| 
 | ||||
|  | @ -336,7 +337,7 @@ class Album(ObjectBase, GroupableMixin): | |||
|         data = { | ||||
|             'albumid': self.id, | ||||
|             'directory': path.absolute_path, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.photodb.insert(table='album_associated_directories', pairs=data) | ||||
| 
 | ||||
|  | @ -383,7 +384,7 @@ class Album(ObjectBase, GroupableMixin): | |||
|         data = { | ||||
|             'albumid': self.id, | ||||
|             'photoid': photo.id, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.photodb.insert(table='album_photo_rel', pairs=data) | ||||
| 
 | ||||
|  | @ -975,12 +976,12 @@ class Photo(ObjectBase): | |||
|         data = { | ||||
|             'photoid': self.id, | ||||
|             'tagid': tag.id, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.photodb.insert(table='photo_tag_rel', pairs=data) | ||||
|         data = { | ||||
|             'id': self.id, | ||||
|             'tagged_at': helpers.now().timestamp(), | ||||
|             'tagged_at': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.photodb.update(table=Photo, pairs=data, where_key='id') | ||||
| 
 | ||||
|  | @ -1382,7 +1383,7 @@ class Photo(ObjectBase): | |||
| 
 | ||||
|         data = { | ||||
|             'id': self.id, | ||||
|             'tagged_at': helpers.now().timestamp(), | ||||
|             'tagged_at': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.photodb.update(table=Photo, pairs=data, where_key='id') | ||||
| 
 | ||||
|  | @ -1401,7 +1402,7 @@ class Photo(ObjectBase): | |||
| 
 | ||||
|         data = { | ||||
|             'id': self.id, | ||||
|             'tagged_at': helpers.now().timestamp(), | ||||
|             'tagged_at': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.photodb.update(table=Photo, pairs=data, where_key='id') | ||||
| 
 | ||||
|  | @ -1671,7 +1672,7 @@ class Tag(ObjectBase, GroupableMixin): | |||
|         data = { | ||||
|             'name': synname, | ||||
|             'mastername': self.name, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.photodb.insert(table='tag_synonyms', pairs=data) | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,6 +25,7 @@ from voussoirkit import ratelimiter | |||
| from voussoirkit import spinal | ||||
| from voussoirkit import sqlhelpers | ||||
| from voussoirkit import stringtools | ||||
| from voussoirkit import timetools | ||||
| from voussoirkit import vlogging | ||||
| from voussoirkit import worms | ||||
| 
 | ||||
|  | @ -113,7 +114,7 @@ class PDBAlbumMixin: | |||
|             'id': album_id, | ||||
|             'title': title, | ||||
|             'description': description, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|             'thumbnail_photo': None, | ||||
|             'author_id': author_id, | ||||
|         } | ||||
|  | @ -205,7 +206,7 @@ class PDBBookmarkMixin: | |||
|             'id': bookmark_id, | ||||
|             'title': title, | ||||
|             'url': url, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|             'author_id': author_id, | ||||
|         } | ||||
|         self.insert(table=objects.Bookmark, pairs=data) | ||||
|  | @ -359,7 +360,7 @@ class PDBPhotoMixin: | |||
|             'id': photo_id, | ||||
|             'filepath': filepath.absolute_path, | ||||
|             'override_filename': None, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|             'tagged_at': None, | ||||
|             'author_id': author_id, | ||||
|             'searchhidden': searchhidden, | ||||
|  | @ -993,7 +994,7 @@ class PDBTagMixin: | |||
|             'id': tag_id, | ||||
|             'name': tagname, | ||||
|             'description': description, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|             'author_id': author_id, | ||||
|         } | ||||
|         self.insert(table=objects.Tag, pairs=data) | ||||
|  | @ -1163,7 +1164,7 @@ class PDBUserMixin: | |||
|             'username': username, | ||||
|             'password': hashed_password, | ||||
|             'display_name': display_name, | ||||
|             'created': helpers.now().timestamp(), | ||||
|             'created': timetools.now().timestamp(), | ||||
|         } | ||||
|         self.insert(table=objects.User, pairs=data) | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| import flask; from flask import request | ||||
| 
 | ||||
| from voussoirkit import flasktools | ||||
| from voussoirkit import timetools | ||||
| 
 | ||||
| import etiquette | ||||
| 
 | ||||
|  | @ -26,7 +27,7 @@ def get_dbdump(): | |||
|     with common.P.transaction: | ||||
|         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' | ||||
|     outgoing_headers = { | ||||
|         'Content-Type': 'application/octet-stream', | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ import werkzeug.datastructures | |||
| from voussoirkit import cacheclass | ||||
| from voussoirkit import flasktools | ||||
| from voussoirkit import passwordy | ||||
| from voussoirkit import timetools | ||||
| 
 | ||||
| import etiquette | ||||
| 
 | ||||
|  | @ -107,7 +108,7 @@ class Session: | |||
|         self.user = user | ||||
|         self.ip_address = request.remote_addr | ||||
|         self.user_agent = request.headers.get('User-Agent', '') | ||||
|         self.last_activity = etiquette.helpers.now() | ||||
|         self.last_activity = timetools.now() | ||||
| 
 | ||||
|     def __repr__(self): | ||||
|         if self.user: | ||||
|  | @ -116,9 +117,9 @@ class Session: | |||
|             return f'Session {self.token} for anonymous' | ||||
| 
 | ||||
|     def expired(self): | ||||
|         now = etiquette.helpers.now() | ||||
|         now = timetools.now() | ||||
|         age = now - self.last_activity | ||||
|         return age.seconds > SESSION_MAX_AGE | ||||
| 
 | ||||
|     def maintain(self): | ||||
|         self.last_activity = etiquette.helpers.now() | ||||
|         self.last_activity = timetools.now() | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue