Código de Python - Acortador de URL

Requerimientos

Librerías y recursos: urlib, pyshortehers, qrcode

1.1

Publicado el 1 de Diciembre del 2021gráfica de visualizaciones de la versión: 1.1
1.700 visualizaciones desde el 1 de Diciembre del 2021
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tkinter import *
from tkinter import messagebox, filedialog
import pyshorteners as ps
import time
import qrcode
import pyperclip
from urllib.parse import urlparse
import threading
import os
 
class shortener:
    def __init__(self):
        self.app = Tk()
        self.app.title("URL Shortener")
        self.app.geometry("1038x370")
        self.app.configure(background="PaleGreen2")
 
        current_dir = StringVar()
        current_dir.set(os.getcwd())
        self.url = StringVar()
 
        Label(self.app,text="URL Shortener",bg="PaleGreen2",width=32,fg="white",font=('Arial', 40, 'bold')).place(x=4,y=50)
        self.ShrtStatus = Label(self.app,bg="PaleGreen2",fg="white",width=103,font=('Arial', 13, 'bold'))
        self.ShrtStatus.place(x=1,y=113)
        Entry(self.app,textvariable=current_dir,width=172).place(x=0,y=0)
        self.url_visor=Entry(self.app,textvariable=self.url,width=37,font='Arial, 33')
        self.url_visor.place(x=20,y=150)
        Button(self.app,text="SHORTEN",height=3,width=12,command=self.init_task).place(x=925,y=150)
        Button(self.app,text="COPY",width=12,command=self.copy).place(x=925,y=235)
        Button(self.app,text="CLEAR",width=12,command=self.clear).place(x=819,y=235)
        Button(self.app,text="IMPORT URL",width=12,command=self.init_task2).place(x=713,y=235)
        Button(self.app,text="CREATE QR",width=20,command=self.save_qr).place(x=20,y=235)
 
        self.app.mainloop()
 
    def shorten_URL(self):
        if self.is_url(self.url_visor.get())==True:
            try:
                self.ShrtStatus.configure(text="shorting your URL...")
                url = self.url_visor.get()
                self.url.set(ps.Shortener().tinyurl.short(url))
                self.ShrtStatus.configure(text="task completed :)")
            except Exception as e:
                messagebox.showwarning("UNEXPECTED ERROR",str(e))
                self.clear()
        else:
            messagebox.showwarning("EMPTY/INVALID URL","Enter a valid URL.")
            self.clear()
 
    def import_url(self):
        self.clear()
        messagebox.showinfo("copy and paste","Copy and paste your URL")
        ultcop = pyperclip.paste().strip()
        while True:
            time.sleep(0.1)
            copy = pyperclip.paste().strip()
            if copy != ultcop:
                self.url.set(copy)
                self.ultcop = copy
                break
 
    def copy(self):
        if self.url_visor.get() != "":
            pyperclip.copy(self.url_visor.get())
            messagebox.showinfo("COPIED","Copied to clipboard.")
 
    def save_qr(self):
        if self.is_url(self.url_visor.get())==True:
            new_file = filedialog.asksaveasfilename(initialdir="/",initialfile="urlQR",
                                                    title="SAVE AS",defaultextension=".png",)
            if new_file != "":
                qr = qrcode.make(self.url_visor.get())
                qr.save(new_file)
 
    def clear(self):
        self.url.set("")
        self.ShrtStatus.configure(text="")
 
    def is_url(self,url):
        try:
            result = urlparse(url)
            return all([result.scheme, result.netloc])
        except ValueError:
            return False
 
    def init_task(self):
        t = threading.Thread(target=self.shorten_URL)
        t.start()
 
    def init_task2(self):
        t2 = threading.Thread(target=self.import_url)
        t2.start()
 
if __name__=="__main__":
    shortener()



Comentarios sobre la versión: 1.1 (0)


No hay comentarios
 

Comentar la versión: 1.1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s7179