Snake case

main
Bob Mottram 2021-12-27 16:18:52 +00:00
parent 7bd8d630e0
commit 322338a455
3 changed files with 47 additions and 51 deletions

View File

@ -339,7 +339,7 @@ from happening import removeCalendarEvent
from bookmarks import bookmark from bookmarks import bookmark
from bookmarks import undoBookmark from bookmarks import undoBookmark
from petnames import setPetName from petnames import setPetName
from followingCalendar import addPersonToCalendar from followingCalendar import add_person_to_calendar
from followingCalendar import removePersonFromCalendar from followingCalendar import removePersonFromCalendar
from notifyOnPost import addNotifyOnPost from notifyOnPost import addNotifyOnPost
from notifyOnPost import removeNotifyOnPost from notifyOnPost import removeNotifyOnPost
@ -2434,11 +2434,11 @@ class PubServer(BaseHTTPRequestHandler):
if '&' in onCalendar: if '&' in onCalendar:
onCalendar = onCalendar.split('&')[0] onCalendar = onCalendar.split('&')[0]
if onCalendar == 'on': if onCalendar == 'on':
addPersonToCalendar(base_dir, add_person_to_calendar(base_dir,
chooserNickname, chooserNickname,
domain, domain,
optionsNickname, optionsNickname,
optionsDomainFull) optionsDomainFull)
else: else:
removePersonFromCalendar(base_dir, removePersonFromCalendar(base_dir,
chooserNickname, chooserNickname,

View File

@ -135,9 +135,9 @@ def _receiveCalendarEvents(base_dir: str, nickname: str, domain: str,
print('EX: _receiveCalendarEvents 4 ' + calendarFilename) print('EX: _receiveCalendarEvents 4 ' + calendarFilename)
def addPersonToCalendar(base_dir: str, nickname: str, domain: str, def add_person_to_calendar(base_dir: str, nickname: str, domain: str,
followingNickname: str, followingNickname: str,
followingDomain: str) -> None: followingDomain: str) -> None:
_receiveCalendarEvents(base_dir, nickname, domain, _receiveCalendarEvents(base_dir, nickname, domain,
followingNickname, followingDomain, True) followingNickname, followingDomain, True)

View File

@ -18,7 +18,7 @@ import locale
from pprint import pprint from pprint import pprint
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hashes
from followingCalendar import addPersonToCalendar from followingCalendar import add_person_to_calendar
# posts containing these strings will always get screened out, # posts containing these strings will always get screened out,
# both incoming and outgoing. # both incoming and outgoing.
@ -54,7 +54,7 @@ def get_actor_languages_list(actor_json: {}) -> []:
lang_list = property_value['value'] lang_list = property_value['value']
lang_list.sort() lang_list.sort()
return lang_list return lang_list
elif isinstance(property_value['value'], str): if isinstance(property_value['value'], str):
lang_str = property_value['value'] lang_str = property_value['value']
lang_list_temp = [] lang_list_temp = []
if ',' in lang_str: if ',' in lang_str:
@ -216,8 +216,8 @@ def valid_post_date(published: str, max_age_days: int, debug: bool) -> bool:
""" """
baseline_time = datetime.datetime(1970, 1, 1) baseline_time = datetime.datetime(1970, 1, 1)
daysDiff = datetime.datetime.utcnow() - baseline_time days_diff = datetime.datetime.utcnow() - baseline_time
now_days_since_epoch = daysDiff.days now_days_since_epoch = days_diff.days
try: try:
post_time_object = \ post_time_object = \
@ -250,7 +250,7 @@ def get_full_domain(domain: str, port: int) -> str:
return domain return domain
if ':' in domain: if ':' in domain:
return domain return domain
if port == 80 or port == 443: if port in (80, 443):
return domain return domain
return domain + ':' + str(port) return domain + ':' + str(port)
@ -289,24 +289,22 @@ def is_dormant(base_dir: str, nickname: str, domain: str, actor: str,
def is_editor(base_dir: str, nickname: str) -> bool: def is_editor(base_dir: str, nickname: str) -> bool:
"""Returns true if the given nickname is an editor """Returns true if the given nickname is an editor
""" """
editorsFile = base_dir + '/accounts/editors.txt' editors_file = base_dir + '/accounts/editors.txt'
if not os.path.isfile(editorsFile): if not os.path.isfile(editors_file):
admin_name = get_config_param(base_dir, 'admin') admin_name = get_config_param(base_dir, 'admin')
if not admin_name: if admin_name:
return False
if admin_name == nickname:
return True
return False
with open(editorsFile, 'r') as f:
lines = f.readlines()
if len(lines) == 0:
admin_name = get_config_param(base_dir, 'admin')
if not admin_name:
return False
if admin_name == nickname: if admin_name == nickname:
return True return True
return False
with open(editors_file, 'r') as editors:
lines = editors.readlines()
if len(lines) == 0:
admin_name = get_config_param(base_dir, 'admin')
if admin_name:
if admin_name == nickname:
return True
for editor in lines: for editor in lines:
editor = editor.strip('\n').strip('\r') editor = editor.strip('\n').strip('\r')
if editor == nickname: if editor == nickname:
@ -321,20 +319,18 @@ def is_artist(base_dir: str, nickname: str) -> bool:
if not os.path.isfile(artists_file): if not os.path.isfile(artists_file):
admin_name = get_config_param(base_dir, 'admin') admin_name = get_config_param(base_dir, 'admin')
if not admin_name: if admin_name:
return False
if admin_name == nickname:
return True
return False
with open(artists_file, 'r') as f:
lines = f.readlines()
if len(lines) == 0:
admin_name = get_config_param(base_dir, 'admin')
if not admin_name:
return False
if admin_name == nickname: if admin_name == nickname:
return True return True
return False
with open(artists_file, 'r') as artists:
lines = artists.readlines()
if len(lines) == 0:
admin_name = get_config_param(base_dir, 'admin')
if admin_name:
if admin_name == nickname:
return True
for artist in lines: for artist in lines:
artist = artist.strip('\n').strip('\r') artist = artist.strip('\n').strip('\r')
if artist == nickname: if artist == nickname:
@ -363,7 +359,7 @@ def get_image_extensions() -> []:
def get_image_mime_type(image_filename: str) -> str: def get_image_mime_type(image_filename: str) -> str:
"""Returns the mime type for the given image """Returns the mime type for the given image
""" """
extensionsToMime = { extensions_to_mime = {
'png': 'png', 'png': 'png',
'jpg': 'jpeg', 'jpg': 'jpeg',
'gif': 'gif', 'gif': 'gif',
@ -372,7 +368,7 @@ def get_image_mime_type(image_filename: str) -> str:
'webp': 'webp', 'webp': 'webp',
'ico': 'x-icon' 'ico': 'x-icon'
} }
for ext, mime_ext in extensionsToMime.items(): for ext, mime_ext in extensions_to_mime.items():
if image_filename.endswith('.' + ext): if image_filename.endswith('.' + ext):
return 'image/' + mime_ext return 'image/' + mime_ext
return 'image/png' return 'image/png'
@ -1195,13 +1191,13 @@ def followPerson(base_dir: str, nickname: str, domain: str,
return True return True
# prepend to follow file # prepend to follow file
try: try:
with open(filename, 'r+') as f: with open(filename, 'r+') as fp:
content = f.read() content = fp.read()
if handleToFollow + '\n' not in content: if handleToFollow + '\n' not in content:
f.seek(0, 0) fp.seek(0, 0)
f.write(handleToFollow + '\n' + content) fp.write(handleToFollow + '\n' + content)
print('DEBUG: follow added') print('DEBUG: follow added')
except Exception as ex: except OSError as ex:
print('WARN: Failed to write entry to follow file ' + print('WARN: Failed to write entry to follow file ' +
filename + ' ' + str(ex)) filename + ' ' + str(ex))
else: else:
@ -1210,8 +1206,8 @@ def followPerson(base_dir: str, nickname: str, domain: str,
print('DEBUG: ' + handle + print('DEBUG: ' + handle +
' creating new following file to follow ' + handleToFollow + ' creating new following file to follow ' + handleToFollow +
', filename is ' + filename) ', filename is ' + filename)
with open(filename, 'w+') as f: with open(filename, 'w+') as fp:
f.write(handleToFollow + '\n') fp.write(handleToFollow + '\n')
if follow_file.endswith('following.txt'): if follow_file.endswith('following.txt'):
# Default to adding new follows to the calendar. # Default to adding new follows to the calendar.
@ -1221,8 +1217,8 @@ def followPerson(base_dir: str, nickname: str, domain: str,
print('DEBUG: adding ' + print('DEBUG: adding ' +
followNickname + '@' + followDomain + ' to calendar of ' + followNickname + '@' + followDomain + ' to calendar of ' +
nickname + '@' + domain) nickname + '@' + domain)
addPersonToCalendar(base_dir, nickname, domain, add_person_to_calendar(base_dir, nickname, domain,
followNickname, followDomain) followNickname, followDomain)
# add a default petname # add a default petname
_setDefaultPetName(base_dir, nickname, domain, _setDefaultPetName(base_dir, nickname, domain,
followNickname, followDomain) followNickname, followDomain)