Project

General

Profile

Paste
Download (1013 Bytes) Statistics
| Branch: | Revision:

root / scripts_divers / migrer_taches_vers_redmine / submiters_parser.py @ 565596d9

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
    p.feed(output)
38

    
39
    #le premier est celui qui a créé la tache et le dernier est potentiellement celui qui n’a pas encore posté de commentaires
40
    return p.data