Use enumerations

merge-requests/26/head
Bob Mottram 2022-01-08 10:58:54 +00:00
parent 5341e5a274
commit 1085f97070
7 changed files with 12 additions and 13 deletions

View File

@ -290,7 +290,7 @@ def update_blocked_cache(base_dir: str,
with open(global_blocking_filename, 'r') as fp_blocked: with open(global_blocking_filename, 'r') as fp_blocked:
blocked_lines = fp_blocked.readlines() blocked_lines = fp_blocked.readlines()
# remove newlines # remove newlines
for index in range(len(blocked_lines)): for index, _ in enumerate(blocked_lines):
blocked_lines[index] = blocked_lines[index].replace('\n', '') blocked_lines[index] = blocked_lines[index].replace('\n', '')
# update the cache # update the cache
blocked_cache.clear() blocked_cache.clear()

View File

@ -143,7 +143,7 @@ def _person_receive_update_outbox(recent_posts_cache: {},
if 'attachment' not in actor_json: if 'attachment' not in actor_json:
continue continue
found = False found = False
for attach_idx in range(len(actor_json['attachment'])): for attach_idx, _ in enumerate(actor_json['attachment']):
if actor_json['attachment'][attach_idx]['type'] != \ if actor_json['attachment'][attach_idx]['type'] != \
'PropertyValue': 'PropertyValue':
continue continue

View File

@ -797,7 +797,7 @@ def person_upgrade_actor(base_dir: str, person_json: {},
update_actor = True update_actor = True
else: else:
# add location if it is missing # add location if it is missing
for index in range(len(person_json['hasOccupation'])): for index, _ in enumerate(person_json['hasOccupation']):
oc_item = person_json['hasOccupation'][index] oc_item = person_json['hasOccupation'][index]
if oc_item.get('hasOccupation'): if oc_item.get('hasOccupation'):
oc_item = oc_item['hasOccupation'] oc_item = oc_item['hasOccupation']

View File

@ -163,7 +163,7 @@ def _set_actor_role(actor_json: {}, role_name: str) -> bool:
if not category: if not category:
return False return False
for index in range(len(actor_json['hasOccupation'])): for index, _ in enumerate(actor_json['hasOccupation']):
occupation_item = actor_json['hasOccupation'][index] occupation_item = actor_json['hasOccupation'][index]
if not isinstance(occupation_item, dict): if not isinstance(occupation_item, dict):
continue continue

View File

@ -503,7 +503,7 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
follows = fp_foll.readlines() follows = fp_foll.readlines()
if len(follows) > 0: if len(follows) > 0:
follow_requests_exist = True follow_requests_exist = True
for i in range(len(follows)): for i, _ in enumerate(follows):
follows[i] = follows[i].strip() follows[i] = follows[i].strip()
follow_requests_list = follows follow_requests_list = follows
post_dm = False post_dm = False

View File

@ -559,7 +559,7 @@ def get_followers_list(base_dir: str,
with open(filename, 'r') as foll_file: with open(filename, 'r') as foll_file:
lines = foll_file.readlines() lines = foll_file.readlines()
for i in range(len(lines)): for i, _ in enumerate(lines):
lines[i] = lines[i].strip() lines[i] = lines[i].strip()
return lines return lines
return [] return []
@ -2126,7 +2126,7 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str,
if '+' in search_str: if '+' in search_str:
search_words = search_str.split('+') search_words = search_str.split('+')
for index in range(len(search_words)): for index, _ in enumerate(search_words):
search_words[index] = search_words[index].strip() search_words[index] = search_words[index].strip()
print('SEARCH: ' + str(search_words)) print('SEARCH: ' + str(search_words))
else: else:
@ -2178,7 +2178,7 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
if '+' in search_str: if '+' in search_str:
search_words = search_str.split('+') search_words = search_str.split('+')
for index in range(len(search_words)): for index, _ in enumerate(search_words):
search_words[index] = search_words[index].strip() search_words[index] = search_words[index].strip()
print('SEARCH: ' + str(search_words)) print('SEARCH: ' + str(search_words))
else: else:
@ -2811,7 +2811,7 @@ def set_occupation_name(actor_json: {}, name: str) -> bool:
return False return False
if not isinstance(actor_json['hasOccupation'], list): if not isinstance(actor_json['hasOccupation'], list):
return False return False
for index in range(len(actor_json['hasOccupation'])): for index, _ in enumerate(actor_json['hasOccupation']):
occupation_item = actor_json['hasOccupation'][index] occupation_item = actor_json['hasOccupation'][index]
if not isinstance(occupation_item, dict): if not isinstance(occupation_item, dict):
continue continue
@ -2831,7 +2831,7 @@ def set_occupation_skills_list(actor_json: {}, skills_list: []) -> bool:
return False return False
if not isinstance(actor_json['hasOccupation'], list): if not isinstance(actor_json['hasOccupation'], list):
return False return False
for index in range(len(actor_json['hasOccupation'])): for index, _ in enumerate(actor_json['hasOccupation']):
occupation_item = actor_json['hasOccupation'][index] occupation_item = actor_json['hasOccupation'][index]
if not isinstance(occupation_item, dict): if not isinstance(occupation_item, dict):
continue continue

View File

@ -941,9 +941,8 @@ def rss_hashtag_search(nickname: str, domain: str, port: int,
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
max_feed_length = 10 max_feed_length = 10
hashtag_feed = \ hashtag_feed = rss2tag_header(hashtag, http_prefix, domain_full)
rss2tag_header(hashtag, http_prefix, domain_full) for index, _ in enumerate(lines):
for index in range(len(lines)):
post_id = lines[index].strip('\n').strip('\r') post_id = lines[index].strip('\n').strip('\r')
if ' ' not in post_id: if ' ' not in post_id:
nickname = get_nickname_from_actor(post_id) nickname = get_nickname_from_actor(post_id)