From 9726ed0a644d8c0248f320f897a48cd42dddb27b Mon Sep 17 00:00:00 2001 From: spla Date: Tue, 20 Oct 2020 13:21:08 +0200 Subject: [PATCH] Now it exit when find first already published feed --- mastofeeds.py | 59 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/mastofeeds.py b/mastofeeds.py index 8ef907b..68f7885 100644 --- a/mastofeeds.py +++ b/mastofeeds.py @@ -1,3 +1,4 @@ +import pdb import os import feedparser from mastodon import Mastodon @@ -25,38 +26,40 @@ def get_parameter( parameter, file_path ): print(file_path + " Missing parameter %s "%parameter) sys.exit(0) -# Load secrets from secrets file -secrets_filepath = "secrets/secrets.txt" -uc_client_id = get_parameter("uc_client_id", secrets_filepath) -uc_client_secret = get_parameter("uc_client_secret", secrets_filepath) -uc_access_token = get_parameter("uc_access_token", secrets_filepath) - -# Load configuration from config file -db_config_filepath = "db_config.txt" -feeds_db = get_parameter("feeds_db", db_config_filepath) -feeds_db_user = get_parameter("feeds_db_user", db_config_filepath) -feeds_url = get_parameter("feeds_url", db_config_filepath) - -# Load configuration from config file -config_filepath = "config.txt" -mastodon_hostname = get_parameter("mastodon_hostname", config_filepath) # E.g., mastodon.social - -# Initialise Mastodon API -mastodon = Mastodon( - client_id = uc_client_id, - client_secret = uc_client_secret, - access_token = uc_access_token, - api_base_url = 'https://' + mastodon_hostname, -) - -# Initialise access headers -headers={ 'Authorization': 'Bearer %s'%uc_access_token } - ############################################################################### # main if __name__ == '__main__': + # Load secrets from secrets file + secrets_filepath = "secrets/secrets.txt" + uc_client_id = get_parameter("uc_client_id", secrets_filepath) + uc_client_secret = get_parameter("uc_client_secret", secrets_filepath) + uc_access_token = get_parameter("uc_access_token", secrets_filepath) + + # Load configuration from config file + db_config_filepath = "db_config.txt" + feeds_db = get_parameter("feeds_db", db_config_filepath) + feeds_db_user = get_parameter("feeds_db_user", db_config_filepath) + feeds_url = get_parameter("feeds_url", db_config_filepath) + + # Load configuration from config file + config_filepath = "config.txt" + mastodon_hostname = get_parameter("mastodon_hostname", config_filepath) # E.g., mastodon.social + + # Initialise Mastodon API + mastodon = Mastodon( + client_id = uc_client_id, + client_secret = uc_client_secret, + access_token = uc_access_token, + api_base_url = 'https://' + mastodon_hostname, + ) + + # Initialise access headers + headers={ 'Authorization': 'Bearer %s'%uc_access_token } + + ####################################################################### + publish = 0 newsfeeds = feedparser.parse(feeds_url) @@ -69,7 +72,6 @@ if __name__ == '__main__': ################################################################### # check database if feed is already published - ################################################################### try: @@ -140,3 +142,4 @@ if __name__ == '__main__': else: print("Any new feeds") + sys.exit(0)