import os import sys import time from app.libraries.database import Database from app.libraries.setup import Setup import feedparser from mastodon import Mastodon import psycopg2 import pdb # main if __name__ == '__main__': pdb.set_trace() db = Database() setup = Setup() mastodon = Mastodon( access_token = setup.mastodon_app_token, api_base_url= setup.mastodon_hostname ) #publish = 0 try: newsfeeds = feedparser.parse(db.feeds_url) print(newsfeeds.status) except: print(newsfeeds.status) sys.exit(0) for entry in newsfeeds.entries: title = entry['title'] id = entry['id'] link = entry['link'] # check database if feed is already published publish = db.published(link) if publish: toot_text = str(title)+'\n' toot_text += str(link) print("Tooting...") print(toot_text) mastodon.status_post(toot_text, in_reply_to_id=None,) time.sleep(2) # write feed db.write_feed(link) else: print("Any new feeds") sys.exit(0)