commit
591ac112dd
|
@ -2,19 +2,20 @@
|
||||||
#
|
#
|
||||||
# Reiko Kaps 2015-2020 <r31k@k4p5.de>
|
# Reiko Kaps 2015-2020 <r31k@k4p5.de>
|
||||||
|
|
||||||
|
import argparse
|
||||||
import json
|
import json
|
||||||
import sys, os, argparse
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import requests
|
import requests
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
except ImportError as e:
|
except ImportError:
|
||||||
print('please install requests python module')
|
print('please install requests python module')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
DIR_URL='https://directory.spaceapi.io/'
|
DIR_URL = 'https://directory.spaceapi.io/'
|
||||||
|
|
||||||
|
|
||||||
def download(url):
|
def download(url):
|
||||||
"""
|
"""
|
||||||
|
@ -48,25 +49,24 @@ def details(data, verbose):
|
||||||
print(json.dumps(data, indent=4, sort_keys=True))
|
print(json.dumps(data, indent=4, sort_keys=True))
|
||||||
|
|
||||||
|
|
||||||
def status(json, verbose):
|
def status(json_data, verbose):
|
||||||
"""Ermittelt aus dem Json den Status des Hackerspace"""
|
"""Ermittelt aus dem JSON den Status des Hackerspace"""
|
||||||
if verbose is True:
|
if verbose is True:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if json['state']['open'] is False:
|
if json_data['state']['open'] is False:
|
||||||
print(' {} is closed'.format(str(json['space'])))
|
print(' {} is closed'.format(str(json_data['space'])))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print(' {} is open'.format(str(json['space'])))
|
print(' {} is open'.format(str(json_data['space'])))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def getHomepage(json, verbose):
|
def getHomepage(json_data, verbose):
|
||||||
"""Ermittelt aus dem Json die Homepage des Hackerspace"""
|
"""Ermittelt aus dem Json die Homepage des Hackerspace"""
|
||||||
if json['url']:
|
if json_data['url']:
|
||||||
print('opening {}'.format(json['url']))
|
print('opening {}'.format(json_data['url']))
|
||||||
subprocess.run(['firefox', json['url']])
|
subprocess.run(['firefox', json_data['url']])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ def getspaceurl(name, debug=False):
|
||||||
return directory[key]
|
return directory[key]
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
|
@ -100,23 +101,21 @@ def main(args):
|
||||||
list_spaces()
|
list_spaces()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
json = download(getspaceurl(args.name, debug))
|
data = download(getspaceurl(args.name, debug))
|
||||||
except ConnectionError as e:
|
except ConnectionError:
|
||||||
print('not connected')
|
print('not connected')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if args.details:
|
if args.details:
|
||||||
details(json, debug)
|
details(data, debug)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if args.web:
|
if args.web:
|
||||||
getHomepage(json, debug)
|
getHomepage(data, debug)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if status(json, verbose=False):
|
if status(data, verbose=False):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,6 +129,3 @@ if __name__ == "__main__":
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
main(args)
|
main(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue