elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Mensajes
Páginas: 1 [2] 3 4
11  Programación / Scripting / Python en: 17 Marzo 2020, 06:28 am
¿Es necesario usar la estructura try/except cuando envió un correo usando ssl  o simplemente cuando
utilizo tls?

¿Cuales son las convenciones a seguir al enviar correos por medio de python?

Gracias por sus respuestas!
12  Programación / Scripting / [Python3 + turtle] = Dibujo de Pacman en: 17 Marzo 2020, 04:41 am
Código
  1. from turtle import Turtle, Screen
  2.  
  3. width = 600
  4. height = 600
  5. X = width - 10
  6. Y = height - 10
  7.  
  8.  
  9. def _turtle():
  10.    # Pantalla
  11.    pantalla = Screen()
  12.    pantalla.title("Pacman")
  13.    pantalla.bgcolor("#254555")
  14.    pantalla.setup(width=width, height=height)
  15.    pantalla.colormode(255)
  16.    pantalla.screensize(X, Y)
  17.    pantalla.delay(0)
  18.  
  19.    # Tortuga
  20.    turtle = Turtle()
  21.    turtle.pensize(2)
  22.    turtle.hideturtle()
  23.    turtle.speed(0)
  24.    turtle.pu()
  25.    turtle.goto(-X/2, Y/2)
  26.    turtle.pd()
  27.    turtle.pencolor("#212140")
  28.    for i in range(91):
  29.        turtle.setheading(-i)
  30.        turtle.fd(width/2)
  31.        turtle.bk(width/2)
  32.    turtle.pu()
  33.    turtle.goto(X/2, Y/2)
  34.    turtle.pd()
  35.    for i in range(91):
  36.        turtle.setheading(i)
  37.        turtle.fd(-width/2)
  38.        turtle.bk(-width/2)
  39.  
  40.    turtle.pu()
  41.    turtle.goto(-X/2, -Y/2)
  42.    turtle.pd()
  43.    for i in range(91):
  44.        turtle.setheading(i)
  45.        turtle.fd(width/2)
  46.        turtle.bk(width/2)
  47.  
  48.    turtle.pu()
  49.    turtle.goto(X/2, -Y/2)
  50.    turtle.pd()
  51.    for i in range(91):
  52.        turtle.setheading(-i)
  53.        turtle.fd(-width/2)
  54.        turtle.bk(-width/2)
  55.    turtle.pu()
  56.    turtle.home()
  57.    turtle.pd()
  58.    for i in range(round(width/2)):
  59.        turtle.pencolor("#cfbb00")
  60.        turtle.setheading(-i)
  61.        turtle.fd(90)
  62.        turtle.bk(90)
  63.  
  64.    turtle.pu()
  65.    turtle.goto(-10, 45)
  66.    turtle.color("#001020")
  67.    turtle.pd()
  68.    turtle.begin_fill()
  69.    turtle.circle(10)
  70.    turtle.end_fill()
  71.  
  72.    pantalla.exitonclick()
  73.  
  74.  
  75. _turtle()
  76.  
  77.  
  78.  
13  Programación / Scripting / [Python3-tkinter ejemplo de calculadora] en: 8 Marzo 2020, 16:38 pm


Hola a todos aquí les dejo una calculadora sin funcionalidad.
Espero les guste o puede que no


Código
  1. from tkinter import Tk
  2. from tkinter import ttk
  3. from math import floor
  4.  
  5.  
  6. class App(ttk.Frame):
  7.    def __init__(self, master):
  8.        super().__init__(master)
  9.        self.pack()
  10.        # Variables
  11.        self.screen = None
  12.        # Metodos de clase
  13.        self.style_widgets()
  14.        self.create_widgets()
  15.  
  16.    # Estilos de los componentes del Frame
  17.    def style_widgets(self):
  18.        # estilos generales
  19.        ttk.Style().configure("TEntry", foreground="#00000a9")
  20.        ttk.Style().configure("TButton", width=10, padding=(
  21.            15, 10), relief=ttk.tkinter.FLAT)
  22.        ttk.Style().configure("E.TButton", background="#709234")
  23.        ttk.Style().configure("OP.TButton", background="#cccccc")
  24.  
  25.    def create_widgets(self):
  26.        self.screen = ttk.Entry(self)
  27.        self.screen.config(justify=ttk.tkinter.RIGHT)
  28.        self.screen.grid(row=1, column=1, ipady=20,
  29.                         columnspan=4, sticky="NSWE")
  30.  
  31.        # Crear botones
  32.        dic_buttons = {}  # diccionario de botones
  33.        for i in range(1, 13):
  34.            dic_buttons[f"btn{i}"] = ttk.Button(self, text=f"{i}")
  35.  
  36.        dic_buttons.update([("btnmul", ttk.Button(self, text="x")),
  37.                            ("btndif", ttk.Button(self, text="-")),
  38.                            ("btnplus", ttk.Button(self, text="+")),
  39.                            ("btnmod", ttk.Button(self, text="/"))])
  40.  
  41.        dic_buttons["btn9"].grid(row=2, column=1)
  42.        dic_buttons["btn8"].grid(row=2, column=2)
  43.        dic_buttons["btn7"].grid(row=2, column=3)
  44.        dic_buttons["btnmul"].grid(row=2, column=4)
  45.        dic_buttons["btn6"].grid(row=3, column=1)
  46.        dic_buttons["btn5"].grid(row=3, column=2)
  47.        dic_buttons["btn4"].grid(row=3, column=3)
  48.        dic_buttons["btndif"].grid(row=3, column=4)
  49.        dic_buttons["btn3"].grid(row=4, column=1)
  50.        dic_buttons["btn2"].grid(row=4, column=2)
  51.        dic_buttons["btn1"].grid(row=4, column=3)
  52.        dic_buttons["btnplus"].grid(row=4, column=4)
  53.        dic_buttons["btn10"].grid(row=5, column=1)
  54.        dic_buttons["btn11"].grid(row=5, column=2)
  55.        dic_buttons["btn12"].grid(row=5, column=3)
  56.        dic_buttons["btnmod"].grid(row=5, column=4)
  57.  
  58.        dic_buttons["btn10"].config(text=",")
  59.        dic_buttons["btn11"].config(text="0")
  60.        dic_buttons["btn12"].config(text="=", style="E.TButton")
  61.  
  62.        # print(dic_buttons.keys())
  63.        dic_buttons["btnmul"].config(style="OP.TButton")
  64.        dic_buttons["btndif"].config(style="OP.TButton")
  65.        dic_buttons["btnplus"].config(style="OP.TButton")
  66.        dic_buttons["btnmod"].config(style="OP.TButton")
  67.  
  68.  
  69. if __name__ == "__main__":
  70.    root = Tk()
  71.    root.resizable(False, False)
  72.    root.title("ttk Example")
  73.    app = App(root)
  74.    app.mainloop()
  75.  
  76.  
14  Programación / Scripting / [Python3] Ayuda con manipulacion de ficheros en: 1 Febrero 2020, 01:51 am
Hola a todos los que lean esto.
El siguiente script trata de automatizar el envió de correos, por medio del uso de dos ficheros.

1.carta.txt:
Estimado/a H #CLIENTE#
Tenemos noticias de que usted don/doña H #CLIENTE# no a abonado el importe
de la cuota mensual a que le obliga el draconiano contrato que firmó.

2.cliente.txt:
alguncorreo@gmail.com nombre apellido
alguncorreo@gmail.com nombre apellido

La idea es sustituir #CLIENTE# por el nombre y apellido del cliente, que es lo que ya he logrado hasta el momento y sustituir H(hombre) si esta presente o M(mujer) por su correspondiente identificativo Estimado/a y don/doña esta es la parte que aun no he podido hacer si me pudieran dar alguna idea de como optimizar y como finalizar este ejercicio se los agradeceria


Gracias por responder al final lo solucione usando expresiones regulares puede que no sea muy
eficiente pero lo logre hacer  ;D.
Este es el código

Código
  1. def envio_correo_personalizado():
  2.    try:
  3.  
  4.        # variables y apertura de ficheros
  5.        nombre = []
  6.        mensaje = ""
  7.        carta = open("carta.txt", "r")
  8.        carta_copia = open("carta.txt.copia", "w")
  9.        cliente = open("cliente.txt", "r")
  10.  
  11.        # lectura de clientes
  12.        for _cliente in cliente:
  13.            nombre += _cliente.rstrip().split("/")
  14.  
  15.        # Leyendo el fichero carta
  16.        linea = carta.readline()
  17.        while linea != "":
  18.            mensaje += linea
  19.            linea = carta.readline()
  20.  
  21.        # TODO Cambiando los valores del mensaje segun el genero usando expresiones regulares.
  22.        # FIXME Buscar otra forma de hacerlo.
  23.        mensaje = re.sub(
  24.            r"/a|/doña|H", "", mensaje) if "H" in mensaje else re.sub(r"o/|don/|M", "", mensaje)
  25.        mensaje = re.sub(r"#CLIENTE#", nombre[1], mensaje)
  26.        print("Mensaje cambiado")
  27.        print(mensaje)
  28.  
  29.        for i in mensaje:
  30.            carta_copia.write(i)
  31.  
  32.        # cierre de ficheros
  33.        carta.close()
  34.        cliente.close()
  35.        carta_copia.close()
  36.  
  37.    except IOError:
  38.        print("Fichero no existe")
  39.  
  40.  
15  Programación / Scripting / [Python3-Flask] Ayuda en: 27 Enero 2020, 02:49 am
¿Existe alguna forma enmascarar la url en flask?


Gracias por su ayuda
16  Programación / Scripting / Re: [Python3]¿Cómo lo puedo optimizar? en: 15 Enero 2020, 04:01 am
Asi es pero no entiendo porque al primer intento salen todos los casos bien y luego se queda cargando y falla el primer caso
17  Programación / Scripting / Re: [Python3]¿Cómo lo puedo optimizar? en: 15 Enero 2020, 03:38 am
A mi simplemente me sale
Compiler Message:
RuntimeError

Input (stdin)
10000
Lista de todos  los datos que se ingresaron

Expected output
Lista de todos los datos buscados
18  Programación / Scripting / Re: [Python3]¿Cómo lo puedo optimizar? en: 15 Enero 2020, 03:06 am
Task
Given n names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each name queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for name is not found, print Not found instead.

Note: Your phone book should be a Dictionary/Map/HashMap data structure.




Aqui ya inicialice algunas variables pero aun sigue el error

Código
  1. def phone_book():
  2.    n = int(input())
  3.    phone_book = {}  # dictionary
  4.    for i in range(n):
  5.        string = input().split()
  6.        phone_book.update({string[0]: int(string[1])})
  7.    return phone_book
  8. # processing
  9. def query(phone_book):
  10.    i = 0
  11.    _query = ""
  12.    lenght = len(phone_book)
  13.    for i in range(lenght):
  14.        _query = input()
  15.        if _query in phone_book:
  16.            print("{0}={1}".format(_query, phone_book[_query]))
  17.        else:
  18.            print("Not found")
  19. query(phone_book())
  20.  
  21.  
19  Programación / Scripting / Re: [Python3]¿Cómo lo puedo optimizar? en: 15 Enero 2020, 02:01 am
Perdón no me especifique bien ese ejercicio lo estoy haciendo en la página de HackerRank y ese error lo tira el interprete dcha página.
El RuntimeError se da cuando al diccionario se le añade un total de 100000 datos y se luego se hace una busqueda de igual magnitud.El script que hice le toma mucho tiempo en realizar la busqueda y no pasa la prueba.
20  Programación / Scripting / Re: [Python3]¿Cómo lo puedo optimizar? en: 15 Enero 2020, 01:42 am
¿Que está?
Páginas: 1 [2] 3 4
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines