Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
    def add_fa(self, newfa):
        try:

            self.fa = self.fa + ',' + convertep(newfa)

            db.execute('update words set fa="%s" ,mode="True" where num=%i' %
                       (convertpe(self.fa), self.num))
            sql.commit()
            self.fa = convertep(self.fa)
            return True
        except:
            return False
Ejemplo n.º 3
0
    def words_fa(q):

        if q == None:
            return None

        db.execute('select num from words where fa="%s"' % convertpe(q))

        try:
            al = db.fetchall()[0]
        except Exception as e:
            return None

        return wdic[al[0]]
Ejemplo n.º 4
0
def massages ():

   try:
      messages = bot1.get_messages()
      for msg in messages: 

         msg ['body'] = convertpe (msg ['body'])
         print ("(receive)   %s: %s "  %(user.get_id(msg['from']),msg['body']))
         
         yield (msg)

   except Exception as e:
      print(e.args[0])
Ejemplo n.º 5
0
    def edit(self, newfa):
        try:
            self.fa = convertep(newfa)

            eeee = ''
            for q in self.fa.split(','):
                eeee += "%s," % q.strip()
            self.fa = eeee[:-1]

            db.execute('update words set fa="%s" ,mode="True" where num=%i' %
                       (convertpe(newfa), self.num))
            sql.commit()
            return True
        except:
            return False
Ejemplo n.º 6
0
def massages():

    try:
        messages = bot1.get_messages()
        for msg in messages:
            #print (msg)

            print('\n' + gname(msg['from']) + ' :')
            print(rrese(msg['body']))
            msg['body'] = convertpe(msg['body'])
            signrun()

            yield (msg)

    except Exception as e:
        print(e.args[0])
Ejemplo n.º 7
0
    def add_fa(self, newfa):
        try:

            self.fa = self.fa + ',' + convertep(newfa)

            eeee = ''
            for q in self.fa.split(','):
                eeee += ',%s' % q.strip()
            self.fa = eeee[1:]

            db.execute('update words set fa="%s" ,mode="True" where num=%i' %
                       (convertpe(self.fa), self.num))
            sql.commit()
            self.fa = convertep(self.fa)
            return True
        except:
            return False
Ejemplo n.º 8
0
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()