Merge branch 'feature/cacheLocal' into develop

This commit is contained in:
Reik Kaps 2020-02-05 23:05:00 +01:00
commit cc5de7cbe3
2 changed files with 32 additions and 17 deletions

View File

@ -16,16 +16,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>.

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
#
# Reiko Kaps 2015 <r31k@k4p5.de>
# Reiko Kaps 2015-2020 <r31k@k4p5.de>
import json
import sys, os, argparse
@ -16,9 +16,9 @@ except ImportError as e:
DIR_URL='https://directory.spaceapi.io/'
def download(url):
"""Download a file to local filesystem
"""
Download json endpoint
Parameter url: URL
returns string (json)
"""
@ -30,11 +30,18 @@ def download(url):
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"""
@ -77,18 +84,24 @@ def getspaceurl(name, debug=False):
sys.exit(1)
def main(args):
if args.v:
if args.verbose:
debug = args.v
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:
print('not connected')
sys.exit(1)
if args.w:
if args.web:
getHomepage(json, debug)
sys.exit(0)
@ -99,8 +112,9 @@ def main(args):
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('-l', '--list', action='store_true', help='List all Hackspaces on Spaceapi')
parser.add_argument('-v', '--verbose', action='store_true', help='Show more Infos of Hackspace')
parser.add_argument('-w', '--web', action='store_true', help='get homepage url')
args = parser.parse_args()
main(args)