<commit_before>from HTMLParser import HTMLParser

FOLDER_NAME = "Lately"

class MyHTMLParser(HTMLParser):
    a_text = False
    h3_text = False

    def __init__(self):
        HTMLParser.__init__(self)
        self.links = []
        self.start_deal = False
    def handle_starttag(self, tag, attrs):
        #print "Encountered the beginning of a %s tag" % tag
        if tag == "h3":
            self.h3_text = True
            self.a_text = False
        else:
            if tag == "a":
                self.a_text = True
                self.h3_text = False
                if len(attrs) == 0:
                    pass
                else:
                    for (variable, value) in attrs:
                        if variable == "href":
                            if self.start_deal:
                                self.address = value
            else:
                self.h3_text = False
                self.a_text = False
    def handle_data(self, data):
        if self.a_text:
            if data == "\r\n            ":
                pass
            else:
                if data == "\r\n        ":
                    self.start_deal = False
                if self.start_deal:
                    print("###" + " " + "[" + data + "]" + "(" + self.address + ")\n\n")
        if self.h3_text:
            if len(data) == 0:
                pass
            else:
                if data == FOLDER_NAME:
                    self.start_deal = True




if __name__ == "__main__":
    htmlFile = open("WeeklyReportDecoder/bookmarks.html", "r")
    html_code = htmlFile.read()
    hp = MyHTMLParser()
    hp.feed(html_code)
    hp.close()
    htmlFile.close()<commit_msg>[bugfix] 读取html文件路径错误。<commit_after>from HTMLParser import HTMLParser

FOLDER_NAME = "Lately"

class MyHTMLParser(HTMLParser):
    a_text = False
    h3_text = False

    def __init__(self):
        HTMLParser.__init__(self)
        self.links = []
        self.start_deal = False
    def handle_starttag(self, tag, attrs):
        #print "Encountered the beginning of a %s tag" % tag
        if tag == "h3":
            self.h3_text = True
            self.a_text = False
        else:
            if tag == "a":
                self.a_text = True
                self.h3_text = False
                if len(attrs) == 0:
                    pass
                else:
                    for (variable, value) in attrs:
                        if variable == "href":
                            if self.start_deal:
                                self.address = value
            else:
                self.h3_text = False
                self.a_text = False
    def handle_data(self, data):
        if self.a_text:
            if data == "\r\n            ":
                pass
            else:
                if data == "\r\n        ":
                    self.start_deal = False
                if self.start_deal:
                    print("###" + " " + "[" + data + "]" + "(" + self.address + ")\n\n")
        if self.h3_text:
            if len(data) == 0:
                pass
            else:
                if data == FOLDER_NAME:
                    self.start_deal = True




if __name__ == "__main__":
    htmlFile = open("bookmarks.html", "r")
    html_code = htmlFile.read()
    hp = MyHTMLParser()
    hp.feed(html_code)
    hp.close()
    htmlFile.close()
{'fraction_non_alphanumeric': 0.10520059435364042, 'fraction_numerical': 0.00475482912332838, 'mean_word_length': 1.1758241758241759, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6190234', 'n_tokens_mistral': 1016, 'n_tokens_neox': 957, 'n_words': 228}