예제 #1
0
 def create_img(url):
     img = requests.get(url=url)
     img_data = img.content
     if url.endswith('jpg'):
         image_name = f'{BASE_DIR}/BotLogic/img/test.jpg'
     elif url.endswith('png'):
         image_name = f'{BASE_DIR}/BotLogic/img/test.png'
     with open(image_name, 'wb') as img:
         img.write(img_data)
     server_data = ApiMethodsClass.photoUploadServer()
     upload_url = server_data.get('upload_url')
     files = {'file': open(image_name, 'rb')}
     response = requests.post(url=upload_url,
                              params={'access_token': TOKEN},
                              files=files)
     json_obj = response.json()
     photo = json_obj.get('photo')
     server = json_obj.get('server')
     hash_data = json_obj.get('hash')
     server_img_data = ApiMethodsClass.savePhoto(photo=photo,
                                                 server=server,
                                                 hash=hash_data)
     data = {
         'owner_id': server_img_data[0].get('owner_id'),
         'media_id': server_img_data[0].get('id')
     }
     new_img = ImageInfo.create(**data)
     new_img.save()
     return new_img.id
예제 #2
0
파일: Bot.py 프로젝트: Sin93/dobro_mail
    def send_answer(self):

        for message in self.response_data['messages']:
            ApiMethodsClass(
                user_id=self.user_id,
                message=message,
            )
예제 #3
0
파일: models.py 프로젝트: Sin93/dobro_mail
    def upload_photo(img_filename):

        server_data = ApiMethodsClass.photoUploadServer()
        upload_url = server_data.get('upload_url')
        files = {'file': open(img_filename, 'rb')}

        response = requests.post(url=upload_url, params={'access_token': TOKEN}, files=files)
        json_obj = response.json()
        photo = json_obj.get('photo')
        server = json_obj.get('server')
        hash_data = json_obj.get('hash')

        server_img_data = ApiMethodsClass.savePhoto(photo=photo, server=server, hash=hash_data)
        data = {
            'owner_id': server_img_data[0].get('owner_id'),
            'media_id': server_img_data[0].get('id')
        }

        return data
예제 #4
0
 def check_users():
     users = Database.get_all_users()
     time = datetime.datetime.now()
     for user in users:
         if user.can_send_reminds:
             if user.is_active == 0 \
                     and (time - user.updated_at).total_seconds() > config.REMIND_DELAY \
                     and (time - user.last_time_donation).total_seconds() > config.PAYMENT_DELAY:
                 user.updated_at = time
                 user.save()
                 messages = SendRemindMessage.generate_remind_message(user)
                 for message in messages:
                     ApiMethodsClass(user.user_id, message)
예제 #5
0
파일: Bot.py 프로젝트: Sin93/dobro_mail
 def create_template(type, data=None):
     if type == 'carousel':
         carousel = []
         for project in data:
             carousel_element = ApiMethodsClass.create_carusel_element(
                 title='title',
                 description=project.short_desc,
                 project_link=project.url,
                 photo_id=f'-198392433_457239229',
                 # Тестовая фотография пока нету реальных того же размера загружена с http://placehold.it/221x136
                 payload={'project': project.offer_id})
             carousel.append(carousel_element)
         return carousel
예제 #6
0
 def check_users():
     """
     Запускает проверку пользователей для отправки сообщений
     :return:
     """
     users = Database.get_all_users()
     time = datetime.datetime.now()
     for user in users:
         if user.can_send_reminds:
             if user.is_active == 0 \
                     and (time - user.updated_at).total_seconds() > config.REMIND_DELAY \
                     and (time - user.last_time_donation).total_seconds() > config.PAYMENT_DELAY:
                 user.updated_at = time
                 user.save()
                 messages = SendRemindMessage.generate_remind_message(user)
                 for message in messages:
                     ApiMethodsClass(user.user_id, message)
             elif (time - user.updated_at).total_seconds(
             ) > config.USER_MAX_ACTIVE_TIME_WITHOUT_ACTIVITY:
                 user.is_active = 0
                 user.save()