mirror of https://gitlab.com/octtspacc/staticoso
ActivityPub time limit and filtering
This commit is contained in:
parent
7ac41b2884
commit
2c889c581f
|
@ -170,7 +170,10 @@ def Main(Args, FeedEntries):
|
||||||
Pages,
|
Pages,
|
||||||
SiteDomain,
|
SiteDomain,
|
||||||
SiteLang,
|
SiteLang,
|
||||||
Locale)
|
Locale,
|
||||||
|
TypeFilter=Args.ActivityPubTypeFilter if Args.ActivityPubTypeFilter else 'Post',
|
||||||
|
CategoryFilter=Args.ActivityPubCategoryFilter if Args.ActivityPubCategoryFilter else 'Blog',
|
||||||
|
HoursLimit=Args.ActivityPubHoursLimit if Args.ActivityPubHoursLimit else 168)
|
||||||
else:
|
else:
|
||||||
MastodonPosts = []
|
MastodonPosts = []
|
||||||
|
|
||||||
|
@ -220,6 +223,9 @@ if __name__ == '__main__':
|
||||||
Parser.add_argument('--MarkdownExts', type=str)
|
Parser.add_argument('--MarkdownExts', type=str)
|
||||||
Parser.add_argument('--MastodonURL', type=str)
|
Parser.add_argument('--MastodonURL', type=str)
|
||||||
Parser.add_argument('--MastodonToken', type=str)
|
Parser.add_argument('--MastodonToken', type=str)
|
||||||
|
Parser.add_argument('--ActivityPubTypeFilter', type=str)
|
||||||
|
Parser.add_argument('--ActivityPubCategoryFilter', type=str)
|
||||||
|
Parser.add_argument('--ActivityPubHoursLimit', type=int)
|
||||||
Parser.add_argument('--AutoCategories', type=str)
|
Parser.add_argument('--AutoCategories', type=str)
|
||||||
Args = Parser.parse_args()
|
Args = Parser.parse_args()
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
| Copyright (C) 2022, OctoSpacc |
|
| Copyright (C) 2022, OctoSpacc |
|
||||||
| ================================= """
|
| ================================= """
|
||||||
|
|
||||||
from time import sleep
|
import time
|
||||||
from Libs.bs4 import BeautifulSoup
|
from Libs.bs4 import BeautifulSoup
|
||||||
|
from Libs.dateutil.parser import parse as date_parse
|
||||||
from Libs.mastodon import Mastodon
|
from Libs.mastodon import Mastodon
|
||||||
from Modules.Utils import *
|
from Modules.Utils import *
|
||||||
|
|
||||||
|
@ -51,12 +52,12 @@ def MastodonGetAllLinkPosts(Session, Domain=None):
|
||||||
return Posts
|
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
|
# 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):
|
def MastodonShare(MastodonURL, MastodonToken, TypeFilter, CategoryFilter, HoursLimit, Pages, SiteDomain, SiteLang, Locale):
|
||||||
Session = MastodonGetSession(MastodonURL, MastodonToken)
|
Session = MastodonGetSession(MastodonURL, MastodonToken)
|
||||||
Posts = MastodonGetAllLinkPosts(Session, SiteDomain)
|
Posts = MastodonGetAllLinkPosts(Session, SiteDomain)
|
||||||
Pages.sort()
|
Pages.sort()
|
||||||
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
if Meta['Type'] == 'Post':
|
if (not TypeFilter or (TypeFilter and (Meta['Type'] == TypeFilter or TypeFilter == '*'))) and (not CategoryFilter or (CategoryFilter and (CategoryFilter in Meta['Categories'] or CategoryFilter == '*'))):
|
||||||
Desc = ''
|
Desc = ''
|
||||||
Parse = BeautifulSoup(ContentHTML, 'html.parser')
|
Parse = BeautifulSoup(ContentHTML, 'html.parser')
|
||||||
Paragraphs = Parse.p.get_text().split('\n')
|
Paragraphs = Parse.p.get_text().split('\n')
|
||||||
|
@ -75,8 +76,8 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
|
||||||
if p['Link'] == URL:
|
if p['Link'] == URL:
|
||||||
DoPost = False
|
DoPost = False
|
||||||
break
|
break
|
||||||
if DoPost:
|
if DoPost and (not HoursLimit or (Meta['Created on'] and time.time() - time.mktime(date_parse(Meta['Created on']).timetuple()) < 60*60*HoursLimit)):
|
||||||
sleep(3)
|
time.sleep(5)
|
||||||
Post = MastodonGetLinkFromPost(
|
Post = MastodonGetLinkFromPost(
|
||||||
Post=MastodonDoPost(
|
Post=MastodonDoPost(
|
||||||
Session,
|
Session,
|
||||||
|
|
Loading…
Reference in New Issue