root / scripts_divers / migrer_taches_vers_redmine / submiters_parser.py @ 8a509595
1 |
from html.parser import HTMLParser |
---|---|
2 |
|
3 |
class LinksParser(HTMLParser): |
4 |
def __init__(self): |
5 |
HTMLParser.__init__(self)
|
6 |
self.recording = 0 |
7 |
self.data = []
|
8 |
|
9 |
def handle_starttag(self, tag, attributes): |
10 |
if tag != 'a': |
11 |
return
|
12 |
if self.recording: |
13 |
self.recording += 1 |
14 |
return
|
15 |
for name, value in attributes: |
16 |
if name == 'class' and value == 'username': |
17 |
break
|
18 |
else:
|
19 |
return
|
20 |
self.recording = 1 |
21 |
|
22 |
def handle_endtag(self, tag): |
23 |
if tag == 'a' and self.recording: |
24 |
self.recording -= 1 |
25 |
|
26 |
def handle_data(self, data): |
27 |
if self.recording: |
28 |
self.data.append(data)
|
29 |
|
30 |
def parse_submiters(input): |
31 |
p = LinksParser() |
32 |
|
33 |
output = ""
|
34 |
|
35 |
for ligne in input: |
36 |
output += ligne |
37 |
print(output) |
38 |
p.feed(output) |
39 |
|
40 |
#le premier est celui qui a créé la tache et le dernier est potentiellement celui qui n’a pas encore posté de commentaires
|
41 |
return p.data
|