示例#1
0
import constants as const
import DBuse
import telegram
from telegram.ext import ConversationHandler
from io import BytesIO
from image_handler import images



images = images()

const.__init__()

START,PHOTO, WITH_PHOTO, WITHOUT_PHOTO,SUBMIT,DELETE= range(6)

chat_info = dict()


# Include on previous wiht start that will serve as a CallBackQuery Handler, careate a fucntion that will be a Filet Image, and in start, make an if statement to go for the Filter text or filter image
def start(update,context):
    user = update.message.from_user.first_name

    options = [[telegram.InlineKeyboardButton('YES', url=None, callback_data='YES')], [telegram.InlineKeyboardButton('NO', url=None, callback_data='NO')] ]
    reply_markup = telegram.InlineKeyboardMarkup(options)

    update.message.reply_text("Hola {}, dinos se tu mensaje incluirá foto".format(user),
                              reply_markup = reply_markup)
    return PHOTO

def photo(update, context):
    query = update.callback_query
示例#2
0
 def get_mydb():
     if DBHandler.DBNAME == '':
         constants.__init__()
     db = DBHandler()
     mydb = db.connect()
     return mydb
示例#3
0
import requests
import datetime
import base64
import constants
import DBuse
from bs4 import BeautifulSoup

import json

constants.__init__()


class images():
    def __init__(self):
        self.url_image = constants.URL_IMAGES
        self.user = constants.WPNAME
        self.password = constants.WPPASS
        self.date = datetime.datetime.now()

    def upload_image(self, image, news_id):
        credentials = self.user + ':' + self.password
        token = base64.b64encode(credentials.encode())
        header = {'Authorization': 'Basic ' + token.decode('utf-8')}
        media = {'file': image}

        responce = requests.post(self.url_image, headers=header, files=media)
        print(responce.content.decode('utf-8'))

        id = json.loads(responce.content.decode('utf-8'))['id']
        link = json.loads(responce.content.decode('utf-8'))['link']