Snake case

merge-requests/30/head
Bob Mottram 2021-12-26 20:48:15 +00:00
parent 0c91ffab00
commit 201429fa92
2 changed files with 23 additions and 23 deletions

View File

@ -277,7 +277,7 @@ from utils import removeHtml
from utils import is_editor from utils import is_editor
from utils import is_artist from utils import is_artist
from utils import get_image_extensions from utils import get_image_extensions
from utils import mediaFileMimeType from utils import media_file_mime_type
from utils import getCSS from utils import getCSS
from utils import firstParagraphFromString from utils import firstParagraphFromString
from utils import clearFromPostCaches from utils import clearFromPostCaches
@ -7219,7 +7219,7 @@ class PubServer(BaseHTTPRequestHandler):
self._304() self._304()
return return
mediaFileType = mediaFileMimeType(mediaFilename) mediaFileType = media_file_mime_type(mediaFilename)
t = os.path.getmtime(mediaFilename) t = os.path.getmtime(mediaFilename)
lastModifiedTime = datetime.datetime.fromtimestamp(t) lastModifiedTime = datetime.datetime.fromtimestamp(t)
@ -7349,7 +7349,7 @@ class PubServer(BaseHTTPRequestHandler):
return return
if self.server.iconsCache.get(mediaStr): if self.server.iconsCache.get(mediaStr):
mediaBinary = self.server.iconsCache[mediaStr] mediaBinary = self.server.iconsCache[mediaStr]
mimeTypeStr = mediaFileMimeType(mediaFilename) mimeTypeStr = media_file_mime_type(mediaFilename)
self._set_headers_etag(mediaFilename, self._set_headers_etag(mediaFilename,
mimeTypeStr, mimeTypeStr,
mediaBinary, None, mediaBinary, None,
@ -7368,7 +7368,7 @@ class PubServer(BaseHTTPRequestHandler):
except OSError: except OSError:
print('EX: unable to read icon image ' + mediaFilename) print('EX: unable to read icon image ' + mediaFilename)
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename) mimeType = media_file_mime_type(mediaFilename)
self._set_headers_etag(mediaFilename, self._set_headers_etag(mediaFilename,
mimeType, mimeType,
mediaBinary, None, mediaBinary, None,
@ -7415,7 +7415,7 @@ class PubServer(BaseHTTPRequestHandler):
except OSError: except OSError:
print('EX: unable to read help image ' + mediaFilename) print('EX: unable to read help image ' + mediaFilename)
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename) mimeType = media_file_mime_type(mediaFilename)
self._set_headers_etag(mediaFilename, self._set_headers_etag(mediaFilename,
mimeType, mimeType,
mediaBinary, None, mediaBinary, None,
@ -7437,7 +7437,7 @@ class PubServer(BaseHTTPRequestHandler):
print('showCachedFavicon: ' + favFilename) print('showCachedFavicon: ' + favFilename)
if self.server.favicons_cache.get(favFile): if self.server.favicons_cache.get(favFile):
mediaBinary = self.server.favicons_cache[favFile] mediaBinary = self.server.favicons_cache[favFile]
mimeType = mediaFileMimeType(favFilename) mimeType = media_file_mime_type(favFilename)
self._set_headers_etag(favFilename, self._set_headers_etag(favFilename,
mimeType, mimeType,
mediaBinary, None, mediaBinary, None,
@ -7462,7 +7462,7 @@ class PubServer(BaseHTTPRequestHandler):
except OSError: except OSError:
print('EX: unable to read cached favicon ' + favFilename) print('EX: unable to read cached favicon ' + favFilename)
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(favFilename) mimeType = media_file_mime_type(favFilename)
self._set_headers_etag(favFilename, self._set_headers_etag(favFilename,
mimeType, mimeType,
mediaBinary, None, mediaBinary, None,
@ -7493,7 +7493,7 @@ class PubServer(BaseHTTPRequestHandler):
except OSError: except OSError:
print('EX: unable to read cached avatar ' + mediaFilename) print('EX: unable to read cached avatar ' + mediaFilename)
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename) mimeType = media_file_mime_type(mediaFilename)
self._set_headers_etag(mediaFilename, self._set_headers_etag(mediaFilename,
mimeType, mimeType,
mediaBinary, None, mediaBinary, None,
@ -12543,7 +12543,7 @@ class PubServer(BaseHTTPRequestHandler):
time.sleep(1) time.sleep(1)
tries += 1 tries += 1
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(qrFilename) mimeType = media_file_mime_type(qrFilename)
self._set_headers_etag(qrFilename, mimeType, self._set_headers_etag(qrFilename, mimeType,
mediaBinary, None, mediaBinary, None,
self.server.domain_full, self.server.domain_full,
@ -12588,7 +12588,7 @@ class PubServer(BaseHTTPRequestHandler):
time.sleep(1) time.sleep(1)
tries += 1 tries += 1
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(bannerFilename) mimeType = media_file_mime_type(bannerFilename)
self._set_headers_etag(bannerFilename, mimeType, self._set_headers_etag(bannerFilename, mimeType,
mediaBinary, None, mediaBinary, None,
self.server.domain_full, self.server.domain_full,
@ -12632,7 +12632,7 @@ class PubServer(BaseHTTPRequestHandler):
time.sleep(1) time.sleep(1)
tries += 1 tries += 1
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(bannerFilename) mimeType = media_file_mime_type(bannerFilename)
self._set_headers_etag(bannerFilename, mimeType, self._set_headers_etag(bannerFilename, mimeType,
mediaBinary, None, mediaBinary, None,
self.server.domain_full, self.server.domain_full,
@ -14626,7 +14626,7 @@ class PubServer(BaseHTTPRequestHandler):
time.sleep(1) time.sleep(1)
tries += 1 tries += 1
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename) mimeType = media_file_mime_type(mediaFilename)
self._set_headers_etag(mediaFilename, mimeType, self._set_headers_etag(mediaFilename, mimeType,
mediaBinary, cookie, mediaBinary, cookie,
self.server.domain_full, self.server.domain_full,
@ -14668,7 +14668,7 @@ class PubServer(BaseHTTPRequestHandler):
time.sleep(1) time.sleep(1)
tries += 1 tries += 1
if mediaBinary: if mediaBinary:
mimeType = mediaFileMimeType(screenFilename) mimeType = media_file_mime_type(screenFilename)
self._set_headers_etag(screenFilename, mimeType, self._set_headers_etag(screenFilename, mimeType,
mediaBinary, cookie, mediaBinary, cookie,
self.server.domain_full, self.server.domain_full,
@ -14710,7 +14710,7 @@ class PubServer(BaseHTTPRequestHandler):
time.sleep(1) time.sleep(1)
tries += 1 tries += 1
if mediaBinary: if mediaBinary:
mimeTypeStr = mediaFileMimeType(iconFilename) mimeTypeStr = media_file_mime_type(iconFilename)
self._set_headers_etag(iconFilename, self._set_headers_etag(iconFilename,
mimeTypeStr, mimeTypeStr,
mediaBinary, cookie, mediaBinary, cookie,
@ -16431,7 +16431,7 @@ class PubServer(BaseHTTPRequestHandler):
print('EX: do_HEAD unable to write ' + print('EX: do_HEAD unable to write ' +
mediaTagFilename) mediaTagFilename)
mediaFileType = mediaFileMimeType(checkPath) mediaFileType = media_file_mime_type(checkPath)
self._set_headers_head(mediaFileType, fileLength, self._set_headers_head(mediaFileType, fileLength,
etag, calling_domain, False) etag, calling_domain, False)

View File

@ -2484,7 +2484,7 @@ def weekDayOfMonthStart(monthNumber: int, year: int) -> int:
return int(firstDayOfMonth.strftime("%w")) + 1 return int(firstDayOfMonth.strftime("%w")) + 1
def mediaFileMimeType(filename: str) -> str: def media_file_mime_type(filename: str) -> str:
"""Given a media filename return its mime type """Given a media filename return its mime type
""" """
if '.' not in filename: if '.' not in filename:
@ -2511,7 +2511,7 @@ def mediaFileMimeType(filename: str) -> str:
return extensions[fileExt] return extensions[fileExt]
def is_recent_post(post_json_object: {}, maxDays: int) -> bool: def is_recent_post(post_json_object: {}, max_days: int) -> bool:
""" Is the given post recent? """ Is the given post recent?
""" """
if not has_object_dict(post_json_object): if not has_object_dict(post_json_object):
@ -2522,20 +2522,20 @@ def is_recent_post(post_json_object: {}, maxDays: int) -> bool:
return False return False
curr_time = datetime.datetime.utcnow() curr_time = datetime.datetime.utcnow()
days_since_epoch = (curr_time - datetime.datetime(1970, 1, 1)).days days_since_epoch = (curr_time - datetime.datetime(1970, 1, 1)).days
recently = days_since_epoch - maxDays recently = days_since_epoch - max_days
publishedDateStr = post_json_object['object']['published'] published_date_str = post_json_object['object']['published']
try: try:
publishedDate = \ published_date = \
datetime.datetime.strptime(publishedDateStr, datetime.datetime.strptime(published_date_str,
"%Y-%m-%dT%H:%M:%SZ") "%Y-%m-%dT%H:%M:%SZ")
except BaseException: except BaseException:
print('EX: is_recent_post unrecognized published date ' + print('EX: is_recent_post unrecognized published date ' +
str(publishedDateStr)) str(published_date_str))
return False return False
publishedDaysSinceEpoch = \ publishedDaysSinceEpoch = \
(publishedDate - datetime.datetime(1970, 1, 1)).days (published_date - datetime.datetime(1970, 1, 1)).days
if publishedDaysSinceEpoch < recently: if publishedDaysSinceEpoch < recently:
return False return False
return True return True