-
Notifications
You must be signed in to change notification settings - Fork 9
/
setuphelp.py
46 lines (40 loc) · 1.19 KB
/
setuphelp.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
from cmd import Cmd
import json
from dev.main import Cfg, CfgLocation
from dev.core import scrape
class Main(Cmd):
def __init__(self):
super().__init__()
self.agencies = []
self.scraper = scrape.Scraper()
for k,v in self.scraper.agencies.items():
self.agencies.append(v["agencyname"])
with open("config.json", "r") as f:
self.cfg = json.loads(f.read())
def input(self, txt):
return input(str(txt) + ":\t")
def do_place(self):
name = self.input("Location name")
address = self.input("Address")
self.cfg['locations'].append({"name": name, "address": address})
print("Location added.")
self.save()
def do_agency(self, name):
thisname = name
for x in self.agencies:
if x.lower().startswith(name): thisname = x
self.cfg['agencies'].append({'name': thisname})
print(f"Agency {thisname} added.")
self.save()
def save(self):
with open("config.json", "w+") as f:
f.write(json.dumps(self.cfg, indent=4))
def complete_agency(self, text, line, begidx, endidx):
if not text:
return self.agencies[:]
else:
return [a for a in self.agencies if a.lower().startswith(text.lower)]
def do_EOF(self, line):
return True
if __name__ == "__main__":
Main().cmdloop()