mirror of
https://gitlab.com/octospacc/bottocto
synced 2025-02-16 11:50:56 +01:00
Handle db per-user; Fix domain name issues
This commit is contained in:
parent
adb0909297
commit
ad45d852ee
20
MastodonFeedHTML/MastodonFeedHTML.py
Normal file → Executable file
20
MastodonFeedHTML/MastodonFeedHTML.py
Normal file → Executable file
@ -12,8 +12,6 @@ from email.mime.text import MIMEText
|
|||||||
from urllib.request import urlopen, Request
|
from urllib.request import urlopen, Request
|
||||||
from Config import *
|
from Config import *
|
||||||
|
|
||||||
StripWS = '\t\r\n'
|
|
||||||
|
|
||||||
def SureList(Item):
|
def SureList(Item):
|
||||||
return Item if type(Item) == list else [Item]
|
return Item if type(Item) == list else [Item]
|
||||||
|
|
||||||
@ -26,7 +24,7 @@ def MakePathStr(Str):
|
|||||||
|
|
||||||
def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo):
|
def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo):
|
||||||
for URL in URLs:
|
for URL in URLs:
|
||||||
URL = URL.rstrip('/').rstrip('/with_replies') + '/with_replies'
|
URL = URL.removesuffix('/').removesuffix('/with_replies') + '/with_replies'
|
||||||
Usertag = f"{URL.split('/')[-2]}@{URL.split('/')[-3]}"
|
Usertag = f"{URL.split('/')[-2]}@{URL.split('/')[-3]}"
|
||||||
try:
|
try:
|
||||||
Response = urlopen(Request(URL, headers={'User-Agent':UserAgent}))
|
Response = urlopen(Request(URL, headers={'User-Agent':UserAgent}))
|
||||||
@ -39,26 +37,26 @@ def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo
|
|||||||
Attached = ''
|
Attached = ''
|
||||||
GlobalId = Entry.find('a', class_='u-url')
|
GlobalId = Entry.find('a', class_='u-url')
|
||||||
if GlobalId:
|
if GlobalId:
|
||||||
GlobalId = GlobalId['href'].lstrip('https://').lstrip('http://')
|
GlobalId = GlobalId['href'].removeprefix('https://').removeprefix('http://')
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if os.path.isfile(f'{AppName}.db'):
|
if os.path.isfile(f'{AppName}.db'):
|
||||||
with open(f'{AppName}.db', 'r') as Db:
|
with open(f'{AppName}.db', 'r') as Db:
|
||||||
if GlobalId in Db.read().splitlines():
|
if f'{Usertag} {GlobalId}' in Db.read().splitlines():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
LocalId = GlobalId.split('/')[-1]
|
LocalId = GlobalId.split('/')[-1]
|
||||||
Username = Entry.find('a', class_='status__display-name').get_text().strip(StripWS)
|
Username = Entry.find('a', class_='status__display-name').get_text().strip()
|
||||||
Content = Entry.find('div', class_='e-content')
|
Content = Entry.find('div', class_='e-content')
|
||||||
StatusPrepend = Entry.find('div', class_='status__prepend')
|
StatusPrepend = Entry.find('div', class_='status__prepend')
|
||||||
StatusPrepend = StatusPrepend.get_text().strip(StripWS)[len(Username):] if StatusPrepend else ''
|
StatusPrepend = StatusPrepend.get_text().strip()[len(Username):] if StatusPrepend else ''
|
||||||
StatusPrepend = ' ' + StatusPrepend.strip(StripWS) if StatusPrepend else ''
|
StatusPrepend = ' ' + StatusPrepend.strip() if StatusPrepend else ''
|
||||||
if not IncludeRetoots and StatusPrepend:
|
if not IncludeRetoots and StatusPrepend:
|
||||||
continue
|
continue
|
||||||
if not StatusPrepend and IncludeReplies and Entry.find('i', class_='fa-reply-all'):
|
if not StatusPrepend and IncludeReplies and Entry.find('i', class_='fa-reply-all'):
|
||||||
StatusPrepend = ' replied'
|
StatusPrepend = ' replied'
|
||||||
Title = Content.get_text().strip(StripWS)
|
Title = Content.get_text().strip()
|
||||||
Title = f"{Usertag}{StatusPrepend}: {Title[:32]}..."
|
Title = f"{Usertag}{StatusPrepend}: {Title[:32]}..."
|
||||||
for Emoji in Entry.find_all('img', class_='custom-emoji'): # Custom emojis in text
|
for Emoji in Entry.find_all('img', class_='custom-emoji'): # Custom emojis in text
|
||||||
Emoji['style'] = 'max-height:1em;'
|
Emoji['style'] = 'max-height:1em;'
|
||||||
@ -90,7 +88,7 @@ def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo
|
|||||||
if Attachments:
|
if Attachments:
|
||||||
for Attachment in Attachments:
|
for Attachment in Attachments:
|
||||||
Href, Alt = '', ''
|
Href, Alt = '', ''
|
||||||
Attachment = str(Attachment).strip(StripWS).replace("'",'"').split('"')
|
Attachment = str(Attachment).strip().replace("'",'"').split('"')
|
||||||
for i,e in enumerate(Attachment):
|
for i,e in enumerate(Attachment):
|
||||||
if e.endswith('<a href='):
|
if e.endswith('<a href='):
|
||||||
Href = Attachment[i+1]
|
Href = Attachment[i+1]
|
||||||
@ -129,7 +127,7 @@ def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo
|
|||||||
File.write(HTML.replace('{ Replace:Attached }', Attached))
|
File.write(HTML.replace('{ Replace:Attached }', Attached))
|
||||||
|
|
||||||
with open(f'{AppName}.db', 'a') as Db:
|
with open(f'{AppName}.db', 'a') as Db:
|
||||||
Db.write(GlobalId + '\n')
|
Db.write(f'{Usertag} {GlobalId}' + '\n')
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user