Example #1
0
def get_quote(bot, update):
    logger.info("[!][get_quote]")
    print("[!][get_quote]")
    try:
        if update.message.text == "/lauters":
            query = "SELECT text FROM lauters ORDER BY RAND() LIMIT 1"
        else:
            quote_id = (update.message.text).split(" ")
            if len(quote_id) > 1:
                query = "SELECT message_ID FROM quote WHERE chat_ID = {} AND id = {} ORDER BY RAND() LIMIT 1".format(
                    update.message.chat_id, int(quote_id[1]))
            else:
                query = "SELECT message_ID FROM quote WHERE chat_ID = {} ORDER BY RAND() LIMIT 1".format(
                    update.message.chat_id)

            cursor.execute(query)
            message_id = cursor.fetchone()[0]
            query = "SELECT text FROM log WHERE message_id = {}".format(
                message_id)
#        logger.info(query)
        cursor.execute(query)
        row = cursor.fetchone()
        quote = "__{}__".format(row[0])
#        logger.info(quote)
    except Exception as e:
        logger.info(str(e))


#    logger.info(row)
    bot.send_message(update.message.chat_id, quote, parse_mode='Markdown')
    def creating_schedule(self):
        cursor.execute(self.query, (self.name_numb))
        X = []
        Y = []
        for (price, date) in cursor:
            X.append({}.format(price))
            Y.append({}.format(date))

        plt.plot(X, Y, label=self.name_numb)
Example #3
0
  def get(self):
    query = "SELECT * FROM gallery ORDER BY id"
    cursor.execute(query)
    MainHandler.data = cursor.fetchall()

    MainHandler.low = 0
    MainHandler.high = MaxImage
    new_data = MainHandler.data[MainHandler.low : MainHandler.high]
    self.render("home.html", pics = new_data)
Example #4
0
 def post(self):
   name = self.get_argument('name')
   email = self.get_argument('email')
   subject = self.get_argument('subject')
   message = self.get_argument('message')
   created_on = datetime.datetime.now()
   
   query = "INSERT INTO Feedback (name, subject, email, message, created_on) VALUES (%s, %s, %s, %s, %s)"
   cursor.execute(query, (name, subject, email, message, created_on,))
   connection.commit()
   self.redirect('contact')
Example #5
0
  def get(self):
    title = self.get_argument('search')
    title = title[0:min(len(title), 3)].capitalize()

    query = "SELECT * FROM gallery WHERE title LIKE \'" + title + "%\'"
    cursor.execute(query)
    MainHandler.data = cursor.fetchall()
    MainHandler.low = 0
    MainHandler.high = min(MaxImage, len(MainHandler.data))
    new_data = MainHandler.data[MainHandler.low : MainHandler.high]
    self.render("response.html", pics = new_data)
Example #6
0
def xinga(bot, update):
    logger.info("[!][xinga]")
    try:
        query = "SELECT text FROM xingamento ORDER BY RAND() LIMIT 1"
        cursor.execute(query)
        row = cursor.fetchone()
        quote = "__{}__".format(row[0])

        msg = "[!] Cala a boca {}, {}!".format(
            update.message.from_user.first_name, quote)
        bot.send_message(update.message.chat_id, msg, parse_mode='Markdown')
    except Exception as e:
        logger.info(str(e))
Example #7
0
def list_quotes(bot, update):
    print("[!] list_quotes")
    quotes_list = ""
    try:
        query = "SELECT quote.id, log.text FROM quote, log WHERE quote.chat_id = {} AND quote.message_id=log.message_id".format(
            update.message.chat_id)
        cursor.execute(query)
        results = cursor.fetchall()
        for result in results:
            quotes_list += "#{}: {} \n".format(result[0], result[1])
        bot.send_message(update.message.from_user.id, quotes_list)
    except Exception as e:
        logger.info(str(e))
Example #8
0
def put_quote(bot, update):
    logger.info("[!][put_quote]")
    try:
        message_id = update.message.reply_to_message.message_id
        query = (
            "INSERT INTO quote (message_id, chat_id) VALUES ({}, {})").format(
                message_id, update.message.chat_id)
        cursor.execute(query)
        con.commit()
        logger.info("{} - OK".format(cursor.lastrowid))
        bot.send_message(
            update.message.chat.id, "Salvei \"{}\" com id {}".format(
                update.message.reply_to_message.text, cursor.lastrowid))
    except Exception as e:
        logger.info(str(e))
Example #9
0
def logging(bot, update):
    try:
        photo = ""
        query = (
            "INSERT INTO log (message_id, date, chat_id, text, photo, from_id, first_name, last_name, username) VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}')"
        ).format(update.message.message_id,
                 str(update.message.date), update.message.chat.id,
                 str(update.message.text), photo, update.message.from_user.id,
                 update.message.from_user.first_name,
                 update.message.from_user.last_name,
                 update.message.from_user.username)
        # else:
        #     photo = update.message.photo.file_id
        # logger.info(photo)
        #     logger.info(query)
        cursor.execute(query)
        con.commit()
        logger.info("{}:{}:{}".format(update.message.chat.id,
                                      update.message.from_user.first_name,
                                      update.message.text))
    except Exception as e:
        logger.info(str(e))
Example #10
0
    "  `date` DATE NOT NULL,"   
    "  PRIMARY KEY (`id`)")

add_crypto = ("INSERT INTO crypto_table "
              "(name, price, date) "
              "VALUES (%(name)s, %(price)s, %(date)s)")

date_now = datetime.now().date()

name = [
    crypto_dict['bitcoin'].naming,
    crypto_dict['ethereum'].naming,
    crypto_dict['ripple'].naming,
]

price = [
    crypto_dict['bitcoin'].pricing,
    crypto_dict['ethereum'].pricing,
    crypto_dict['ripple'].pricing,
]

data_crypto = {
    'name': name,
    'price': price,
    'date': date_now
}

cursor.execute(add_crypto, data_crypto)
cnx.commit()
cursor.close()
cnx.close()