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 | |
download | atom_to_gitea-9281e283cd46598e3ffee853a343f8623c12d5e4.tar.gz |
init
-rw-r--r-- | .gitignore | 138 | ||||
-rw-r--r-- | README.md | 1 | ||||
-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 | ||||
-rwxr-xr-x | setup.py | 24 |
6 files changed, 229 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a81c8ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,138 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..42c90e4 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# rss-to-gitea 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') diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..1d7400c --- /dev/null +++ b/setup.py @@ -0,0 +1,24 @@ +from distutils.core import setup +import setuptools + +setup( + name='rsstogitea', + version='0.0.0-dev', + author="Jonas Gunz", + description="Create a Gitea Issue for new RSS entries", + packages=['rss_to_gitea'], + entry_points={ + 'console_scripts': ['rsstogitea=rss_to_gitea.main:main'] + }, + install_requires=[ + "requests>=2.25.1" + ], + license='All rights reserved', + long_description=open('README.md').read(), + long_description_content_type="text/markdown", + classifiers=[ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + ], +) + |