mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
4ffee42529
commit
9d7e90a908
189
posts.py
189
posts.py
|
@ -3980,112 +3980,115 @@ def _create_box_items(base_dir: str,
|
||||||
'/' + index_box_name + '.index'
|
'/' + index_box_name + '.index'
|
||||||
total_posts_count = 0
|
total_posts_count = 0
|
||||||
posts_added_to_timeline = 0
|
posts_added_to_timeline = 0
|
||||||
if os.path.isfile(index_filename):
|
if not os.path.isfile(index_filename):
|
||||||
if first_post_id:
|
return total_posts_count, posts_added_to_timeline
|
||||||
first_post_id = first_post_id.replace('--', '#')
|
|
||||||
first_post_id = first_post_id.replace('/', '#')
|
|
||||||
with open(index_filename, 'r', encoding='utf-8') as index_file:
|
|
||||||
posts_added_to_timeline = 0
|
|
||||||
while posts_added_to_timeline < items_per_page:
|
|
||||||
post_filename = index_file.readline()
|
|
||||||
|
|
||||||
if not post_filename:
|
if first_post_id:
|
||||||
break
|
first_post_id = first_post_id.replace('--', '#')
|
||||||
|
first_post_id = first_post_id.replace('/', '#')
|
||||||
|
|
||||||
if first_post_id and total_posts_count == 0:
|
with open(index_filename, 'r', encoding='utf-8') as index_file:
|
||||||
if first_post_id not in post_filename:
|
posts_added_to_timeline = 0
|
||||||
continue
|
while posts_added_to_timeline < items_per_page:
|
||||||
total_posts_count = \
|
post_filename = index_file.readline()
|
||||||
int((page_number - 1) * items_per_page)
|
|
||||||
|
|
||||||
# Has this post passed through the newswire voting stage?
|
if not post_filename:
|
||||||
if not _passed_newswire_voting(newswire_votes_threshold,
|
break
|
||||||
base_dir, domain,
|
|
||||||
post_filename,
|
if first_post_id and total_posts_count == 0:
|
||||||
positive_voting,
|
if first_post_id not in post_filename:
|
||||||
voting_time_mins):
|
continue
|
||||||
|
total_posts_count = \
|
||||||
|
int((page_number - 1) * items_per_page)
|
||||||
|
|
||||||
|
# Has this post passed through the newswire voting stage?
|
||||||
|
if not _passed_newswire_voting(newswire_votes_threshold,
|
||||||
|
base_dir, domain,
|
||||||
|
post_filename,
|
||||||
|
positive_voting,
|
||||||
|
voting_time_mins):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Skip through any posts previous to the current page
|
||||||
|
if not first_post_id:
|
||||||
|
if total_posts_count < \
|
||||||
|
int((page_number - 1) * items_per_page):
|
||||||
|
total_posts_count += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Skip through any posts previous to the current page
|
# if this is a full path then remove the directories
|
||||||
if not first_post_id:
|
if '/' in post_filename:
|
||||||
if total_posts_count < \
|
post_filename = post_filename.split('/')[-1]
|
||||||
int((page_number - 1) * items_per_page):
|
|
||||||
total_posts_count += 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
# if this is a full path then remove the directories
|
# filename of the post without any extension or path
|
||||||
if '/' in post_filename:
|
# This should also correspond to any index entry in
|
||||||
post_filename = post_filename.split('/')[-1]
|
# the posts cache
|
||||||
|
post_url = remove_eol(post_filename)
|
||||||
|
post_url = post_url.replace('.json', '').strip()
|
||||||
|
|
||||||
# filename of the post without any extension or path
|
if post_url in post_urls_in_box:
|
||||||
# This should also correspond to any index entry in
|
continue
|
||||||
# the posts cache
|
|
||||||
post_url = remove_eol(post_filename)
|
|
||||||
post_url = post_url.replace('.json', '').strip()
|
|
||||||
|
|
||||||
if post_url in post_urls_in_box:
|
# is the post cached in memory?
|
||||||
|
if recent_posts_cache.get('index'):
|
||||||
|
if post_url in recent_posts_cache['index']:
|
||||||
|
if recent_posts_cache['json'].get(post_url):
|
||||||
|
url = recent_posts_cache['json'][post_url]
|
||||||
|
if _add_post_string_to_timeline(url,
|
||||||
|
boxname,
|
||||||
|
posts_in_box,
|
||||||
|
box_actor):
|
||||||
|
total_posts_count += 1
|
||||||
|
posts_added_to_timeline += 1
|
||||||
|
post_urls_in_box.append(post_url)
|
||||||
|
continue
|
||||||
|
print('Post not added to timeline')
|
||||||
|
|
||||||
|
# read the post from file
|
||||||
|
full_post_filename = \
|
||||||
|
locate_post(base_dir, nickname,
|
||||||
|
original_domain, post_url, False)
|
||||||
|
if full_post_filename:
|
||||||
|
# has the post been rejected?
|
||||||
|
if os.path.isfile(full_post_filename + '.reject'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# is the post cached in memory?
|
if _add_post_to_timeline(full_post_filename, boxname,
|
||||||
if recent_posts_cache.get('index'):
|
posts_in_box, box_actor):
|
||||||
if post_url in recent_posts_cache['index']:
|
posts_added_to_timeline += 1
|
||||||
if recent_posts_cache['json'].get(post_url):
|
total_posts_count += 1
|
||||||
url = recent_posts_cache['json'][post_url]
|
post_urls_in_box.append(post_url)
|
||||||
if _add_post_string_to_timeline(url,
|
|
||||||
boxname,
|
|
||||||
posts_in_box,
|
|
||||||
box_actor):
|
|
||||||
total_posts_count += 1
|
|
||||||
posts_added_to_timeline += 1
|
|
||||||
post_urls_in_box.append(post_url)
|
|
||||||
continue
|
|
||||||
print('Post not added to timeline')
|
|
||||||
|
|
||||||
# read the post from file
|
|
||||||
full_post_filename = \
|
|
||||||
locate_post(base_dir, nickname,
|
|
||||||
original_domain, post_url, False)
|
|
||||||
if full_post_filename:
|
|
||||||
# has the post been rejected?
|
|
||||||
if os.path.isfile(full_post_filename + '.reject'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if _add_post_to_timeline(full_post_filename, boxname,
|
|
||||||
posts_in_box, box_actor):
|
|
||||||
posts_added_to_timeline += 1
|
|
||||||
total_posts_count += 1
|
|
||||||
post_urls_in_box.append(post_url)
|
|
||||||
else:
|
|
||||||
print('WARN: Unable to add post ' + post_url +
|
|
||||||
' nickname ' + nickname +
|
|
||||||
' timeline ' + boxname)
|
|
||||||
else:
|
else:
|
||||||
if timeline_nickname != nickname:
|
print('WARN: Unable to add post ' + post_url +
|
||||||
# if this is the features timeline
|
' nickname ' + nickname +
|
||||||
full_post_filename = \
|
' timeline ' + boxname)
|
||||||
locate_post(base_dir, timeline_nickname,
|
else:
|
||||||
original_domain, post_url, False)
|
if timeline_nickname != nickname:
|
||||||
if full_post_filename:
|
# if this is the features timeline
|
||||||
if _add_post_to_timeline(full_post_filename,
|
full_post_filename = \
|
||||||
boxname,
|
locate_post(base_dir, timeline_nickname,
|
||||||
posts_in_box, box_actor):
|
original_domain, post_url, False)
|
||||||
posts_added_to_timeline += 1
|
if full_post_filename:
|
||||||
total_posts_count += 1
|
if _add_post_to_timeline(full_post_filename,
|
||||||
post_urls_in_box.append(post_url)
|
boxname,
|
||||||
else:
|
posts_in_box, box_actor):
|
||||||
print('WARN: Unable to add features post ' +
|
posts_added_to_timeline += 1
|
||||||
post_url + ' nickname ' + nickname +
|
total_posts_count += 1
|
||||||
' timeline ' + boxname)
|
post_urls_in_box.append(post_url)
|
||||||
else:
|
else:
|
||||||
print('WARN: features timeline. ' +
|
print('WARN: Unable to add features post ' +
|
||||||
'Unable to locate post ' + post_url)
|
post_url + ' nickname ' + nickname +
|
||||||
|
' timeline ' + boxname)
|
||||||
else:
|
else:
|
||||||
if timeline_nickname == 'news':
|
print('WARN: features timeline. ' +
|
||||||
print('WARN: Unable to locate news post ' +
|
'Unable to locate post ' + post_url)
|
||||||
post_url + ' nickname ' + nickname)
|
else:
|
||||||
else:
|
if timeline_nickname == 'news':
|
||||||
print('WARN: Unable to locate post ' + post_url +
|
print('WARN: Unable to locate news post ' +
|
||||||
' nickname ' + nickname)
|
post_url + ' nickname ' + nickname)
|
||||||
|
else:
|
||||||
|
print('WARN: Unable to locate post ' + post_url +
|
||||||
|
' nickname ' + nickname)
|
||||||
return total_posts_count, posts_added_to_timeline
|
return total_posts_count, posts_added_to_timeline
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue