rsstofedi.py
· 872 B · Python
Raw
import feedparser,re,time,requests
from mastodon import Mastodon
posts = []
with open(LOGFILE,"r") as log:
last = log.read()
rss = feedparser.parse(RSS)
guids = []
for entry in rss.entries:
if entry.guid == last:
break
else:
thestring = "[LINK TEXT](" + entry.link + ") " + entry.summary + " #TAG"
posts.append(thestring)
guids.append(entry.guid)
# repeat the above for each rss feed
mastodon = Mastodon(access_token="TOKEN",api_base_url="https://kes.praze.net",
feature_set="pleroma",version_check_mode="none")
if len(posts) > 0:
try:
posts = posts[::-1]
except:
pass
for post in posts:
mastodon.status_post(post,content_type="text/markdown")
time.sleep(10)
# repeat the below for each rss feed
if len(guids) > 0:
with open(LOGFILE,"w") as log:
log.write(guids[0])
| 1 | import feedparser,re,time,requests |
| 2 | from mastodon import Mastodon |
| 3 | |
| 4 | posts = [] |
| 5 | |
| 6 | with open(LOGFILE,"r") as log: |
| 7 | last = log.read() |
| 8 | rss = feedparser.parse(RSS) |
| 9 | guids = [] |
| 10 | for entry in rss.entries: |
| 11 | if entry.guid == last: |
| 12 | break |
| 13 | else: |
| 14 | thestring = "[LINK TEXT](" + entry.link + ") " + entry.summary + " #TAG" |
| 15 | posts.append(thestring) |
| 16 | guids.append(entry.guid) |
| 17 | |
| 18 | # repeat the above for each rss feed |
| 19 | |
| 20 | mastodon = Mastodon(access_token="TOKEN",api_base_url="https://kes.praze.net", |
| 21 | feature_set="pleroma",version_check_mode="none") |
| 22 | |
| 23 | if len(posts) > 0: |
| 24 | try: |
| 25 | posts = posts[::-1] |
| 26 | except: |
| 27 | pass |
| 28 | for post in posts: |
| 29 | mastodon.status_post(post,content_type="text/markdown") |
| 30 | time.sleep(10) |
| 31 | |
| 32 | # repeat the below for each rss feed |
| 33 | |
| 34 | if len(guids) > 0: |
| 35 | with open(LOGFILE,"w") as log: |
| 36 | log.write(guids[0]) |