Exemple #1
0
def combinacion(bot, update, args):

    chat_id = update.message.chat.id

    if (len(args) == 0):

        log.info("He recibido un comando combinacion [Chat ID: " +
                 str(update.message.chat_id) + "]")
        message = (
            'Indicame tu combinación favorita en este formato\n\n'
            '*/combinacion 1,2,3,4,5 1,2* \n\n'
            '¡¡¡Respeta los espacios entre el comando, los números y las estrellas!!!'
        )

    else:
        log.info("He recibido un comando combinacion + args [Chat ID: " +
                 str(update.message.chat_id) + "]")

        if (len(args) == 2):
            db.GrabaCombinacion(chat_id, args[0], args[1])
            message = 'Actualizada tu combinación favorita'

        else:
            message = 'Revisa el formato del comando no encuentro la combinación y las estrellas'

    bot.send_message(chat_id=chat_id, text=message, parse_mode="Markdown")
Exemple #2
0
def premios(bot, update):
    #Preparar para subscripción entrando un solo comando
    chat_id = update.message.chat.id
    log.info("He recibido un comando premios [Chat ID: " + str(chat_id) + "]")

    update.message.reply_text(text='¿Cuántos sorteos comprobamos?',
                              reply_markup=tc.sorteos_markup)
Exemple #3
0
def end(bot, update, args):
    log.info("He recibido un comando end [Chat ID: " +
             str(update.message.chat_id) + "]")
    chat_id = update.message.chat.id
    message = update.message.reply_text('end')

    bot.send_message(chat_id=chat_id, text=message)
Exemple #4
0
def suscripcion(bot, update):

    chat_id = update.message.chat.id
    log.info("He recibido un comando suscripción [Chat ID: " + str(chat_id) +
             "]")

    if (db.select("*",
                  "Combinaciones",
                  where="chat_id = %s",
                  values=(chat_id, ))) == []:
        log.info("No hay combinación favorita [Chat ID: " + str(chat_id) + "]")
        bot.send_message(
            chat_id=chat_id,
            text="Debes indicar una combinación favorita primero /combinacion")

    else:
        if (db.select("*",
                      "Suscripciones",
                      where="chat_id = %s",
                      values=(chat_id, ))) == []:
            db.addSuscripcion(chat_id)
            log.info("Añadida Suscripción [Chat ID: " + str(chat_id) + "]")
            bot.send_message(chat_id=chat_id,
                             text="Estás suscrito a los sorteos")
        else:
            db.delSuscripcion(chat_id)
            log.info("Eliminada Suscripción [Chat ID: " + str(chat_id) + "]")
            bot.send_message(chat_id=chat_id,
                             text="Estás desuscrito a los sorteos")
Exemple #5
0
def ultimo(bot, update):

    if hasattr(update, 'message'):

        log.info("He recibido un comando ultimo [Chat ID: " +
                 str(update.message.chat_id) + "]")
        text = db.resultado() + db.CompruebaCombo(
            update.message.chat_id) + db.CompruebaGrupo(
                update.message.chat_id,
                db.select(
                    'fecha', 'Euromillones',
                    'fecha= (select max(fecha) from Euromillones)')[0][0])

        bot.send_message(chat_id=update.message.chat_id, text=text)

    else:
        chat_ids = db.suscripcion()
        for chat_id in chat_ids:
            log.info("He enviado un comando de suscripción ultimo [Chat ID: " +
                     chat_id[0] + "]")
            text = db.resultado() + db.CompruebaCombo(chat_id[0])
            bot.send_message(chat_id=chat_id[0], text=text)
Exemple #6
0
import helpers.io as io
import helpers.api as api
import helpers.log as log
import colorama
from dotenv import load_dotenv

# Enable colored output
colorama.init(autoreset=True)

# Read secrets
load_dotenv()

# Read config
config_path = "config.txt"
log.info(f"Opening file at {config_path}…")
coin_tickers = io.read_file(config_path)
log.debug(f"Read {str(len(coin_tickers))} lines")

# Fetch prices
prices = []
for coin in coin_tickers:
    coin = coin.rstrip()
    log.info(f"Fetching data for {coin}…")
    coin_price = api.get_price(coin)
    log.info(f"  {coin_price} EUR")
    prices.append(coin_price)

# Write results
output_path = "prices.txt"
io.write_list_file(output_path, prices)
log.info(f"Prices exported to {output_path}")
Exemple #7
0
def start(bot, update):
    log.info("He recibido un comando start [Chat ID: " +
             str(update.message.chat_id) + "]")
    bot.send_message(chat_id=update.message.chat_id,
                     text="Bienvenido a Uromillones",
                     reply_markup=tc.reply_markup)
Exemple #8
0
def grupo(bot, update):
    chat_id = update.message.chat.id
    log.info("He recibido un comando grupo [Chat ID: " + str(chat_id) + "]")
Exemple #9
0
    def handle(self):
        """Main handler"""

        stage = INIT_STAGE
        leftover = ''

        try:    
            while stage < CONN_ACCEPTED:
                data = self.request.recv(BUF_SIZE)
                
                # Client closed connection
                if not data:
                    raise Socks5ConnectionClosed
                    
                data = leftover + data

                if len(data) < 3:
                    leftover = data
                    continue

                # Init stage
                if stage == INIT_STAGE:
                    # If no auth required                
                    if not self.local_auth and data == '\x05\x01\x00':
                        self.request.sendall('\x05\x00')
                        stage = FINAL_STAGE
                        continue
                    # if username/password auth required
                    elif self.local_auth and data == '\x05\x01\x02':
                        self.request.sendall('\x05\x02')
                        stage = AUTH_STAGE
                        continue
                    # no auth method accepted
                    else:
                        self.request.sendall('\x05\xFF')
                        #print hexstring(data)
                        raise Socks5NoAuthMethodAccepted
                        
                # Auth stage
                elif stage == AUTH_STAGE:
                    name_length, = struct.unpack('B', data[1])
                    if len(data[2:]) < name_length + 1:
                        leftover = data
                        continue
                    pass_length, = struct.unpack('B', data[2+name_length])
                    if len(data[2+name_length+1:]) < pass_length:
                        leftover = data
                        continue                    

                    username = data[2:2+name_length]
                    password = data[2+name_length+1:]

                    self.member_id, error_code = self.authority.auth(username, password)
                    
                    if error_code != AUTH_SUCCESSFUL:
                        self.request.sendall('\x01' + error_code)
                        log.info('Auth failed for user: %s', username)
                        raise Socks5AuthFailed
                    else:
                        self.request.sendall('\x01\x00')
                        log.info('Auth succeeded for user: %s', username)
                        stage = FINAL_STAGE
                        
                # Final stage
                elif stage == FINAL_STAGE:
                    if data < 6:
                        leftover = data
                        continue

                    # Only TCP connections and requests by DNS are allowed
                    if data[:2] != '\x05\x01' or data[3] != '\x03':
                        # Protocol error
                        self.request.sendall('\x05\x07')
                        raise Socks5NotImplemented
                    else:
                        length, = struct.unpack('B', data[4])
                        if len(data) < 5 + length + 2:
                            leftover = data
                            continue

                        domain = data[5:5+length]
                        port, = struct.unpack('!H', data[5+length:])

                        try:
                            # Connect to upstream instead of destination
                            if self.upstream_addr:
                                sc = Socks5Client(self.upstream_addr, self.upstream_username, self.upstream_password, data)
                                log.info("Connecting to %s via upstream %s.", domain, self.upstream_addr)
                                dest = sc.connect()

                            # Connect to destination directly
                            else:
                                if port not in [80, 443]:
                                    raise Socks5SocketError("Port %d not allowed for %s" % (port, username))
                                my_ip, my_port = self.request.getsockname()
                                log.info("Connecting to %s.", domain)
                                dest = make_connection((domain, port), my_ip)

                            # Connected to upstream/destination
                            dsockname = dest.getsockname()
                            client_ip = dsockname[0]
                            client_port = dsockname[1]
                            ip_bytes = my_inet_aton(client_ip)                            
                            port_bytes = struct.pack('!H', client_port)
                            self.request.sendall('\x05\x00\x00\x01' + ip_bytes + port_bytes)
                                
                            stage = CONN_ACCEPTED

                        except Exception, e:
                            log.debug('Error when trying to resolve/connect to: %s, reason: %s', (domain, port), e)
                            #traceback.print_exc()
                            self.request.sendall('\x05\x01')
                            raise

                        
            # Starting to forward data
            try:
                self.forward(self.request, dest)
            except Socks5Exception, e:
                log.debug("Forwarding finished: %s", e)
Exemple #10
0
                            #traceback.print_exc()
                            self.request.sendall('\x05\x01')
                            raise

                        
            # Starting to forward data
            try:
                self.forward(self.request, dest)
            except Socks5Exception, e:
                log.debug("Forwarding finished: %s", e)
            except Exception, e:
                log.debug('Error when forwarding: %s', e)
                #traceback.print_exc()
            finally:
                dest.close()
                log.info("%d bytes out, %d bytes in. Socks5 session finished %s <-> %s.", self.bytes_out, self.bytes_in, self.client_name, self.server_name)
                if self.local_auth and (self.bytes_in or self.bytes_out):
                    self.authority.usage(self.member_id, self.bytes_in + self.bytes_out)
        except Socks5Exception, e:
            log.debug("Connection closed. Reason: %s", e)
        except Exception, e:
            log.debug('Error when proxying: %s', e)
            #traceback.print_exc()
        finally:
            try:
                self.request.shutdown(socket.SHUT_RDWR)
            except:
                self.request.close()
            return

    def forward(self, client, server):