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
usage: SpaceApiCli.py [-h] [-n NAME] [-v] [-w] usage: SpaceApiCli.py [-h] [-n NAME] [-l] [-v] [-w]
Show Space Status Show Space Status
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-n NAME, --name NAME Name of Hackerspace -n NAME, --name NAME Name of Hackerspace
-v Show more Infos of Hackerspace -l, --list List all Hackspaces on Spaceapi
-w get homepage url -v, --verbose Show more Infos of Hackspace
-w, --web get homepage url
Defaults: without option -n it will get the state of the hackspace Defaults: without option -n it will get the state of the hackspace
LeineLab in Hannover, Germany <https://leinelab.org>. LeineLab in Hannover, Germany <https://leinelab.org>.

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
# #
# Reiko Kaps 2015 <r31k@k4p5.de> # Reiko Kaps 2015-2020 <r31k@k4p5.de>
import json import json
import sys, os, argparse import sys, os, argparse
@ -16,9 +16,9 @@ except ImportError as e:
DIR_URL='https://directory.spaceapi.io/' DIR_URL='https://directory.spaceapi.io/'
def download(url): def download(url):
"""Download a file to local filesystem """
Download json endpoint
Parameter url: URL Parameter url: URL
returns string (json) returns string (json)
""" """
@ -30,11 +30,18 @@ def download(url):
return file.json() return file.json()
def save(json): def list_spaces():
status(json) """
file = open("./spaceapi.json", 'w') list all directory entries
file.write(str(json)) """
file.close() try:
directory = download(DIR_URL)
except ConnectionError:
raise
# print all entries
for name in directory:
print('{}'.format(name))
def status(json, verbose): def status(json, verbose):
"""Ermittelt aus dem Json den Status des Hackerspace""" """Ermittelt aus dem Json den Status des Hackerspace"""
@ -77,18 +84,24 @@ def getspaceurl(name, debug=False):
sys.exit(1) sys.exit(1)
def main(args): def main(args):
if args.v: if args.verbose:
debug = args.v debug = args.v
else: else:
debug = False debug = False
# get the full hackspace list and exit
if args.list:
list_spaces()
sys.exit(0)
try: try:
json = download(getspaceurl(args.name, debug)) json = download(getspaceurl(args.name, debug))
except ConnectionError as e: except ConnectionError as e:
print('not connected') print('not connected')
sys.exit(1) sys.exit(1)
if args.w: if args.web:
getHomepage(json, debug) getHomepage(json, debug)
sys.exit(0) sys.exit(0)
@ -99,8 +112,9 @@ def main(args):
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Show Space Status') parser = argparse.ArgumentParser(description='Show Space Status')
parser.add_argument('-n', '--name', help='Name of Hackerspace', default='LeineLab') 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('-l', '--list', action='store_true', help='List all Hackspaces on Spaceapi')
parser.add_argument('-w', action='store_true', help='get homepage url') 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() args = parser.parse_args()
main(args) main(args)