Esempio n. 1
0
 def get_languages_message_count(language_to_search=None):
     languages = Texts.objects().only('language').distinct(
             'language') if language_to_search is None else Texts.objects(language=language_to_search).only(
             'language')
     count = {}
     for language in languages:
         count[language] = Texts.objects(language=language).count()
     return count
Esempio n. 2
0
 def save_values_to_db(self):
     try:
       transaction.begin()
       Texts.reset()
       for k,v in self.items.iteritems():
         dbsession = DBSession()
         texts = Texts(v['text'], v['color'], v['effect'], v['effect_time'])
         dbsession.add(texts)
       
       dbsession.commit()
       transaction.commit()
       return True
     except:
       return False
Esempio n. 3
0
def index(bot, update, args):
    if len(args) is 0:
        from models import Texts
        available_languages = Texts.objects().only('language').distinct('language')
        for language in available_languages:
            db.index_messages_by_language(language, True)
    else:
        language_chosen = args[0]
        logging.info(args)

        db.index_messages_by_language(language_chosen)
        bot.sendMessage(chat_id=update.message.chat_id, text="Messages indexed")
Esempio n. 4
0
    def insert_message(self, update):
        self.create_chat(update)
        self.create_user(update)

        msg = update.message
        new_message = Messages(
                date=msg.date,
                from_user=msg.from_user.id,
                from_chat=msg.chat_id,
                message_id=msg.message_id,
                update_id=update.update_id,
                number_of_words=len(msg.text.split()),
                language=detect(msg.text)
        )
        new_text = Texts(
                text=msg.text,
                date=msg.date,
                language=detect(msg.text)
        )
        new_text.save()
        new_message.save()
Esempio n. 5
0
    def create_wallet(self, bot_id):
        if request.form:
            not_for_all = False
            wallet = request.form['greet_msg']
            for key in request.form:
                try:
                    if key != 'greet_msg':
                        bot_id = request.form[key]
                        text = Texts.objects(bot_id=bot_id)
                        if str(text) != "[]":
                            for i in text:
                                if str(i) != "None":
                                    i.greet_msg = wallet
                                    i.save()
                        else:
                            Texts(greet_msg=wallet,
                                  bot_id=bot_id,
                                  back_btn=BACKBTN,
                                  use_buttons_msg=USEBUTTONS,
                                  choose_good_msg=CHOOSEGOOD,
                                  choose_city_msg=CHOOSESITY,
                                  choose_district_msg=CHOOSEDISTRICT,
                                  choose_payment_msg=CHOOSEPAYMENT,
                                  done_btn=DONE,
                                  leads_btn=LEADS,
                                  new_order_msg=NEWORDER,
                                  selected_good_msg=SELECTED,
                                  selected_good_msg2=SELECTED2).save()

                except Exception as e:
                    print(e)
                    not_for_all = True
                    flash('К боту ' + request.form[key] +
                          ' не удалось привязать greet msg')
            if not not_for_all:
                flash('Greet msg успешно привязано')

        return self.render('MyMsg.html',
                           bot_id=bot_id,
                           bots=BotProfile.objects())
Esempio n. 6
0
 def index_messages_by_language(language, indexed=False):
     texts_by_language = Texts.objects(language=language, indexed=indexed)
     message_2_index = ''
     for message in texts_by_language:
         message_2_index += "%s\n" % message.text
         message.update(indexed=True)
     try:
         os.makedirs('./messages')
     except OSError:
         pass
     with open('./messages/%s.txt' % language, 'a+') as messages_text:
         messages_text.write(message_2_index)
     return texts_by_language
Esempio n. 7
0
 def init_datastore(self):
   i = 0
   for item in Texts.get_items():
     d = {
             'text': str(item.text),
             'color': str(item.color),
             'effect': item.effects.effect,
             'effect_time': item.effect_time
         }
     self.items[i] = d
     i+=1
   
   options_obj = Options.get_options()
   self.options['timeon'] = options_obj.timeon
   self.options['timeoff'] = options_obj.timeoff
   self.options['speed'] = options_obj.speed
Esempio n. 8
0
def notify_admins(self, order):
    admins = User.objects(bot=order.user.bot, is_admin=True)
    texts = Texts.objects(bot_id=str(order.user.bot.id)).first()

    if not admins:
        return

    for admin in admins:
        if order.user.username:
            username = f'@{order.user.username}'
        else:
            username = '******'
        message_text = texts['new_order_msg'].format(
            order.user.user_id, order.user.first_name, order.user.last_name,
            username, order.city_name, order.district_name, order.good_name,
            order.payment_name, order.code)
        self._bot.send_message(admin.user_id,
                               message_text,
                               parse_mode='markdown')
Esempio n. 9
0
def send_leads_summary(self, user):
    texts = Texts.objects().first()
    l_texts = LeadTexts.objects().first()
    if not user.tax:
        user.tax = defaults.tax
    l_requests = LeadRequest.objects(user=user)
    total = len(l_requests)
    today = len(
        [r for r in l_requests if r.date.date() == datetime.today().date()])
    pending = len([r for r in l_requests if not r.approved])
    approved = len([r for r in l_requests if r.approved])
    self._bot.send_message(
        user.user_id,
        l_texts['summary_msg'].format(user.tax, total, today, pending,
                                      approved, user.balance),
        reply_markup=keyboards.set_leads_keyboard(texts,
                                                  l_texts,
                                                  withdraw_btn=user.balance
                                                  and user.wallet),
        parse_mode='markdown')
Esempio n. 10
0
    def create_dub(self, bot_id, bot_2):
        try:
            telebot.TeleBot(bot_2).get_me()
        except Exception:
            return 'ERROR, go back'
        bot_2 = loads(
            BotProfile.objects(token=bot_2).first().to_json())['_id']['$oid']

        text = Texts.objects(bot_id=bot_id).first()

        if not (text is None):
            text_dict = loads(text.to_json())

            dub_text = {}

            for key in text_dict:
                if key != '_id':
                    dub_text.update({key: text_dict[key]})

            dub_text['bot_id'] = bot_2

            new_text = Texts(**dub_text)
            new_text.save()

        cities = City.objects(bot_id=bot_id)

        if cities is not None:
            for city in cities:
                if not (city is None):
                    city_dict = loads(city.to_json())

                    dub_city = {}

                    for key in city_dict:
                        if key != '_id':
                            dub_city.update({key: city_dict[key]})

                    dub_city['bot_id'] = bot_2

                    new_city = City(**dub_city)
                    new_city.save()
                    goods = Good.objects(city_id=city.id.binary.hex())

                    for good in goods:
                        if good is not None:
                            Good(name=good.name,
                                 city_id=new_city.id.binary.hex(),
                                 price=good.price,
                                 description=good.description,
                                 photo=good.photo,
                                 districts=good.districts).save()

        payment = Payment.objects(bot_id=bot_id).first()

        if not (payment is None):
            payment_dict = loads(payment.to_json())

            dub_payment = {}

            for key in payment_dict:
                if key != '_id':
                    dub_payment.update({key: payment_dict[key]})

            dub_payment['bot_id'] = bot_2

            new_payment = Payment(**dub_payment)
            new_payment.save()
        return str(bot_2)
Esempio n. 11
0
def set(ref_id, text):
    return Texts(ref_id=ref_id, value=text).insert()._id
Esempio n. 12
0
def gets(ref_id):
    '''
    Get texts objects.
    '''
    return Texts.select('where ref_id=? order by creation_time desc', ref_id)
Esempio n. 13
0
def get(_id):
    ' get text value '
    return Texts.get_by_id(_id).value
Esempio n. 14
0
                      'Город: {}\n' \
                      'Район: {}\n' \
                      'Товар: {}\n' \
                      'Оплата: {}\n' \
                      'Код: {}'
SELECTED = 'Выбрано: *{}*\n' \
                          'Коротко о товаре: *{}*\n' \
                          'Цена: *{}* грн.\n\n' \
                          'Выбирай район:'
SELECTED2 = 'Выбрано: *{}*\n' \
                          'Коротко о товаре: *{}*\n' \
                          'Старая цена: *{}* грн.\n' \
                          'Новая цена: *{}* грн.\n\n' \
                           'Выбирай район:'

texts = Texts()
texts.greet_msg = 'Привет'
texts.back_btn = BACKBTN
texts.use_buttons_msg = USEBUTTONS
texts.choose_good_msg = CHOOSEGOOD
texts.choose_city_msg = CHOOSESITY
texts.choose_district_msg = CHOOSEDISTRICT
texts.choose_payment_msg = CHOOSEPAYMENT
texts.done_btn = DONE
texts.leads_btn = LEADS
texts.new_order_msg = NEWORDER
texts.selected_good_msg2 = SELECTED2
texts.selected_good_msg = SELECTED

l_texts = LeadTexts()
l_texts.wallet_btn = 'Кошелек'
Esempio n. 15
0
 def get_texts(self):
     return Texts.objects(bot_id=str(self.bot_id)).first()