Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- from googletrans import Translator
- translator = Translator()
- import os.path
- def transfunction(word):
- trans = translator.translate(word, src="en", dest="de")
- return trans.text
- def translation(conn):
- word_en = input("Your word?\n")
- word_de = transfunction(word_en)
- print("Means in german: ", word_de)
- conn.execute('''
- INSERT INTO words(en, de)
- VALUES (?, ?)
- ''',
- (word_en, word_de))
- conn.commit()
- def start():
- if os.path.exists("data.db") == False:
- conn = sqlite3.connect("data.db")
- conn.execute('''
- CREATE TABLE words (
- en TEXT NOT NULL,
- de TEXT NOT NULL )
- ''')
- conn.close()
- def showall(conn):
- cur = conn.cursor()
- cur.execute("SELECT * FROM words")
- rows = cur.fetchall()
- for row in rows:
- print(row)
- def main():
- start()
- conn = sqlite3.connect("data.db")
- while True:
- selection = input("\n What do you want to do: \n \
- 1. tranlate \n \
- 2. show all word\n \
- 3. close app \n \
- \n")
- if selection == "1":
- translation(conn)
- elif selection == "2":
- showall(conn)
- elif selection == "3":
- break
- conn.close()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement