Commit b0a8aa37 authored by loelkes's avatar loelkes
Browse files

WIP

parents
# 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/
pip-wheel-metadata/
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/
# 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
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.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
# celery beat schedule file
celerybeat-schedule
# 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/
Copyright 2019 Christian Lölkes
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# infobeamerhosted
## Quick usage
```
pip install infobeamerhosted
python -m infobeamerhosted
```
## API
### Infobeamer()
```
from infobeamerhosted import *
InfobeamerAPI.KEY = 'your info beamer api key here'
foo = Infobeamer()
```
#### Properties
* ```.devices``` access all devices
* ```.setups``` access all devices
* ```.packages``` access all devices
* ```.assets``` access all devices
* ```.group : str``` Sets .group for all devices, setups, packages and assets.
### Common Properties for Devices(), Setups(), Packages(), Assets()
* ```.group```: the current group name used to select a subset of items. Set to '' (default) to disable.
* ```.all```: all items available.
* ```.selection```: items where the group name matches ```.group```. If this is not set the output is identitcal to ```.all```.
### Common Methods for Devices(), Setups, Packages(), Assets()
* ```getItems()```fetches all items from the Info-Beamer API. This is called upon initialization.
### Common Properties for Device(), Setup(), Package(), Asset()
* *Device()*: all properties from the [Device Object](https://info-beamer.com/doc/api#deviceobject)
* *Setup()*: all properties from the [Setup Info Object](https://info-beamer.com/doc/api#setupinfoobject)
* *Package()*: all properties from the [Package Object](https://info-beamer.com/doc/api#packageobject)
* *Asset()*: all properties from the [Package Object](https://info-beamer.com/doc/api#assetinfoobject)
* ```.group```: the current group name used to select a subset of items. Set to '' (default) to disable.
### Common Methods for Device(), Setup(), Package(), Asset()
* ```.inGroup(name: str) -> bool``` return True if the Item is in the group with the name *name*.
* ```.update([option: str, payload: dict]) -> bool```. Returns True if successfull, False otherwise.
* ```.delete() -> bool``` deletes the item. Returns True if successfull, False otherwise.
### InfobeamerAPI()
#### Static Properties
* ```InfobeamerAPI.KEY```holds our API key (required).
* ```InfobeamerAPI.USER```holds the username for the API. Default is set to ''.
* ```InfobeamerAPI.URL```holds the API URL. Default is set to https://info-beamer.com/api/v1/.
## Standalone use
```python -m infobeamerhosted```
### *API Settings*
* ```--api-key``` Key for info-beamer.com.
* ```--api-user``` User for info-beamer.com. Default is *empty*. (optional)
* ```--api-url``` Key from info-beamer.com. Default is **https://info-beamer.com/api/v1/** (optional)
You can also set environment variables for API_KEY, API_USER (optional), API_URL (optional).
```
export API_KEY = "infobeamer api key"
export API_USER = ""
export API_URL = "https://info-beamer.com/api/v1/"
```
## Ressources
* **API Documentation** [info-beamer.com/doc/api](https://info-beamer.com/doc/api)
import setuptools
with open('README.md', 'r') as fh:
long_description = fh.read()
setuptools.setup(
name='yanic',
version='1.0',
author='Christian Lölkes',
author_email='christian.loelkes@gmail.com',
description='Python wrapper around the YANIC API.',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/zkmkarlsruhe/pypi-yanic',
packages=setuptools.find_packages(),
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
python_requires='>=3.5',
install_requires=[
'requests',
],
)
from obelixtools import API
import logging
logger = logging.getLogger(__name__)
class YANIC(object):
def __init__(self, url=False):
self.url = url or 'https://api.frickelfunk.net/yanic/meshviewer/nodes.json'
self.api = API(url=self.url, format='json')
self.api.query()
self.nodes = self.api.content['nodes']
@property
def nodes(self):
return self.__nodes
@nodes.setter
def nodes(self, data):
self.__nodes = [Node(config) for config in data]
def select(self, id = False):
return next(node for node in self.nodes if node.id == id)
class Node:
def __init__(self, config):
self.__dict__.update(config)
@property
def id(self):
return self.statistics.node_id
# From https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
# See also https://en.wikipedia.org/wiki/Binary_prefix#yobi
def HRB(self, num, suffix='B'):
# Convert to Humand Readable Bits or Bytes (HRB)
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
return '{:3.1f}{}{}'.format(num, unit, suffix)
num /= 1024.0
return '{:.1f}{}{}'.format(num, 'Yi', suffix)
# Copyright 2019 Christian Lölkes
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import argparse
import logging
from yanic import *
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
if __name__ == '__main__':
ffka = YANIC()
logger.info('Found {} nodes'.format(len(ffka.nodes)))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment