diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2022-01-16 11:24:24 +0100 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2022-01-16 11:24:24 +0100 |
commit | 9281e283cd46598e3ffee853a343f8623c12d5e4 (patch) | |
tree | 1706bceb579d21a562b550c26c2b7f9bc761e4e1 /rss_to_gitea | |
download | atom_to_gitea-9281e283cd46598e3ffee853a343f8623c12d5e4.tar.gz |
init
Diffstat (limited to 'rss_to_gitea')
-rw-r--r-- | rss_to_gitea/__main__.py | 4 | ||||
-rw-r--r-- | rss_to_gitea/gitea.py | 54 | ||||
-rw-r--r-- | rss_to_gitea/main.py | 8 |
3 files changed, 66 insertions, 0 deletions
diff --git a/rss_to_gitea/__main__.py b/rss_to_gitea/__main__.py new file mode 100644 index 0000000..40e2b01 --- /dev/null +++ b/rss_to_gitea/__main__.py @@ -0,0 +1,4 @@ +from .main import main + +if __name__ == "__main__": + main() diff --git a/rss_to_gitea/gitea.py b/rss_to_gitea/gitea.py new file mode 100644 index 0000000..fdb1203 --- /dev/null +++ b/rss_to_gitea/gitea.py @@ -0,0 +1,54 @@ +import requests +import json + +APIBASE="/api/v1" + +class GiteaAPIAuthException (Exception): + pass + +class GiteaAPIException (Exception): + pass + +class GiteaAPI: + def __init__(self, _url, _token): + self.token = _token + self.address = _url.strip('/') + APIBASE + + headers={'Authorization':f'token {self.token}'} + result = requests.get(f'{self.address}/user',headers=headers) + + if result.status_code != 200: + raise GiteaAPIAuthException(result.json()['message']) + + self.username = result.json()['login'] + + def _api_get(self, _endpoint, _params): + headers={ + 'Authorization':f'token {self.token}', + 'Content-Type': 'application/json', + 'accept': 'application/json' + } + result = requests.get(f'{self.address}/{_endpoint}',headers=headers, params=_params) + + return result.json() + + + def createIssue(self, owner, repo, title, content): + pass + + def searchIssue(self, _owner, _repo, _title, _labels): + data= { + 'state':'open', + 'labels':_labels, + 'created_by':self.username, + 'q':_title + } + + result = self._api_get(f'repos/{_owner}/{_repo}/issues', data ) + + for issue in result: + print(issue['title']) + + def updateIssue(self, owner, repo, issueid): + pass + diff --git a/rss_to_gitea/main.py b/rss_to_gitea/main.py new file mode 100644 index 0000000..93c16de --- /dev/null +++ b/rss_to_gitea/main.py @@ -0,0 +1,8 @@ +import xml +import sys +from .gitea import GiteaAPI + +def main(): + token = sys.argv[1] + api = GiteaAPI("https://gitea.my.cum.re", token) + api.searchIssue('infra', 'ansible', '', 'update') |