mirror of https://gitlab.com/octtspacc/staticoso
Cringe fix
This commit is contained in:
parent
cafaf77d28
commit
cc7aaf19ec
|
@ -9,7 +9,13 @@ import string
|
|||
import datetime
|
||||
import collections
|
||||
from contextlib import closing
|
||||
import pytz
|
||||
|
||||
try:
|
||||
import pytz
|
||||
have_pytz = True
|
||||
except ModuleNotFoundError:
|
||||
have_pytz = False
|
||||
|
||||
import requests
|
||||
from requests.models import urlencode
|
||||
import dateutil
|
||||
|
@ -3176,11 +3182,11 @@ class Mastodon:
|
|||
"""
|
||||
date_time_utc = None
|
||||
if date_time.tzinfo is None:
|
||||
date_time_utc = date_time.replace(tzinfo=pytz.utc)
|
||||
date_time_utc = date_time.replace(tzinfo=pytz.utc) if have_pytz else date_time
|
||||
else:
|
||||
date_time_utc = date_time.astimezone(pytz.utc)
|
||||
date_time_utc = date_time.astimezone(pytz.utc) if have_pytz else date_time
|
||||
|
||||
epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc)
|
||||
epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc) if have_pytz else datetime.datetime.utcfromtimestamp(0)
|
||||
|
||||
return (date_time_utc - epoch_utc).total_seconds()
|
||||
|
||||
|
@ -3214,7 +3220,7 @@ class Mastodon:
|
|||
if v != None:
|
||||
try:
|
||||
if isinstance(v, int):
|
||||
json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc)
|
||||
json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc) if have_pytz else datetime.datetime
|
||||
else:
|
||||
json_object[k] = dateutil.parser.parse(v)
|
||||
except:
|
||||
|
@ -3266,7 +3272,7 @@ class Mastodon:
|
|||
every time instead of randomly doing different things on some systems
|
||||
and also it represents that time as the equivalent UTC time.
|
||||
"""
|
||||
isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
|
||||
isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z") if have_pytz else datetime_val.strftime("%Y-%m-%dT%H:%M:%S%z")
|
||||
if isotime[-2] != ":":
|
||||
isotime = isotime[:-2] + ":" + isotime[-2:]
|
||||
return isotime
|
||||
|
@ -3366,7 +3372,7 @@ class Mastodon:
|
|||
self.ratelimit_reset += server_time_diff
|
||||
self.ratelimit_lastcall = time.time()
|
||||
except Exception as e:
|
||||
raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e)
|
||||
pass #raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e)
|
||||
|
||||
# Handle response
|
||||
if self.debug_requests:
|
||||
|
|
|
@ -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('"', "'") + '...'
|
||||
|
|
Loading…
Reference in New Issue