-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroupA.py
277 lines (234 loc) · 11 KB
/
groupA.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Module: groupA
# Purpose: To get the group A match details
import ply.yacc as yacc
import ply.lex as lex
# lists to store the data
# to stote points of each team
stagelist = []
# to store match fixtures
matchlist = []
# to store match scorers
scorerlist = []
# to store match details (stadium, attendence, referee)
matchdetails = []
tokens=[
'BEGINSTAGEA', 'BEGINSTAGEB', 'OPENMATCHDIV',
'OPENPOINTTABLE', 'CLOSEPOINTTABLE', 'OPENTABLE', 'OPENLIST', 'CLOSELIST', 'OPENROW', 'CLOSEROW', 'OPENDATA', 'CLOSEDATA', 'OPENHEADER', 'CLOSEHEADER', 'OPENHREF', 'CLOSEHREF', 'SEPARATOR',
'CONTENT', 'GARBAGE', 'OPENLINK', 'OPENABBR', 'CLOSEABBR', 'FRIGHTDIV'
]
def t_BEGINSTAGEA(t):
'''<span\sclass="mw-headline"\sid="Group_A">Group\sA</span>'''
return t
def t_BEGINSTAGEB(t):
'''<span\sclass="mw-headline"\sid="Group_B">Group\sB</span>'''
return t
def t_OPENPOINTTABLE(t):
'''<table\sclass="wikitable"\sstyle="text-align:center;">'''
return t
def t_OPENTABLE(t):
'''<table\sclass="fevent">'''
return t
def t_CLOSEPOINTTABLE(t):
'''</table>'''
return t
def t_OPENMATCHDIV(t):
'''<div\sitemscope=""\sitemtype="http&\#58;//schema.org/SportsEvent"\sclass="footballbox">'''
return t
def t_FRIGHTDIV(t):
'''<div\sclass="fright">'''
return t
def t_SEPARATOR(t):
'''<link\srel="mw-deduplicated-inline-style"\shref="mw-data:TemplateStyles:r997937747"/>'''
return t
def t_OPENROW(t):
r'<tr.*?>'
return t
def t_CLOSEROW(t):
r'</tr>'
return t
def t_OPENDATA(t):
r'<td.*?>'
return t
def t_CLOSEDATA(t):
r'</td>'
return t
def t_OPENLINK(t):
r'<link.*?>'
def t_OPENABBR(t):
r'<abbr.*?>'
def t_CLOSEABBR(t):
r'</abbr>'
def t_OPENLIST(t):
r'<li .*?>'
return t
def t_CLOSELIST(t):
r'</li>'
return t
def t_OPENHREF(t):
r'<a .*?>'
return t
def t_CLOSEHREF(t):
r'</a>'
return t
def t_OPENHEADER(t):
r'<th.*?>'
return t
def t_CLOSEHEADER(t):
r'</th>'
return t
def t_CONTENT(t):
r'[A-Za-z0-9ñáćéíøäæóúÁÉÜÚÑÓÍïüšëčýÿû,$#§&.:;@ \'")\(–]+'
return t
def t_GARBAGE(t):
r'<.*?>'
def t_error(t):
t.lexer.skip(1)
# grammar to final stage A heading
def p_start(p):
'''start : before BEGINSTAGEA skip OPENPOINTTABLE handletable CLOSEPOINTTABLE skip OPENMATCHDIV handlematches BEGINSTAGEB'''
# grammar to handle each row of pointtable
def p_handletable(p):
'''handletable : OPENROW handlerow CLOSEROW handletable
| '''
# grammar to handle point table columns and store it
def p_handlerow(p):
'''handlerow : OPENHEADER skip CLOSEHEADER OPENHEADER skip OPENLIST skip CLOSELIST OPENLIST skip CLOSELIST OPENLIST skip CLOSELIST CLOSEHEADER OPENHEADER skip CLOSEHEADER OPENHEADER skip CLOSEHEADER OPENHEADER skip CLOSEHEADER OPENHEADER skip CLOSEHEADER OPENHEADER skip CLOSEHEADER OPENHEADER skip CLOSEHEADER OPENHEADER skip CLOSEHEADER OPENHEADER skip CLOSEHEADER OPENHEADER skip CLOSEHEADER handlerow
| OPENDATA skip CLOSEDATA OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CLOSEHEADER OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA handlerow
| OPENDATA skip CLOSEDATA OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CLOSEHEADER OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA skip CLOSEDATA handlerow
| OPENDATA skip CLOSEDATA OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CONTENT CONTENT CLOSEHEADER OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA handlerow
| '''
if len(p)==35:
stagelist.append(p[7]+" "+p[23]+" "+p[26])
elif len(p)==38:
stagelist.append(p[7]+" "+p[23]+" "+p[26])
elif len(p)==37:
stagelist.append(p[7]+" "+p[13]+" " +p[25])
# grammar to handle match details one by one and store it
def p_handlematches(p):
'''handlematches : skip OPENTABLE OPENROW OPENHEADER OPENHREF CONTENT CLOSEHREF CONTENT CLOSEHEADER OPENHEADER OPENHREF CONTENT CLOSEHREF CLOSEHEADER OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CLOSEHEADER CLOSEROW OPENROW OPENDATA handlescorer CLOSEDATA OPENDATA skip CLOSEDATA OPENDATA handlescorer CLOSEDATA CLOSEROW CLOSEPOINTTABLE FRIGHTDIV handledetails SEPARATOR handlematches
| OPENMATCHDIV skip OPENTABLE OPENROW OPENHEADER OPENHREF CONTENT CLOSEHREF CONTENT CLOSEHEADER OPENHEADER OPENHREF CONTENT CLOSEHREF CLOSEHEADER OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CLOSEHEADER CLOSEROW OPENROW OPENDATA handlescorer CLOSEDATA OPENDATA skip CLOSEDATA OPENDATA handlescorer CLOSEDATA CLOSEROW CLOSEPOINTTABLE FRIGHTDIV handledetails SEPARATOR handlematches
| OPENMATCHDIV skip OPENTABLE OPENROW OPENHEADER OPENHREF CONTENT CLOSEHREF CONTENT CLOSEHEADER OPENHEADER OPENHREF CONTENT CLOSEHREF CLOSEHEADER OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CLOSEHEADER CLOSEROW OPENROW OPENDATA handlescorer CLOSEDATA OPENDATA skip CLOSEDATA OPENDATA handlescorer CLOSEDATA CLOSEROW CLOSEPOINTTABLE FRIGHTDIV handledetails
| '''
if len(p)>1:
matchlist.append(p[7]+" "+p[13]+" "+p[19])
# grammar to handle scorer details and store it
def p_handlescorer(p):
'''handlescorer : skip OPENLIST OPENHREF CONTENT CLOSEHREF skip CLOSELIST handlescorer
| '''
if len(p)>1:
scorerlist.append(p[4])
# grammar to handle stadium details and store it
def p_handledetails(p):
'''handledetails : OPENHREF CONTENT CLOSEHREF CONTENT OPENHREF CONTENT CLOSEHREF CONTENT CONTENT OPENHREF CONTENT CLOSEHREF skip'''
matchdetails.append(p[2]+" "+p[4]+" "+p[6]+" "+p[8]+" "+p[9]+" "+p[11])
# def p_handledata(p):
# '''handledata : OPENDATA skip CLOSEDATA OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CLOSEHEADER OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA handledata
# | OPENDATA skip CLOSEDATA OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CLOSEHEADER OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA skip CLOSEDATA handledata
# | OPENDATA skip CLOSEDATA OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CONTENT CONTENT CLOSEHEADER OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA OPENDATA CONTENT CLOSEDATA handledata
# | '''
# if len(p) == 35:
# print(p[7], p[11], p[14], p[17], p[20], p[23], p[26], p[29], p[32])
# elif len(p) == 38:
# print(p[7], p[11], p[14], p[17], p[20], p[23], p[26], p[29], p[32])
# elif len(p) == 37:
# print(p[7], p[13], p[16], p[19], p[22], p[25], p[28], p[31],p[34])
# def p_handlehead(p):
# '''handlehead : OPENHEADER skip CLOSEHEADER handlehead
# | OPENHEADER skip OPENLIST skip CLOSELIST OPENLIST skip CLOSELIST OPENLIST skip CLOSELIST CLOSEHEADER handlehead
# | '''
# def p_handlematches(p):
# '''handlematches : OPENMATCHDIV skip OPENTABLE handlescores CLOSEPOINTTABLE FRIGHTDIV OPENHREF CONTENT CLOSEHREF CONTENT OPENHREF CONTENT CLOSEHREF CONTENT CONTENT OPENHREF CONTENT CLOSEHREF skip SEPARATOR handlematches
# | '''
# if len(p) > 1:
# print(p[8],p[10],p[12],p[14],p[15],p[17])
# # OPENHREF CONTENT CLOSEHREF CONTENT OPENHREF CONTENT CLOSEHREF CONTENT CONTENT OPENHREF CONTENT CLOSEHREF
# def p_handlescores(p):
# '''handlescores : OPENROW OPENHEADER OPENHREF CONTENT CLOSEHREF skip CLOSEHEADER OPENHEADER OPENHREF CONTENT CLOSEHREF CLOSEHEADER OPENHEADER CONTENT OPENHREF CONTENT CLOSEHREF CLOSEHEADER CLOSEROW handlescores
# | OPENROW OPENDATA handlelist CLOSEDATA OPENDATA skip CLOSEDATA OPENDATA handlelist CLOSEDATA CLOSEROW'''
# if len(p) > 12:
# print(p[4],p[10],p[16])
# def p_handlelist(p):
# '''handlelist : skip OPENLIST OPENHREF CONTENT CLOSEHREF skip CLOSELIST handlelist
# | '''
# if len(p) > 1:
# print(p[4])
def p_before(p):
'''before : CONTENT before
| OPENHREF before
| CLOSEHREF before
| OPENHEADER before
| CLOSEHEADER before
| OPENDATA before
| CLOSEDATA before
| OPENROW before
| CLOSEROW before
| OPENLIST before
| CLOSELIST before
| OPENTABLE before
| OPENLINK before
| CLOSEPOINTTABLE before
| '''
def p_skip(p):
'''skip : CONTENT skip
| OPENHREF skip
| CLOSEHREF skip
| '''
def p_error(p):
# print('Error at line ', p)
pass
def groupA():
global stagelist
global matchlist
global scorerlist
global matchdetails
stagelist = []
matchlist = []
scorerlist = []
matchdetails = []
lexer = lex.lex()
parser = yacc.yacc()
f=open('fifa.html','r',encoding='utf-8')
data = f.read()
lexer.input(data)
res = parser.parse(data)
matchlist.reverse()
matchlist[0]='Qatar 0-2 Equador'
# formatting the data for better and generalized access in the future
groupAdata = {
'pointtable' : stagelist,
'matchlist' : matchlist,
'matches' : {
'1': {
'score' : matchlist[0],
'details' : matchdetails[0],
'scorers' : [scorerlist[0]]
},
'2': {
'score' : matchlist[1],
'details' : matchdetails[1],
'scorers' : [scorerlist[1],scorerlist[2]]
},
'3': {
'score' : matchlist[2],
'details' : matchdetails[2],
'scorers' : [scorerlist[3],scorerlist[4],scorerlist[5],scorerlist[6]]
},
'4': {
'score' : matchlist[3],
'details' : matchdetails[3],
'scorers' : [scorerlist[7],scorerlist[8]]
},
'5': {
'score' : matchlist[4],
'details' : matchdetails[4],
'scorers' : [scorerlist[9],scorerlist[10],scorerlist[11]]
},
'6': {
'score' : matchlist[5],
'details' : matchdetails[5],
'scorers' : [scorerlist[12],scorerlist[13]]
}
}
}
f.close()
return groupAdata