mirror of https://gitlab.com/octtspacc/staticoso
Support for sharing new posts on Mastodon
This commit is contained in:
parent
e0777bd143
commit
045f5be79c
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"CreatedOn": "Created on",
|
"CreatedOn": "Created on",
|
||||||
"EditedOn": "Edited on",
|
"EditedOn": "Edited on",
|
||||||
"Categories": "Categories"
|
"Categories": "Categories",
|
||||||
|
"ReadFullPost": "Read the full post"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"CreatedOn": "Creato in data",
|
"CreatedOn": "Creato in data",
|
||||||
"EditedOn": "Modificato in data",
|
"EditedOn": "Modificato in data",
|
||||||
"Categories": "Categorie"
|
"Categories": "Categorie",
|
||||||
|
"ReadFullPost": "Leggi il post intero"
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,8 +441,11 @@ def SetSorting(Sorting):
|
||||||
def Main(Args, FeedEntries):
|
def Main(Args, FeedEntries):
|
||||||
SiteName = Args.SiteName if Args.SiteName else ''
|
SiteName = Args.SiteName if Args.SiteName else ''
|
||||||
SiteTagline = Args.SiteTagline if Args.SiteTagline else ''
|
SiteTagline = Args.SiteTagline if Args.SiteTagline else ''
|
||||||
SiteDomain = Args.SiteDomain if Args.SiteDomain else ''
|
SiteDomain = Args.SiteDomain.rstrip('/') if Args.SiteDomain else ''
|
||||||
SiteLang = Args.SiteLang if Args.SiteLang else 'en'
|
SiteLang = Args.SiteLang if Args.SiteLang else 'en'
|
||||||
|
Locale = LoadLocale(SiteLang)
|
||||||
|
MastodonURL = Args.MastodonURL if Args.MastodonURL else ''
|
||||||
|
MastodonToken = Args.MastodonToken if Args.MastodonToken else ''
|
||||||
|
|
||||||
ResetPublic()
|
ResetPublic()
|
||||||
if os.path.isdir('Pages'):
|
if os.path.isdir('Pages'):
|
||||||
|
@ -465,7 +468,7 @@ def Main(Args, FeedEntries):
|
||||||
SiteRoot=Args.SiteRoot if Args.SiteRoot else '/',
|
SiteRoot=Args.SiteRoot if Args.SiteRoot else '/',
|
||||||
FolderRoots=literal_eval(Args.FolderRoots) if Args.FolderRoots else {},
|
FolderRoots=literal_eval(Args.FolderRoots) if Args.FolderRoots else {},
|
||||||
Reserved=SetReserved(literal_eval(Args.ReservedPaths) if Args.ReservedPaths else {}),
|
Reserved=SetReserved(literal_eval(Args.ReservedPaths) if Args.ReservedPaths else {}),
|
||||||
Locale=LoadLocale(SiteLang),
|
Locale=Locale,
|
||||||
Minify=Args.Minify if Args.Minify else 'None',
|
Minify=Args.Minify if Args.Minify else 'None',
|
||||||
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
||||||
MarkdownExts=literal_eval(Args.MarkdownExts) if Args.MarkdownExts else ['attr_list'])
|
MarkdownExts=literal_eval(Args.MarkdownExts) if Args.MarkdownExts else ['attr_list'])
|
||||||
|
@ -483,16 +486,14 @@ def Main(Args, FeedEntries):
|
||||||
if Args.GemtextOut:
|
if Args.GemtextOut:
|
||||||
GemtextCompileList(Pages)
|
GemtextCompileList(Pages)
|
||||||
|
|
||||||
"""
|
if MastodonURL and MastodonToken and SiteDomain:
|
||||||
MastodonSession = MastodonGetSession(
|
MastodonShare(
|
||||||
Args.MastodonURL if Args.MastodonURL else '',
|
MastodonURL,
|
||||||
Args.MastodonToken if Args.MastodonToken else '')
|
MastodonToken,
|
||||||
MastodonPosts = MastodonGetPostsFromUserID(
|
Pages,
|
||||||
MastodonSession,
|
SiteDomain,
|
||||||
MastodonGetMyID(MastodonSession))
|
SiteLang,
|
||||||
for i in MastodonPosts:
|
Locale)
|
||||||
print(i['uri'], i['content'])
|
|
||||||
"""
|
|
||||||
|
|
||||||
DelTmp()
|
DelTmp()
|
||||||
os.system("cp -R Assets/* public/")
|
os.system("cp -R Assets/* public/")
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
| Copyright (C) 2022, OctoSpacc |
|
| Copyright (C) 2022, OctoSpacc |
|
||||||
| ================================= """
|
| ================================= """
|
||||||
|
|
||||||
|
from Libs.bs4 import BeautifulSoup
|
||||||
from Libs.mastodon import Mastodon
|
from Libs.mastodon import Mastodon
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
|
@ -23,5 +24,60 @@ def MastodonGetPostsFromUserID(Session, UserID):
|
||||||
UserID,
|
UserID,
|
||||||
exclude_replies=True)
|
exclude_replies=True)
|
||||||
|
|
||||||
def MastodonDoPost(Session):
|
def MastodonDoPost(Session, Text, Lang=None, Visibility='public'):
|
||||||
pass # mastodon.toot('Tooting from python using #mastodonpy !')
|
if Text:
|
||||||
|
Session.status_post(
|
||||||
|
Text,
|
||||||
|
language=Lang,
|
||||||
|
visibility=Visibility)
|
||||||
|
|
||||||
|
# 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,
|
||||||
|
MastodonGetMyID(Session))
|
||||||
|
for i,e in enumerate(Posts):
|
||||||
|
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':
|
||||||
|
Desc = ''
|
||||||
|
Parse = BeautifulSoup(HTMLContent, 'html.parser')
|
||||||
|
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:
|
||||||
|
if Desc:
|
||||||
|
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:
|
||||||
|
DoPost = False
|
||||||
|
break
|
||||||
|
if DoPost:
|
||||||
|
MastodonDoPost(
|
||||||
|
Session,
|
||||||
|
Desc + Read + URL,
|
||||||
|
SiteLang)
|
||||||
|
#BodyDescription = Parse.p.get_text()[:150].replace('\n', ' ').replace('"', "'") + '...'
|
||||||
|
|
|
@ -20,7 +20,7 @@ def MakeFeed(Pages, SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, Minify=
|
||||||
Feed.link(href=Link, rel='alternate')
|
Feed.link(href=Link, rel='alternate')
|
||||||
Feed.description(SiteTagline if SiteTagline else ' ')
|
Feed.description(SiteTagline if SiteTagline else ' ')
|
||||||
if SiteDomain:
|
if SiteDomain:
|
||||||
Feed.logo(SiteDomain.rstrip('/') + '/favicon.png')
|
Feed.logo(SiteDomain + '/favicon.png')
|
||||||
Feed.language(Lang)
|
Feed.language(Lang)
|
||||||
|
|
||||||
DoPages = []
|
DoPages = []
|
||||||
|
@ -35,7 +35,7 @@ def MakeFeed(Pages, SiteName, SiteTagline, SiteDomain, MaxEntries, Lang, Minify=
|
||||||
Entry = Feed.add_entry()
|
Entry = Feed.add_entry()
|
||||||
File = '{}.html'.format(StripExt(File))
|
File = '{}.html'.format(StripExt(File))
|
||||||
Content = ReadFile('public/'+File)
|
Content = ReadFile('public/'+File)
|
||||||
Link = SiteDomain+'/'+File if SiteDomain else ' '
|
Link = SiteDomain + '/' + File if SiteDomain else ' '
|
||||||
CreatedOn = GetFullDate(Meta['CreatedOn'])
|
CreatedOn = GetFullDate(Meta['CreatedOn'])
|
||||||
EditedOn = GetFullDate(Meta['EditedOn'])
|
EditedOn = GetFullDate(Meta['EditedOn'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue