mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-06-05 22:09:23 +02:00
Status prints
This commit is contained in:
@ -26,27 +26,33 @@ def MastodonGetPostsFromUserID(Session, UserID):
|
||||
|
||||
def MastodonDoPost(Session, Text, Lang=None, Visibility='public'):
|
||||
if Text:
|
||||
Session.status_post(
|
||||
return Session.status_post(
|
||||
Text,
|
||||
language=Lang,
|
||||
visibility=Visibility)
|
||||
|
||||
def MastodonGetLinkPosts(Session, Domain=None):
|
||||
def MastodonGetLinkFromPost(Post, Domain=None):
|
||||
Parse = BeautifulSoup(Post['content'], 'html.parser')
|
||||
if Parse.a:
|
||||
Link = Parse.find_all('a')[-1]['href']
|
||||
if not Domain or (Domain and Link.startswith(Domain)):
|
||||
return {
|
||||
'Post': Post['uri'],
|
||||
'Link': Link}
|
||||
return None
|
||||
|
||||
def MastodonGetAllLinkPosts(Session, Domain=None):
|
||||
Posts = []
|
||||
for i,e in enumerate(MastodonGetPostsFromUserID(Session, MastodonGetMyID(Session))):
|
||||
Parse = BeautifulSoup(e['content'], 'html.parser')
|
||||
if Parse.a:
|
||||
Link = Parse.find_all('a')[-1]['href']
|
||||
if not Domain or (Domain and Link.startswith(Domain)):
|
||||
Posts += [{
|
||||
'Post': e['uri'],
|
||||
'Link': Link}]
|
||||
for p in MastodonGetPostsFromUserID(Session, MastodonGetMyID(Session)):
|
||||
Post = MastodonGetLinkFromPost(p, Domain)
|
||||
if Post:
|
||||
Posts += [Post]
|
||||
return Posts
|
||||
|
||||
# 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):
|
||||
Session = MastodonGetSession(MastodonURL, MastodonToken)
|
||||
Posts = MastodonGetLinkPosts(Session, SiteDomain)
|
||||
Posts = MastodonGetAllLinkPosts(Session, SiteDomain)
|
||||
Pages.sort()
|
||||
for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages:
|
||||
if Meta['Type'] == 'Post':
|
||||
@ -69,8 +75,13 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
|
||||
DoPost = False
|
||||
break
|
||||
if DoPost:
|
||||
MastodonDoPost(
|
||||
Session,
|
||||
Desc + Read + URL,
|
||||
SiteLang)
|
||||
sleep(3)
|
||||
Post = MastodonGetLinkFromPost(
|
||||
Post=MastodonDoPost(
|
||||
Session,
|
||||
Text=Desc+Read+URL,
|
||||
Lang=SiteLang),
|
||||
Domain=SiteDomain)
|
||||
if Post:
|
||||
Posts += [Post]
|
||||
return Posts
|
||||
|
Reference in New Issue
Block a user