This repository has been archived by the owner on Dec 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathauto_add_libraries.py
112 lines (87 loc) · 3.81 KB
/
auto_add_libraries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python3
from add_library import *
import webbrowser
import sys
APIS = {
'bibliotheca' : Bibliotheca,
'sisis' : Sisis,
'biber1992' : Biber1992,
'zones22' : Zones22,
'iopac' : IOpac,
'pica' : Pica,
'adis' : Adis,
'webopac.net' : WebOpacNet,
'winbiap' : WinBiap,
}
if __name__ == '__main__':
print("Hallo! Dieses Skript hilft dir, eine neue Bibliothek hinzuzufügen")
if not os.path.isdir(LIBDIR):
print("Bitte wechsle in das Verzeichnis, in dem die App liegt.")
sys.exit(0)
print("Welche Datei enthält die Liste der Bibliotheken?")
filename = getInput(required=True, default=sys.argv[1] if len(sys.argv) > 1 else "");
json_list = open(filename).read();
list = json.loads(json_list);
api = sys.argv[2] if len(sys.argv) > 2 else ""
while api not in APIS.keys():
print("Welche API-Implementierung wird genutzt?")
print("Verfügbar sind: " + " ".join(APIS.keys()))
api = getInput(required=True)
for library in list:
data = {};
try:
webbrowser.get().open('https://www.google.de/search?hl=de&q=%s+%s' % (
library['title'], library['city'])
)
except:
pass
library['title'] = library['title'].replace(library['city'], "");
library['title'] = library['title'].strip();
data['city'] = library['city'];
data['title'] = library['title'];
print("---------------------------------");
print("Stadt: " + data['city']);
print("Bibliothek: " + data['title']);
print("Lade Geodaten...")
geo = loadGeoPossibilities(data['city'])
for k, g in enumerate(geo):
print("[%d] %s" % (k + 1, g[0]))
print("Welche dieser Positionen trifft am besten zu? 0 für überspringen.")
print("Nummer", end=" ")
geokey = int(getInput(default="0"))
if geokey > 0:
data['geo'] = geo[geokey - 1][1]
if geokey == 0:
continue
data['state'] = library['country'];
data['state'] = library['state'];
print("Bundesland: " + data['state']);
data['api'] = api;
data['data'] = {};
data['data']['baseurl'] = library['baseurl'];
print("OPAC-URL: " + data['data']['baseurl']);
print("URL zu einer Informationsseite")
print("Sollte Öffnungszeiten u.ä. enthalten")
data['information'] = getInput(required=True)
data['account_supported'] = APIS[api]().accountSupported();
data = APIS[api]().prompt(data)
ok = False;
while not ok:
print("Dateiname")
print("Sowas wie 'Mannheim' oder 'Heidelberg_Uni'. Möglichst keine Leerzeichen und Umlaute.")
if data['title'] in ("Stadtbibliothek", "Stadtbücherei", "Gemeindebücherei", "Gemeindebibliothek"):
name = data['city'];
else:
name = data['city'] + " " + data['title'];
name = name.replace(" ", "_").replace("ä", "ae").replace("ü", "ue").replace("ö", "oe").replace("ß", "ss");
ident = getInput(required=True, default = name);
if os.path.isfile(LIBDIR + ident + '.json'):
print("ACHTUNG: Datei existiert bereits. Überschreiben? (j/n)");
value = getInput(required=True, default="n")
if value == "j":
ok = True;
else:
ok = True;
print(json.dumps(data, indent=4, sort_keys=True), end="\n\n")
json.dump(data, open(LIBDIR + ident + '.json', 'w'), sort_keys=True, indent=4)
print("In Datei %s geschrieben." % (LIBDIR + ident + '.json'))