Compare commits
25 Commits
Author | SHA1 | Date |
---|---|---|
Reik Kaps | d5bcc27608 | |
Reik Kaps | 16a73b5949 | |
Reik Kaps | 591ac112dd | |
Moridius | 93968d6526 | |
Moridius | 56d4ecdad3 | |
Reik Kaps | 1da5aa169f | |
Reik Kaps | 74da526fce | |
Reik Kaps | a56b03500e | |
Reik Kaps | 286d1018e0 | |
Moridius | 21e650a483 | |
Reik Kaps | 8203e62359 | |
Reik Kaps | 9215b20a13 | |
Reik Kaps | 1e47040b75 | |
Reik Kaps | b4b2edb409 | |
Reik Kaps | 1961aa8df4 | |
Reik Kaps | a3e8dd7f85 | |
Reik Kaps | 16495c4056 | |
Reik Kaps | 4dde81d3ae | |
Reik Kaps | a6f9d75a21 | |
Reik Kaps | 955ec3229f | |
Reik Kaps | cc5de7cbe3 | |
Reik Kaps | f07234b6ea | |
Reik Kaps | 0c8c495350 | |
Reik Kaps | e4d487f968 | |
Reik Kaps | 0b75a3772f |
|
@ -0,0 +1,20 @@
|
|||
name: Python application
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python 3.8
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.8
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python setup.py install
|
||||
|
11
README.md
11
README.md
|
@ -1,5 +1,7 @@
|
|||
# SpaceApiCli
|
||||
|
||||
![Python application](https://github.com/reikkaps/spaceapicli/workflows/Python%20application/badge.svg?branch=master)
|
||||
|
||||
a simple cmdline tool to access the hackspace-API from
|
||||
the unix console or toolbars like polybar
|
||||
|
||||
|
@ -16,16 +18,17 @@ the unix console or toolbars like polybar
|
|||
|
||||
## Usage
|
||||
|
||||
usage: SpaceApiCli.py [-h] [-n NAME] [-v] [-w]
|
||||
usage: SpaceApiCli.py [-h] [-n NAME] [-l] [-v] [-w]
|
||||
|
||||
Show Space Status
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-n NAME, --name NAME Name of Hackerspace
|
||||
-v Show more Infos of Hackerspace
|
||||
-w get homepage url
|
||||
|
||||
-l, --list List all Hackspaces on Spaceapi
|
||||
-v, --verbose Show more Infos of Hackspace
|
||||
-w, --web get homepage url
|
||||
|
||||
|
||||
Defaults: without option -n it will get the state of the hackspace
|
||||
LeineLab in Hannover, Germany <https://leinelab.org>.
|
||||
|
|
2
setup.py
2
setup.py
|
@ -1,7 +1,7 @@
|
|||
from setuptools import setup, find_packages
|
||||
setup(
|
||||
name="SpaceApiCli",
|
||||
version="0.1rc1",
|
||||
version="0.1rc2",
|
||||
packages=find_packages(),
|
||||
scripts=["src/SpaceApiCli.py"],
|
||||
|
||||
|
|
|
@ -1,60 +1,73 @@
|
|||
#!/usr/bin/python3
|
||||
#
|
||||
# Reiko Kaps 2015 <r31k@k4p5.de>
|
||||
# Reiko Kaps 2015-2020 <r31k@k4p5.de>
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys, os, argparse
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
try:
|
||||
try:
|
||||
import requests
|
||||
from requests.exceptions import ConnectionError
|
||||
except ImportError as e:
|
||||
except ImportError:
|
||||
print('please install requests python module')
|
||||
sys.exit(1)
|
||||
|
||||
DIR_URL='https://directory.spaceapi.io/'
|
||||
DIR_URL = 'https://directory.spaceapi.io/'
|
||||
|
||||
|
||||
def download(url):
|
||||
"""Download a file to local filesystem
|
||||
Parameter url: URL
|
||||
"""
|
||||
Download json endpoint
|
||||
Parameter url: URL
|
||||
returns string (json)
|
||||
"""
|
||||
try:
|
||||
file = requests.get(url)
|
||||
except ConnectionError as e:
|
||||
raise e
|
||||
|
||||
|
||||
return file.json()
|
||||
|
||||
|
||||
def save(json):
|
||||
status(json)
|
||||
file = open("./spaceapi.json", 'w')
|
||||
file.write(str(json))
|
||||
file.close()
|
||||
def list_spaces():
|
||||
"""
|
||||
list all directory entries
|
||||
"""
|
||||
try:
|
||||
directory = download(DIR_URL)
|
||||
except ConnectionError:
|
||||
raise
|
||||
# print all entries
|
||||
for name in directory:
|
||||
print('{}'.format(name))
|
||||
|
||||
def status(json, verbose):
|
||||
"""Ermittelt aus dem Json den Status des Hackerspace"""
|
||||
|
||||
def details(data, verbose):
|
||||
"""Show all details"""
|
||||
print(json.dumps(data, indent=4, sort_keys=True))
|
||||
|
||||
|
||||
def status(json_data, verbose):
|
||||
"""Ermittelt aus dem JSON den Status des Hackerspace"""
|
||||
if verbose is True:
|
||||
pass
|
||||
|
||||
if json['state']['open'] is False:
|
||||
print('🧘 closed'.format(str(json['space'])))
|
||||
|
||||
if json_data['state']['open'] is False:
|
||||
if verbose:
|
||||
print('{} is closed'.format(str(json_data['space'])))
|
||||
return False
|
||||
|
||||
print('🌞 open'.format(str(json['space'])))
|
||||
print('{} is open'.format(str(json_data['space'])))
|
||||
return True
|
||||
|
||||
|
||||
def getHomepage(json, verbose):
|
||||
def getHomepage(json_data, verbose):
|
||||
"""Ermittelt aus dem Json die Homepage des Hackerspace"""
|
||||
if json['url']:
|
||||
print('opening {}'.format(json['url']))
|
||||
subprocess.run(['firefox', json['url']])
|
||||
|
||||
if json_data['url']:
|
||||
print('opening {}'.format(json_data['url']))
|
||||
subprocess.run(['firefox', json_data['url']])
|
||||
else:
|
||||
return False
|
||||
|
||||
|
@ -64,7 +77,7 @@ def getspaceurl(name, debug=False):
|
|||
directory = download(DIR_URL)
|
||||
except ConnectionError:
|
||||
raise
|
||||
if name in directory:
|
||||
if name in directory:
|
||||
return directory[name]
|
||||
else:
|
||||
if debug:
|
||||
|
@ -76,34 +89,49 @@ def getspaceurl(name, debug=False):
|
|||
return directory[key]
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main(args):
|
||||
if args.v:
|
||||
debug = args.v
|
||||
|
||||
if args.verbose:
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
|
||||
|
||||
# get the full hackspace list and exit
|
||||
if args.list:
|
||||
list_spaces()
|
||||
sys.exit(0)
|
||||
|
||||
try:
|
||||
json = download(getspaceurl(args.name, debug))
|
||||
except ConnectionError as e:
|
||||
data = download(getspaceurl(args.name, debug))
|
||||
except ConnectionError:
|
||||
print('not connected')
|
||||
sys.exit(1)
|
||||
|
||||
if args.w:
|
||||
getHomepage(json, debug)
|
||||
if args.details:
|
||||
details(data, debug)
|
||||
sys.exit(0)
|
||||
|
||||
if status(json, verbose=False):
|
||||
|
||||
if args.web:
|
||||
getHomepage(data, debug)
|
||||
sys.exit(0)
|
||||
|
||||
if status(data, debug):
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='Show Space Status')
|
||||
parser.add_argument('-n', '--name', help='Name of Hackerspace', default='LeineLab')
|
||||
parser.add_argument('-v', action='store_true', help='Show more Infos of Hackerspace')
|
||||
parser.add_argument('-w', action='store_true', help='get homepage url')
|
||||
parser.add_argument('-n', '--name', help='Name of Hackerspace',
|
||||
default='LeineLab')
|
||||
parser.add_argument('-d', '--details',
|
||||
help='Shows more details of Hackerspace')
|
||||
parser.add_argument('-l', '--list', action='store_true',
|
||||
help='List all Hackspaces on Spaceapi')
|
||||
parser.add_argument('-v', '--verbose', action='store_true',
|
||||
help='verbose output')
|
||||
parser.add_argument('-w', '--web', action='store_true',
|
||||
help='get homepage url')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
main(args)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue