-
Notifications
You must be signed in to change notification settings - Fork 0
/
retrieve_settings.py
56 lines (49 loc) · 1.79 KB
/
retrieve_settings.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
# This module retrieves the global game settings and parses them
import support_lib as bnw
import time
def getSettings(baseURL):
debug = True
# xpaths
# Key #1
# html/body/table[1]/tbody/tr[1]/td[1]
# Value #1
# html/body/table[1]/tbody/tr[1]/td[2]
# Key #2
# html/body/table[1]/tbody/tr[2]/td[1]
# Value #2
# html/body/table[1]/tbody/tr[2]/td[2]
# ...
# Key # 27
# html/body/table[1]/tbody/tr[27]/td[1]
# Value # 27
# html/body/table[1]/tbody/tr[27]/td[2]
xBanner = "html/body/h1[3]"
settingsPage = "http://{}/settings.php".format(baseURL)
bnw.loadPage(settingsPage)
time.sleep(2)
bannerText = bnw.textFromElement(xBanner)
if bannerText == "DONTEXIST":
print("Unable to load the game global settings page")
exit(1)
elif not bannerText == "Game Settings":
print("Unexpected banner text: {}, was looking for 'Game Settings'".format(bannerText))
exit(1)
if debug:
print("Game Settings page successfully loaded")
gameSettings = {}
for settingNumber in range(1, 28):
keyXpath = "html/body/table[1]/tbody/tr[{}]/td[1]".format(settingNumber)
valueXpath = "html/body/table[1]/tbody/tr[{}]/td[2]".format(settingNumber)
keyText = bnw.textFromElement(keyXpath)
valueText = bnw.textFromElement(valueXpath)
keyText = keyText.strip()
valueText = valueText.strip()
if keyText == "DONTEXIST" or valueText == "DONTEXIST":
print("Unable to retrieve the key value for settings #{}".format(settingNumber))
exit(1)
# remove commas from numbers
valueText = valueText.replace(',', '')
gameSettings[keyText] = valueText
if debug:
print("DONE Parsing the settings page")
return gameSettings