-
Notifications
You must be signed in to change notification settings - Fork 1
/
scanner.py
125 lines (100 loc) · 4.06 KB
/
scanner.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
113
114
115
116
117
118
119
120
121
122
123
124
125
# Python 3.9
import requests
import mwparserfromhell
import pywikibot
import setup_families
import re
import json
import os
import errno
def Import():
site = pywikibot.Site("eft:en")
questPage = pywikibot.Page(site, u"Quests")
questText = questPage.text
hideoutPage = pywikibot.Page(site, u"Hideout")
hideoutText = hideoutPage.text
outputDir = os.path.dirname(os.path.abspath(__file__))+"/output"
questsOutput = outputDir + "/quest.json"
hideoutOutput = outputDir + "/hideout.json"
questItemList = []
hideoutItemList = []
# Create quest object
for line in questText.splitlines():
findInRaid = False
if ("raid" in line):
findInRaid = True
if ("Find " in line):
match = re.match(r".*\[\[(.*?)\]\].*", line)
if (match):
matchSplit = match.groups()[0] .split('|')
if (len(matchSplit) > 0):
# If the item already exists, make sure findInRaid is set if it should be for any of them
itemExists = False
for obj in questItemList:
if obj["name"] == matchSplit[0]:
itemExists = True
obj["count"] = obj["count"] + GetAmount(line)
if (item["raid"] or findInRaid):
item["raid"] = True
# Only add items once
if (not itemExists):
item = {}
item["wiki"] = "https://escapefromtarkov.gamepedia.com/" + matchSplit[0]
item["name"] = matchSplit[0]
item["count"] = GetAmount(line)
item["raid"] = findInRaid
questItemList.append(item)
# Create hideout object
for line in hideoutText.splitlines():
if (re.search(r"\*\s*\d+", line)):
match = re.match(r".*\[\[(.*?)\]\].*", line)
if (match):
matchSplit = match.groups()[0] .split('|')
if (len(matchSplit) > 0):
itemExists = False
for obj in hideoutItemList:
if obj["name"] == matchSplit[0]:
itemExists = True
obj["count"] = obj["count"] + GetAmount(line)
if not itemExists:
item = {}
item["wiki"] = "https://escapefromtarkov.gamepedia.com/" + matchSplit[0]
item["name"] = matchSplit[0]
item["count"] = GetAmount(line)
hideoutItemList.append(item)
# Create quest.json
if not os.path.exists(os.path.dirname(questsOutput)):
try:
os.makedirs(os.path.dirname(questsOutput))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
# Create hideout.json
if not os.path.exists(os.path.dirname(questsOutput)):
try:
os.makedirs(os.path.dirname(questsOutput))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
# Write quest.json
with open(questsOutput, "w", encoding="utf-8") as f:
json.dump(questItemList, f, ensure_ascii=False, indent=4)
# Write hideout.json
with open(hideoutOutput, "w", encoding="utf-8") as f:
json.dump(hideoutItemList, f, ensure_ascii=False, indent=4)
def GetAmount(line):
if ("key " in line.lower()):
return 1
match = re.match(r".*?([\d|\.]+)[\w|\s]*?\[", line)
if (not match):
match = re.match(r".*?([\d|\.]+)[\s]*pcs", line)
if (match):
number = match.groups()[0]
number = number.replace(".", "")
if (number.isdigit()):
return int(number)
else:
return 1
else:
return 1
Import()