def sync(): sql = connect(user=DBI.usr(), password=DBI.pas(), database=DBI.dbn()) db = sql.cursor() return sql, db
def sync(): try: sql.disconnect() except: pass sql = connect(user=DBI.usr(), password=DBI.pas(), database=DBI.dbn()) db = sql.cursor() return sql, db
def give_data(): sql = connect(user=DBI.usr(), password=DBI.pas(), database=DBI.dbn()) db = sql.cursor() db.execute('select * from words') words = db.fetchall() dword = dict() for q in words: dword[q[0]] = q[1] return dword
def get_words(self): sql = connect(user=DBI.usr(), password=DBI.pas(), database=DBI.dbn()) db = sql.cursor() db.execute('select tday from user where id="%s"' % self.id) m = db.fetchall()[0][0] if m == 'True': return True elif m == 'False': db.execute( 'select word1 ,word2 ,word3 ,word4 ,word5 from user where id="%s"' % self.id) return db.fetchall() elif m == 'False2': db.execute( 'select word1 ,word2 ,word3 ,word4 ,word5 ,word6 ,word7 ,word8 ,word9 ,word10 from user where id="%s"' % self.id) return db.fetchall()
def get_data(): from mysql.connector import connect from re import findall as find from bs4 import BeautifulSoup as bs from requests import get from time import sleep urls = [ "https://lang.b-amooz.com/en/vocabulary/subcategories/643/lesson-1", "https://lang.b-amooz.com/en/vocabulary/subcategories/1690/lesson-2" ] bd = lambda x: True if find('\d+', x) != [] and len(find( '\d+', x)) == 1 and find('\d+', x)[0] == str(x) else False num = 0 for url in urls: #page = webdriver.Chrome() page = get(url) #sleep (3) qq = page.text z = bs(qq, 'html.parser') x = z.findAll('li') r = [] b = 0 for q in x: ok = find(r'\w+\s{0,1}\w*', q.text) if len(ok) != 0 and bd(ok[0]): r.append(ok) yo = r[3:] y = [] for s0 in yo: if b < 6 or not (s0[0] in ['1', '2', '3', '4', '5']): po = "" for j in s0: if b_per(j): po += ' %s ' % j.strip() y.append((s0[1].strip(), convertpe(po.strip()))) b += 1 sql = connect(user=DBI.usr(), password=DBI.pas(), database=DBI.dbn()) mydb = sql.cursor() for en, fa in y: num += 1 mydb.execute( 'INSERT INTO words (en ,fa ,num ,mode) VALUES ("%s" ,"%s" ,%i ,"False") ' % (en, fa, num)) sql.commit()
from mysql.connector import connect from sys import path from library import convertep, convertpe, b_per from atoken import DBInformation as DBI sql = connect(user=DBI.usr(), password=DBI.pas(), database=DBI.dbn()) db = sql.cursor() wdic = dict() class word: def __init__(self, en, fa, num, mode): self.mode = mode self.en = en self.fa = fa self.num = num def edit(self, newfa): try: self.fa = newfa db.execute('update words set fa="%s" ,mode="True" where num=%i' % (convertpe(newfa), self.num)) sql.commit() return True except: return False def add_fa(self, newfa): try:
from sys import path from mysql.connector import connect from time import sleep , localtime from list import list_get as lget from core import send_message as osend from atoken import DBInformation as DBI sql = connect ( user = DBI.usr(), password = DBI.pas(). database = DBI.dbn() ) db = sql.cursor() inl = [] def gen (): while True : sleep (3) yield list(localtime() ) [3] def read_to_send (id):