From ad3ec123d4543c8cc4106d9d11f6e8e806b90de3 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Tue, 8 Feb 2022 17:20:47 +0100 Subject: working --- rss_to_gitea/main.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'rss_to_gitea/main.py') diff --git a/rss_to_gitea/main.py b/rss_to_gitea/main.py index f4425a2..c1a4a11 100644 --- a/rss_to_gitea/main.py +++ b/rss_to_gitea/main.py @@ -6,29 +6,33 @@ import sys from .gitea import GiteaAPI from .atom import AtomFeed +from .config import Config +def print_help(): + print(''' +USAGE: + rsstogitea + ''') -feeds = [ - { - 'name':'Gitea', - 'url':'https://github.com/go-gitea/gitea/releases.atom', - 'exclude':['dev', 'rc'], - 'assign':'' - } -] +def main(): + if len(sys.argv) <= 1: + return 1 -def load_yaml(_file: str): - required = ['feeds', 'token', 'url'] - config = {} + config = Config(sys.argv[1]) + api = GiteaAPI("https://gitea.my.cum.re", config.token) - with open(_file, 'r') as f: - config = yaml.load(f.read(), Loader=yaml.FullLoader) + label_id = api.getLabelId(config.owner, config.repo, config.label) - return config + for feed in config.feeds: + remote = AtomFeed(feed['url']) + latest = remote.get_latest(feed['exclude'], feed['include']) -def main(): - #token = sys.argv[1] - #api = GiteaAPI("https://gitea.my.cum.re", token) - #api.searchIssue('infra', 'ansible', '', 'update') - feed = AtomFeed(feeds[0]['url']) - print(feed.get_latest([])) + issue_title = f'{feed["name"]}: {latest["title"]}' + print("Title=", issue_title) + + ticket = api.searchIssue(config.owner, config.repo, issue_title, [config.label]) + if ticket is not None: + print(f'{issue_title} already exists. Skipping') + continue + + result = api.createIssue(config.owner, config.repo, issue_title, '', feed['assign'], [label_id]) -- cgit v1.2.3