delete orphaned lines, added a list option

This commit is contained in:
Reik Kaps 2020-02-05 23:03:34 +01:00
parent e4d487f968
commit 0c8c495350
1 changed files with 27 additions and 13 deletions

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)