Skip to content

Commit 74b23b9

Browse files
authored
feat: add wubi.py
1 parent 9ee9845 commit 74b23b9

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

wubi.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# coding: utf-8
2+
import console
3+
import sys
4+
from markdown2 import markdown
5+
import ui
6+
import requests
7+
8+
TEMPLATE = '''
9+
<!doctype html>
10+
<html>
11+
<head>
12+
<meta charset="utf-8">
13+
<meta name="viewport" content="width=device-width">
14+
<title>Preview</title>
15+
<style type="text/css">
16+
body {
17+
font-family: helvetica;
18+
font-size: 15px;
19+
margin: 10px;
20+
}
21+
</style>
22+
</head>
23+
<body>{{CONTENT}}</body>
24+
</html>
25+
'''
26+
27+
def main():
28+
29+
search_word = console.input_alert(u'想查哪个字的编码?')
30+
if not search_word:
31+
print('No text input found.')
32+
sys.exit(0)
33+
34+
url = "https://www.iamwawa.cn/home/wubi/ajax"
35+
36+
headers = {
37+
'Origin': 'https://www.iamwawa.cn',
38+
'Referer': 'https://www.iamwawa.cn/wubi.html',
39+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36',
40+
}
41+
42+
payload = {"hanzi": search_word}
43+
44+
response = requests.post(url,headers=headers, data=payload)
45+
46+
res_dict = {}
47+
if response.status_code == 200:
48+
data = response.json()
49+
50+
if data['status'] == 1:
51+
res_dict = data['data'][0]
52+
53+
else:
54+
print(response.json())
55+
else:
56+
print('请求异常')
57+
print(response.json())
58+
sys.exit(1)
59+
60+
61+
text = "# {}\n - 98简码: {}\n - 98编码: {}\n - 拼音: {}\n\n![](https://iamwawa.cn/Data/wubi/{}.png)".format(search_word,res_dict["c98j"],res_dict["c98"],res_dict["py"],search_word)
62+
converted = markdown(text)
63+
html = TEMPLATE.replace('{{CONTENT}}', converted)
64+
webview = ui.WebView(name='98五笔编码查询')
65+
webview.load_html(html)
66+
webview.present()
67+
68+
if __name__ == '__main__':
69+
main()

0 commit comments

Comments
 (0)