kindle manager
This commit is contained in:
50
tfile/tparseamazon.py
Normal file
50
tfile/tparseamazon.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#########################################################
|
||||
## @file : tparseamazon.py
|
||||
## @desc : test parse amazon response
|
||||
## @create : 2020/05/26
|
||||
## @author : Chengan
|
||||
## @email : douboer@gmail.com
|
||||
#########################################################
|
||||
|
||||
import re
|
||||
import json
|
||||
|
||||
s =['''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">丹·琼斯(Dan Jones)</span><span class="a-size-base" dir="auto">, </span><span class="a-size-base" dir="auto">杰弗里·瓦夫罗(Geoffrey Wawro)</span><span class="a-size-base" dir="auto">, </span><span class="a-size-base" dir="auto">克里斯托弗·希伯特(Christopher Hibbert)</span><span class="a-size-base" dir="auto">, </span><span class="a-size-base" dir="auto">罗斯·金(Ross King)</span><span class="a-size-base" dir="auto">等等。</span></div>''',
|
||||
'''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">马克·哈里斯</span><span class="a-size-base" dir="auto">、 </span><span class="a-size-base" dir="auto">黎绮妮</span></div>''',
|
||||
'''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">马克·哈里斯</span><span class="a-size-base" dir="auto">、 </span><span class="a-size-base" dir="auto">黎绮妮</span></div>''',
|
||||
'''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">[美]威廉·厄本(William Urban)</span><span class="a-size-base" dir="auto">, </span><span class="a-size-base" dir="auto">陆大鹏</span><span class="a-size-base" dir="auto">、 </span><span class="a-size-base" dir="auto">刘晓晖</span></div>''',
|
||||
'''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">[英]安德鲁·罗伯茨(Andrew Roberts)</span><span class="a-size-base" dir="auto">、 </span><span class="a-size-base" dir="auto">苏然</span></div>''',
|
||||
'''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">[英]安德鲁·罗伯茨(Andrew Roberts)</span><span class="a-size-base" dir="auto">、 </span><span class="a-size-base" dir="auto">苏然</span></div>''',
|
||||
'''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">堀田江理(Eri Hotta)</span></div>''',
|
||||
'''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">景跃进</span><span class="a-size-base" dir="auto">, </span><span class="a-size-base" dir="auto">张小劲</span><span class="a-size-base" dir="auto">、 </span><span class="a-size-base" dir="auto">余逊达</span></div>''']
|
||||
|
||||
tre = ['''<div data-asin="B07S46LMCK" data-index="3" data-uuid="ef76dd52-2ab2-4372-8597-2c3258698b6e" data-component-type="s-search-result" class="sg-col-20-of-24 s-result-item s-asin sg-col-0-of-12 sg-col-28-of-32 sg-col-16-of-20 sg-col sg-col-32-of-36 sg-col-12-of-16 sg-col-24-of-28"><div class="sg-col-inner">''',
|
||||
'''<img src="https://images-cn.ssl-images-amazon.com/images/I/41JFUwuJPCL._AC_UY218_.jpg"''',
|
||||
'''alt="小窗幽记(国学大书院)(为人处世的智慧之果 修身齐家的行动指南)"''',
|
||||
'''<div class="a-row a-size-base a-color-secondary"><span class="a-size-base" dir="auto"></span><span class="a-size-base" dir="auto">野田洋次郎</span><span class="a-size-base" dir="auto">、 </span><span class="a-size-base" dir="auto">蒋青青</span></div>''',
|
||||
'''<span aria-label="4.7 颗星,最多 5 颗星">''',
|
||||
'''<span class="a-letter-space"></span></div></div>''']
|
||||
|
||||
|
||||
for t in s:
|
||||
ret = re.split('<span.+?auto\">|<\/span',t)
|
||||
fret = ret[3::4]
|
||||
#print(json.dumps(re.split('<span.+?auto\">|<\/span',t), indent=2, ensure_ascii=False))
|
||||
print(','.join(fret))
|
||||
|
||||
re_asin = re.compile(r'''^<div data-asin=\"(.+?)\" data-index''')
|
||||
re_img = re.compile(r'''^<img src=\"(.+?)\"$''')
|
||||
re_bn = re.compile(r'''^alt=\"(.+?)\"$''')
|
||||
re_author = re.compile(r'''^<div class=.+auto\"><\/span>.+$''')
|
||||
re_rate = re.compile(r'''^<span aria-label=\"(.+?)\">$''')
|
||||
#re_end = re.compile(r'''<\/body><\/html>''')
|
||||
re_end = re.compile(r'''^<span class=\"a-letter-space\"><\/span><\/div><\/div>''')
|
||||
|
||||
print(re.search(re_asin, tre[0]).group(1))
|
||||
print(re.search(re_img , tre[1]).group(1))
|
||||
print(re.search(re_bn , tre[2]).group(1))
|
||||
print(re.search(re_author,tre[3]).group(0))
|
||||
print(re.search(re_rate, tre[4]).group(1))
|
||||
print(re.search(re_end , tre[5]).group(0))
|
||||
|
||||
|
||||
37
tfile/tsqllite.py
Normal file
37
tfile/tsqllite.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#########################################################
|
||||
## @file : tsqlite.py
|
||||
## @desc : test sqlite3
|
||||
## @create : 2020/06/11
|
||||
## @author : Chengan
|
||||
## @email : douboer@gmail.com
|
||||
#########################################################
|
||||
|
||||
|
||||
import sqlite3
|
||||
|
||||
dbname = 'vocab.db'
|
||||
conn = sqlite3.connect(dbname)
|
||||
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
sql1 = '''select * from words;'''
|
||||
sql2 = '''select * from lookups;'''
|
||||
|
||||
# fetch one record
|
||||
cursor.execute(sql2)
|
||||
one=cursor.fetchone()
|
||||
print(one)
|
||||
|
||||
# fetch all records
|
||||
for row in cursor.fetchall():
|
||||
print(row)
|
||||
|
||||
# fetch table structure
|
||||
|
||||
except Exception as e:
|
||||
print('sql failure {}'.format(e))
|
||||
pass
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
88
tfile/ttranslator.py
Normal file
88
tfile/ttranslator.py
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
# from webside not test, only for reference XXX
|
||||
|
||||
#coding=utf8
|
||||
import random
|
||||
import requests
|
||||
import hashlib
|
||||
appid = 'xxxxxx'
|
||||
secretKey = 'xxxxx'
|
||||
def get_md5(string):#返回字符串md5加密
|
||||
hl = hashlib.md5()
|
||||
hl.update(string.encode('utf-8'))
|
||||
return hl.hexdigest()
|
||||
|
||||
def en_to_zh(en_str):#英语翻译成中文
|
||||
api_url = 'http://api.fanyi.baidu.com/api/trans/vip/translate'
|
||||
salt = random.randint(32768,65536)
|
||||
sign = get_md5(appid + en_str + str(salt) + secretKey)
|
||||
api_data = {
|
||||
'q':en_str,
|
||||
'from':'en',
|
||||
'to':'zh',
|
||||
'appid':appid,
|
||||
'salt':salt,
|
||||
'sign':sign
|
||||
}
|
||||
req_get = requests.get(api_url,api_data)
|
||||
result = req_get.json()
|
||||
print(result)
|
||||
return result['trans_result']
|
||||
|
||||
print(en_to_zh('test'))
|
||||
|
||||
'''
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
import json
|
||||
from tkinter import *
|
||||
root=Tk()
|
||||
root.title("翻译小程序")
|
||||
sw = root.winfo_screenwidth()
|
||||
#得到屏幕宽度
|
||||
sh = root.winfo_screenheight()
|
||||
#得到屏幕高度
|
||||
ww = 500
|
||||
wh = 300
|
||||
x = (sw-ww) / 2
|
||||
y = (sh-wh) / 2-50
|
||||
root.geometry("%dx%d+%d+%d" %(ww,wh,x,y))
|
||||
lb2=Label(root,text="输入英文翻译中文,或者输入中文翻译英文,按回车键翻译。--版权所有,翻录必究。")
|
||||
lb2.place(relx=0, rely=0.05)
|
||||
txt = Text(root,font=("宋体",20))
|
||||
txt.place(rely=0.6, relheight=0.4,relwidth=1)
|
||||
inp1 = Entry(root,font=("",20))
|
||||
inp1.place(relx=0, rely=0.2, relwidth=1, relheight=0.25)
|
||||
def run2(event):
|
||||
txt.delete("0.0",END)
|
||||
a = (inp1.get())
|
||||
content = a
|
||||
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
|
||||
data={}
|
||||
data['i'] = content
|
||||
data['from'] = 'AUTO'
|
||||
data['to'] = 'AUTO'
|
||||
data['smartresult'] = 'dict'
|
||||
data['client'] = 'fanyideskweb'
|
||||
data['salt'] = '15812376682056'
|
||||
data['sign'] = 'a1246b257926af8432be022564ff79f5'
|
||||
data['ts'] = '1581237668205'
|
||||
data['bv'] = '656f750600466990f874a839d9f5ad23'
|
||||
data['doctype'] = 'json'
|
||||
data['version'] = '2.1'
|
||||
data['keyfrom'] = 'fanyi.web'
|
||||
data['action'] = 'FY_BY_CLICKBUTTION'
|
||||
data = urllib.parse.urlencode(data).encode('utf-8')
|
||||
response = urllib.request.urlopen(url,data)
|
||||
html = response.read().decode('utf-8')
|
||||
target = json.loads(html)
|
||||
s=("%s"%(target['translateResult'][0][0]['tgt'])+"\n")
|
||||
print(s)
|
||||
txt.insert(END, s)
|
||||
def button1(event):
|
||||
btn1 = Button(root, text='结果如下', font=("",12))
|
||||
btn1.place(relx=0.35, rely=0.45, relwidth=0.2, relheight=0.15)
|
||||
inp1.bind("<Return>",run2)
|
||||
button1(1)
|
||||
root.mainloop()
|
||||
'''
|
||||
Reference in New Issue
Block a user