No offense to the title, but I thought the AD was fun and the mind map above is yours to take, because I can’t learn that much anyway

The article directories

    • preface
      • Welcome to our circle
    • Showdown, the Stealthy Python series is about to enter a long XXX
    • Python pangolin (Part 1) : Translation software
    • The design

preface

Previous Review: I will Learn Python secretly (Day 13)

Another great article.

Interrupt a push :(if you are small white, you can take a look at the following paragraph)

Welcome to our circle

I created a Python learning q & A group, interested friends can know: what is this group

There are more than 1000 friends in the group!!

Portal of the Straight group: Portal


This series of articles assumes that you have some basic knowledge of C or C++, because I started Python after learning a little C++. Thank you qi Feng for your support. This series of articles by default you will baidu, learning 'module' this module, or suggest that you have your own editor and compiler, the last article has given you to do the recommendation? I don't want much, just click on it. And then, the catalogue for this series, to be honest, MY preference is for the two Primer Plus books, so I'll stick with their catalogue structure. This series will also focus on cultivating your ability to do things on your own. After all, I cannot tell you all the knowledge points, so the ability to solve your needs by yourself is particularly important. Therefore, please do not regard the holes I have buried in the article as holes.Copy the code

Showdown, the Stealthy Python series is about to enter a long XXX

The long days of Reptilian Wars.

Yes, there will be lots of small projects coming up, some of which will be economical, some of which will be purely fun.

Of course, I will not write all the fun small projects, but I will make a highly scalable project, the interface is clear, if you want to expand.

Python pangolin (Part 1) : Translation software

Why would I want to do this? Fun bai, I paid attention to a few “reptilian hundred battles” column, first picked this to do, but they are mostly can only translate a word, that I will ah, boring.

Under my unremitting efforts, I climbed and climbed, climbed and climbed, finally climbed to a big guy, he put the encryption algorithm to crack.

Here’s the thing: why do most blogs only offer single-word translations? Because they can’t provide multiple word translations, and the definition of the word they can catch is limited, anyway, let’s put the picture here, I feel that it is not clear without the picture today:

Well, they are all using this incomplete package called SUG, I just started on Baidu translation can also catch such a package, but youdao can not brush out.

In fact, you should use the package of the first one in this picture, but that package is encrypted, in Baidu Translation, you need to bring cookies, and two secret keys, for the moment the secret keys, because these things are changed with the word, so if each is to capture the package, unpack, it is not meaningful.

At that time, there was a big discovered the rule, so he was a fierce operations such as tiger, shout: blog.csdn.net/nunchakushu…

Great. Cracked it.

And then there’s what we’re going to do.

The following code is completed by my partner Siqi and ME in our group. I gave him the modified algorithm and he equipped with UI.

import urllib.request
import requests
import urllib.parse
import json
import time
import random
import hashlib
import tkinter
from tkinter import ttk

text = ""

# Empty the input field
def qing_kong(shu_ru) :
    shu_ru.delete(0, tkinter.END)

Make sure to start the query
def que_ding(a, b, content, shu_chu) :
    global text
    # content = input(' Please input what you want translated: ')
    # from_s = input(" input language ", "EN:", "EN: ")
    # to_s = input(" please input the target language, Chinese please enter EN, English please enter EN: ")
    if a == "Chinese":
        from_s = 'ZH'
    else:
        from_s = 'EN'
    if a == "English":
        to_s = 'EN'
    else:
        to_s = 'ZH'

    # url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom=https://www.google.com/'
    url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
    data = {}

    u = 'fanyideskweb'
    d = content
    f = str(int(time.time() * 1000) + random.randint(1.10))
    c = 'rY0D^0\'nM0}g5Mm1z%1G4'

    sign = hashlib.md5((u + d + f + c).encode('utf-8')).hexdigest()

    data['i'] = content
    data['from'] = from_s
    data['to'] = to_s
    data['smartresult'] = 'dict'
    data['client'] = 'fanyideskweb'
    data['salt'] = f
    data['sign'] = sign
    data['doctype'] = 'json'
    data['version'] = '2.1'
    data['keyfrom'] = 'fanyi.web'
    data['action'] = 'FY_BY_CL1CKBUTTON'
    data['typoResult'] = 'true'

    data = urllib.parse.urlencode(data).encode('utf-8')

    res = requests.post(url, data=data)
    request = urllib.request.Request(url=url, data=data, method='POST')
    response = urllib.request.urlopen(request)

    # print(response.read().decode('utf-8'))
    pre_js = response.read().decode('utf-8')

    # pat=re.compile(r'[\u4e00-\u9fa5]+')
    # result=pat.findall(pre_js)
    # result = '\n'.join(result[5:])

    a = pre_js.split('[[')
    b = a[1].split(']] ')
    c = b[0]

    j = json.loads(c)
    text = j['tgt']
    shu_chu.set(text)
    print(j['tgt'])
    # for i in result:
    # print(i+'\n')
    # print(pre_js)


# main function
def jie_main() :
    global text
    win = tkinter.Tk()
    win.title("Translation")
    win.geometry("500x400")
    win.resizable(0.0)

    shu_chu = tkinter.StringVar()
    shu_chu.set(text)

    tkinter.Label(win, text='translation', font=('Arial'.12)).place(x=100, y=30, anchor='nw')

    tkinter.Label(win, text='Translation Language Options', font=('Arial'.12)).place(x=10, y=70, anchor='nw')
    yu_yan1 = ttk.Combobox(win, width=10)
    yu_yan1['value'] = ('Chinese'.'English')
    yu_yan1.current(0)
    yu_yan1.place(x=120, y=70, anchor='nw')
    tkinter.Label(win, text='", font=('Arial'.12)).place(x=220, y=70, anchor='nw')
    yu_yan2 = ttk.Combobox(win, width=10)
    yu_yan2['value'] = ('English'.'Chinese')
    yu_yan2.current(0)
    yu_yan2.place(x=270, y=70, anchor='nw')

    tx1 = tkinter.Label(win, text='Original:', font=('Arial'.12))
    tx1.place(x=10, y=120, anchor='nw')
    shu_ru = tkinter.Entry(win)
    shu_ru.place(x=120, y=120, anchor='nw')
    guess = shu_ru.get()

    tx2 = tkinter.Label(win, text='译文:', font=('Arial'.12))
    tx2.place(x=10, y=160, anchor='nw')
    tkinter.Label(win, textvariable=shu_chu, font=('Arial'.12)).place(x=100, y=160, anchor='nw')

    bt1 = tkinter.Button(win, text='empty', command=lambda: qing_kong(shu_ru))
    bt1.place(x=10, y=210, anchor='nw')
    bt2 = tkinter.Button(win, text='sure', command=lambda: que_ding(yu_yan1.get(), yu_yan2.get(), shu_ru.get(), shu_chu))
    bt2.place(x=100, y=210, anchor='nw')

    win.mainloop()


if __name__ == '__main__':
    jie_main()
Copy the code

The design

It feels like there’s nothing left to expand, except the language module. It must be that our friends have done it too well.

Let me tell you what I think, and make a long story short. If I don’t finish it, it won’t be reviewed until later.

Builder mode.

The scene class obtains all the language categories from the language category, and then fills them in the drop-down box of the UI class. The scene class is open, and the algorithm and UI are closed.

A bit hasty, UML didn’t even open… Forgive me.

If you have any questions, you can ask me directly, or you can ask me what is the Builder mode