-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparse.py
55 lines (44 loc) · 1.72 KB
/
parse.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
import re
import settings
class Good:
def __init__(self, id, text, swf, pic):
self.id = id
self.text = text.replace("\"", "")
self.swf = swf
self.pic = pic
def parse(resource_file, goods_file):
goods = []
item = re.compile('g\[(.*)\] = {Id:(.*)};')
resOpen = open(settings.goods_file, "r+")
resRead = resOpen.read()
resOpen.close()
mrOpen = open(settings.resources_file, encoding="utf8")
mrRead = mrOpen.read()
mrOpen.close()
resStrings = resRead.split("\n")
for strs in resStrings:
text = "Без названия"
swf = ""
pic = ""
if "g[" in strs:
dwnlfile = re.findall(item, strs)
damn = dwnlfile[0][1].split(",")
_id = dwnlfile[0][0]
if 'TRId:' in dwnlfile[0][1]:
resTr = re.compile('tr\['+damn[2].replace("TRId:", "")+'\] = {H:(.*)};')
dwnlfile1 = re.findall(resTr, mrRead)
if (len(dwnlfile1) != 0):
text = dwnlfile1[0]
if 'MRId:' in dwnlfile[0][1]:
resMr = re.compile('mr\[-'+damn[1].replace("MRId:", "")+'\] = {TId:(.*),Url:"(.*)",V:(.*)};')
dwnlfile2 = re.findall(resMr, mrRead)
if (len(dwnlfile2) != 0):
pic = "http://sharaball.ru/fs/" + dwnlfile2[0][1]
if 'MRId:' in dwnlfile[0][1]:
resMr = re.compile('mr\['+damn[1].replace("MRId:", "")+'\] = {TId:(.*),Url:"(.*)",V:(.*)};')
dwnlfile2 = re.findall(resMr, mrRead)
if (len(dwnlfile2) != 0):
swf = dwnlfile2[0][1]
g = Good(_id, text, swf, pic)
goods.append(g)
return goods