Ejemplo n.º 1
0
def city_post():
    try:
        country = request.args.get('country')
        countyname = country.split("_")[0]
        state = request.args.get('state')
        citylist = []
        for cityname in City.objects(countryname=countyname, state=state):
            citylist.append(cityname.city)
        cities = sorted(citylist)
        return jsonify(cities)

    except Exception as e:
        return jsonify('{"mesg":' + str(e) + '}')
Ejemplo n.º 2
0
 def cities_state(self, message, entry=False):
     cities = group_by_name(City.objects(bot_id=str(self.bot_id)))
     texts = self.get_texts()
     user = self.get_user(message)
     if entry:
         print("fi")
         if self.botType == "fi":
             messId = message.chat.id
             keybd = keyboards2
         elif self.botType == "sec":
             messId = message.from_user.id
             keybd = keyboards
         else:
             messId = ""
             keybd = ""
         self._bot.send_message(messId,
                                texts['choose_city_msg'],
                                reply_markup=keybd.set_keyboard(
                                    texts,
                                    cities.keys(),
                                    leads_btn=user.is_admin))
     else:
         print("se")
         if self.botType == "fi":
             messText = message.text
         elif self.botType == "sec":
             messText = message.data
         else:
             messText = ""
         if cities.get(messText):
             user.city = cities.get(messText)
             user.save()
             self._go_to_state(message, self.goods_state)
         elif messText == texts['leads_btn'] and user.is_admin:
             self._go_to_state(message, self.leads_summary_state)
         else:
             if self.botType == "fi":
                 messId = message.chat.id
                 keybd = keyboards2
             elif self.botType == "sec":
                 messId = message.from_user.id
                 keybd = keyboards
             else:
                 messId = ""
                 keybd = ""
             self._bot.send_message(messId,
                                    texts['use_buttons_msg'],
                                    reply_markup=keybd.set_keyboard(
                                        texts,
                                        cities.keys(),
                                        leads_btn=user.is_admin))
Ejemplo n.º 3
0
 def _start_state(self, message, entry=False):
     if self.botType == "fi":
         messId = message.chat.id
     elif self.botType == "sec":
         messId = message.from_user.id
     else:
         messId = ""
     self._bot.send_message(messId, self.get_texts()['greet_msg'])
     cities = City.objects(bot_id=str(self.bot_id))
     print("start")
     if not cities:
         return
     if len(cities) == 1:
         user = self.get_user(message)
         user.city = cities[0]
         user.save()
         self._go_to_state(message, self.goods_state)
     else:
         self._go_to_state(message, self.cities_state)
Ejemplo n.º 4
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)