-
Notifications
You must be signed in to change notification settings - Fork 0
/
mark-words.py
executable file
·56 lines (47 loc) · 1.33 KB
/
mark-words.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# import codecs
import time
import re
import random
from fake_useragent import UserAgent
from urllib.request import Request, urlopen
import urllib.parse
from bs4 import BeautifulSoup
# Local Vars
input_name = "male-count"
output_name = "male-finished"
dict_name = "edict2"
def soup(html):
soup = BeautifulSoup(html, 'html.parser')
ba = soup.find_all("div", id="inf")
# print(ba[0].text)
count = re.search(r'^.*約(.*)件', ba[0].text).group(1)
count = count.replace(',', '')
# print(count)
# print(soup.prettify())
return(count)
def prepare_dict():
edic = open(dict_name, 'r')
words = dict()
for line in edic:
word = re.search(r'^(.*?) .*$', line).group(1)
if word not in words:
words.update({word: None})
return(words)
if __name__ == "__main__":
input_file = open(input_name, 'r')
output = open(output_name, 'w')
words = prepare_dict()
count = 0
for line in input_file:
entry = re.search(r'^(.*?) .*$', line).group(1)
if entry in words.keys():
print(entry + " found in edict2")
count += 1
output.write(line[:-1] + " -- edict2\n")
else:
output.write(line)
pass
print(str(count) + " words in dict")
output.close()