diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a7e9c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +Config.py diff --git a/MastodonFeedHTML.py b/MastodonFeedHTML/MastodonFeedHTML.py similarity index 80% rename from MastodonFeedHTML.py rename to MastodonFeedHTML/MastodonFeedHTML.py index 937633f..9bde210 100644 --- a/MastodonFeedHTML.py +++ b/MastodonFeedHTML/MastodonFeedHTML.py @@ -3,38 +3,14 @@ import base64 import feedparser import os import time -import urllib.request import email, smtplib, ssl from bs4 import BeautifulSoup from email import encoders from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText -# from Config import * - -Feeds = [ - { - "URLs": ["https://botsin.space/@sitoctt"], - "IncludeRetoots": True, - "IncludeReplies": True, - "LocalSave": True, - "SendMail": True, - "MailTo": ["example@example.com"] - } -] - -MailUsername = "example@example.com" -MailPassword = "Example" -MailServer = "smtp.example.com" -MailPort = 465 - -NoSpacesFile = False - -LoopTime = 0 -MailSleep = 10 - -AppName = "MastodonFeedHTML" - +from urllib.request import urlopen, Request +from Config import * StripWS = '\t\r\n' @@ -53,7 +29,7 @@ def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo URL = URL.rstrip('/').rstrip('/with_replies') + '/with_replies' Usertag = f"{URL.split('/')[-2]}@{URL.split('/')[-3]}" try: - Response = urllib.request.urlopen(URL) + Response = urlopen(Request(URL, headers={'User-Agent':UserAgent})) Data = Response.read() Soup = BeautifulSoup(Data, 'html.parser') Feed = Soup.find_all('div', class_='entry') @@ -61,12 +37,17 @@ def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo for Entry in Feed: Attached = '' - print(Entry) GlobalId = Entry.find('a', class_='u-url') if GlobalId: GlobalId = GlobalId['href'].lstrip('https://').lstrip('http://') else: continue + + if os.path.isfile(f'{AppName}.db'): + with open(f'{AppName}.db', 'r') as Db: + if GlobalId in Db.read().splitlines(): + continue + LocalId = GlobalId.split('/')[-1] Username = Entry.find('a', class_='status__display-name').get_text().strip(StripWS) Content = Entry.find('div', class_='e-content') @@ -79,16 +60,16 @@ def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo StatusPrepend = ' replied' Title = Content.get_text().strip(StripWS) Title = f"{Usertag}{StatusPrepend}: {Title[:32]}..." - for Emoji in Entry.find_all('img', class_='custom-emoji'): + for Emoji in Entry.find_all('img', class_='custom-emoji'): # Custom emojis in text Emoji['style'] = 'max-height:1em;' - Entry.find('img', class_='u-photo account__avatar')['style'] = 'max-height:2em;'#'display:none; visibility:hidden;' + Entry.find('img', class_='u-photo account__avatar')['style'] = 'max-height:4em;' # Profile pics Entry.find('div', class_='status__action-bar').replace_with('') print(f"-> {LocalId} - {Title}") HTML = f"""\