Cringe fix

This commit is contained in:
2022-07-01 01:04:20 +02:00
parent cafaf77d28
commit cc7aaf19ec
2 changed files with 14 additions and 21 deletions

View File

@ -8,7 +8,7 @@
| ================================= """
from Libs.bs4 import BeautifulSoup
#from Libs.mastodon import Mastodon
from Libs.mastodon import Mastodon
from Modules.Utils import *
def MastodonGetSession(MastodonURL, MastodonToken):
@ -33,7 +33,6 @@ def MastodonDoPost(Session, Text, Lang=None, Visibility='public'):
# TODO: Set a limit/cooldown on how many new posts at a time can be posted, or ignore posts older than date X.. otherwise if someone starts using this after having written 100 blog posts, bad things will happen
def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Locale):
#return None
Session = MastodonGetSession(MastodonURL, MastodonToken)
Posts = MastodonGetPostsFromUserID(
Session,
@ -42,10 +41,7 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
Parse = BeautifulSoup(e['content'], 'html.parser')
Posts[i] = {
'URL': e['uri'],
#e['content'],
'LastLink': Parse.find_all('a')[-1]['href'] if Parse.a else None}
#print(i['uri'], i['content'])
#print(Posts)
Pages.sort()
for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages:
if Meta['Type'] == 'Post':
@ -54,13 +50,7 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
Paragraphs = Parse.p.get_text().split('\n')
Read = '...' + Locale['ReadFullPost'] + ':\n'
URL = '{}/{}.html'.format(SiteDomain, StripExt(File))
#Desc = '...' + Read + ':\n' + URL
#DescLen = len(Read) + 30
#if not Paragraphs[0]:
# Paragraphs.pop(0)
for p in Paragraphs:
#while len(Description) <= 450:
#if p and len(Description+p)+2 <= 450:
if p and len(Read+Desc+p)+25 < 500:
Desc += p + '\n\n'
else:
@ -68,8 +58,6 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
break
else:
Desc = p[:500-25-5-len(Read)] + '...'
#if len(Description) > 450:
# Description = Description[:450] + '...'
DoPost = True
for p in Posts:
if p['LastLink'] == URL:
@ -80,4 +68,3 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
Session,
Desc + Read + URL,
SiteLang)
#BodyDescription = Parse.p.get_text()[:150].replace('\n', ' ').replace('"', "'") + '...'