"Original" Shadowebdict Development Diary: A Concise English-Chinese dictionary based on Linux (iv)

Source: Internet
Author: User

Full range of catalogs:
    • "Original" Shadowebdict Development Diary: A Concise English-Chinese dictionary based on Linux (i)
    • "Original" Shadowebdict Development Diary: A Concise English-Chinese dictionary based on Linux (II.)
    • "Original" Shadowebdict Development Diary: A Concise English-Chinese dictionary based on Linux (c)
    • "Original" Shadowebdict Development Diary: A Concise English-Chinese dictionary based on Linux (iv)
    • GitHub Address of the project

The internship work is so busy, really.

Finally have time to write some blog, Bang complete Forget

To undertake the above

This article completes the development of the local database module.

Because it is a very lightweight application, it does not bother MySQL, to a sqlite can be, local db file read.

Here we can implement one more function: Difficult word system.

Define a word that is difficult for a query to reach a threshold multiple times, and record the number of queries for all vocabularies in the local database.

When a word reaches this standard, it is added to the difficult word list in the local database and provides a way for other modules to query the difficult vocabulary.

It can be seen that the difficult word system determines the local data module this part and the response module, need to provide multiple modules for upper-level operation, including:

0. Provide an interface for querying difficult vocabularies.

1. Provide an interface to update the number of queries per word.

2. Provide an interface for inserting words.

3, like the response module, given a word, query its meaning of the interface.

The specific code is as follows:

#-*-Coding:utf-8-*-__author__ = ' wmydx ' Import sqlite3class localdict:def __init__ (self): Self.con = None        Self.limit = 4 Self.setup_connect () def setup_connect (self): Self.con = Sqlite3.connect ('./word.db ')            create_table = "' CREATE table IF not EXISTS words (word text, explain text,        Net_explain text, sentence text, times int); "' Self.con.execute (create_table) create_table =" "CREATE table IF not EXISTS hard (wor        D text, explain text, net_explain text, sentence text, times int);        "' Self.con.execute (create_table) self.con.text_factory = str def is_a_hard_word (self, diction): Print diction[' times '] = = self.limit return diction[' times '] = = self.limit # prevent mutiple insert, so use  = = instead of >= def update_word_times (self, diction):      Curs = Self.con.cursor () update_sql = "Update words SET times=?"        WHERE word=? "' Curs.execute (Update_sql, (diction[' Times '], diction[' word '])) def get_hard_word (self): Curs = Self.con        . cursor () Select_sql = "' Select Word from hard; "' Curs.execute (select_sql) names = [d[0] for D in curs.description] rows = [Dict (Zip (names, row)) F        or row in Curs.fetchall ()] return to Rows def get_eng_word_from_db (self, word): Curs = Self.con.cursor ()        Select_sql = "" SELECT * from words WHERE word=\ '%s\ '; "% word curs.execute (select_sql) names = [d[0] for D in curs.description] rows = [Dict (Zip (names,             Row))) for row in Curs.fetchall ()] return to Rows def process_dict (self, diction): for key in Diction.keys ():  If diction[key] = = -1:diction[key] = "return diction # before pass diction to this MetHod, u need to add word and times in diction def insert_word_to_db (self, diction, table): diction = self.process            _dict (diction) Insert_sql = "INSERT into%s (word,explain,net_explain,sentence,times) VALUES        (?,?,?,?,?);                                      "% table Self.con.execute (insert_sql, (diction[' word '], diction[' explain '),        diction[' Net_explain '], diction[' sentence '], diction[' Times ')) def turn_off_db (self): Self.con.commit () Self.con.close () if __name__ = = ' __main__ ': db = Localdict () db.setup_connect ()

To this end, we have developed a complete webdict, usually read the English version of the original, the quick command a dozen will be easy to find it

To avoid opening the browser and then ... =_+

"Original" Shadowebdict Development Diary: A Concise English-Chinese dictionary based on Linux (iv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.