Código de Python - Colector de links

Imágen de perfil
Val: 712
Bronce
Ha aumentado 1 puesto en Python (en relación al último mes)
Gráfica de Python

Colector de linksgráfica de visualizaciones


Python

Actualizado el 2 de Marzo del 2024 por Antonio (75 códigos) (Publicado el 6 de Marzo del 2022)
3.457 visualizaciones desde el 6 de Marzo del 2022
Aplicación para guardar accesos directos a internet (que se guardan en un archivo 'json' que se genera al ejecutar el programa por primera vez), mediante la introducción de la URL en la entrada superior (o su copia mediante el botón 'IMPORT NEW LINK'). El nuevo acceso se guarda mediante el botón "SAVE LINK AS:" que abrirá una ventana pidiendo el nombre del nuevo acceso. Una vez guardado el acceso, se podrá acceder a la correspondiente página seleccionando, en la lista, el elemento guardado y clicando en el botón 'ACCESS' (admite selección normal y múltiple). También permite la eliminación la totalidad de los link o solo los seleccionados. También permite la búsqueda por nombre entre los accesos guardados. El botón "SAVE LIST" generará un archivo de texto con los nombres de enlace y sus correspondientes URLs asociadas, que estén almacenados en el archivo JSON.
PARA CUALQUIER DUDA U OBSERVACIÓN, USEN LA SECCIÓN DE COMENTARIOS.
LNKC

Requerimientos

Librerías y recursos: tkinter, urlib, threading, json, webbrowser, pyperclip, time, os
Escrito en Python 3.7

1.1

Actualizado el 16 de Abril del 2022 (Publicado el 6 de Marzo del 2022)gráfica de visualizaciones de la versión: 1.1
1.034 visualizaciones desde el 6 de Marzo del 2022

2.0

Actualizado el 2 de Marzo del 2024 (Publicado el 9 de Agosto del 2022)gráfica de visualizaciones de la versión: 2.0
2.424 visualizaciones desde el 9 de Agosto del 2022
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

Mejoras en las importaciones. Se agregó una barra de desplazamiento horizontal debajo del listbox de títulos de enlaces.
lc
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tkinter as tk
from tkinter import messagebox, filedialog
from urllib.parse import urlparse
import threading
from prettytable import PrettyTable
import json
import webbrowser
import pyperclip
import pprint
import time
import os
 
if not "my_link_list.json" in os.listdir():
    d = {}
    with open("my_link_list.json", "w") as f:
        json.dump(d, f)
 
class Collector:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("Link Collector")
        self.root.geometry("575x623")
        self.root.configure(bg="gray88")
        self.root.resizable(height=tk.FALSE,width=tk.FALSE)
 
        currentDir = tk.StringVar()
        currentDir.set(os.getcwd())
        self.my_url = tk.StringVar()
        self.selMode = 'normal'
        self.search = tk.StringVar()
 
        with open("my_link_list.json") as f:
            self.link_list = json.load(f)
            #print(self.link_list)
 
        tk.Entry(self.root,textvariable=currentDir,width=95).place(x=0,y=0)
        self.urlEntry = tk.Entry(self.root,textvariable=self.my_url,width=43,font=("arial",18))
        self.urlEntry.place(x=5,y=35)
        tk.Button(self.root,text="SAVE URL AS:",width=49,bg="gray77",command=self.enter_name).place(x=5,y=70)#79
        tk.Button(self.root,text="CLEAR URL",width=28,bg="gray77",command=self.clear_url).place(x=363,y=70)
        self.canvas = tk.Canvas(self.root,bg="black")
        self.canvas.place(x=5,y=110)
        self.scrollbar = tk.Scrollbar(self.canvas,orient=tk.VERTICAL)
        self.scrollbar2 = tk.Scrollbar(self.canvas,orient=tk.HORIZONTAL)
        self.scrollbar.pack(side=tk.RIGHT,fill=tk.Y)
        self.scrollbar2.pack(side=tk.BOTTOM,fill=tk.X)
        self.linkBox = tk.Listbox(self.canvas,height=30,width=55)# 32 55
        self.linkBox.pack()
        self.linkBox.config(yscrollcommand = self.scrollbar.set)
        self.linkBox.config(xscrollcommand = self.scrollbar2.set)
        self.scrollbar.config(command = self.linkBox.yview)
        self.scrollbar2.config(command = self.linkBox.xview)
        self.searchEntry = tk.Entry(self.root,textvariable=self.search,font=("arial",14),width=13)
        self.searchEntry.place(x=363,y=110)
        tk.Button(self.root,text="SEARCH",bg="gray77",command=self.search_name).place(x=513,y=110)
        self.showAll = tk.Button(self.root,text="SHOW ALL LINKS",width=28,command=self.show_all)
        self.showAll.place(x=363,y=138)
        self.numLinks = tk.Label(self.root,text='{} LINKS'.format(len(self.link_list)),bg='black',fg='green',width=25,font=("arial",10))
        self.numLinks.place(x=363,y=195)#205
        tk.Button(self.root,text="ADD NEW LINK",bg="gray77",width=28,height=2,command=self.init_copy).place(x=363,y=230)#245
        tk.Button(self.root,text="ACCESS",bg="gray77",width=28,height=2,command=self.init_task).place(x=363,y=280)#295
        tk.Button(self.root,text="DELETE",bg="gray77",width=28,height=2,command=self.remove_link).place(x=363,y=350)#365
        tk.Button(self.root,text="DELETE ALL",bg="gray77",width=28,height=2,command=self.delete_listbox).place(x=363,y=400)#415
        tk.Button(self.root,text="CLEAR SELECTION",bg="gray77",width=28,height=2,command=self.clear_selection).place(x=363,y=450)#465
        self.selMod = tk.Button(self.root,text="SELECTION MODE: NORMAL",bg="gray77",width=28,height=2,command=self.selection_mode)
        self.selMod.place(x=363,y=500)#515
        tk.Button(self.root,text="SAVE LIST",bg="gray77",width=28,height=2,command=self.write_doc).place(x=363,y=570)#575
 
        self.show_list()
 
        self.root.mainloop()
 
    def copy_paste(self):
        messagebox.showinfo("COPY URL","Copy the URL you want.")
        self.ultima_copia = pyperclip.paste().strip()
        while True:
            time.sleep(0.1)
            self.copia = pyperclip.paste().strip()
            if self.copia != self.ultima_copia:
                self.my_url.set(self.copia)
                self.ultima_copia = self.copia
                break
 
    def clear_url(self):
        self.my_url.set("")
 
    def show_all(self):
        self.linkBox.delete(0,tk.END)
        with open("my_link_list.json") as f:
            self.link_list = json.load(f)
        self.show_list()
        #self.showAll.configure(state='disabled')
 
    def delete_listbox(self):
        if self.linkBox.size() > 0:
            message = messagebox.askquestion("REMOVING",'Do you want to remove all link list?')
            if message == "yes":
                self.link_list = {}
                self.update_json()
                self.linkBox.delete(0,tk.END)
                self.numLinks.configure(text='{} LINKS'.format(len(self.link_list)))#rep
 
    def selection_mode(self):
        if self.selMode == 'normal':
            self.linkBox.configure(selectmode='multiple')
            self.selMod.configure(text="SELECTION MODE: MULTIPLE")
            self.selMode = 'multiple'
        else:
            self.linkBox.configure(selectmode='normal')
            self.selMod.configure(text="SELECTION MODE: NORMAL")
            self.selMode = 'normal'
 
    def enter_name(self):
        if self.urlEntry.get() != "":
            if self.urlEntry.get() not in self.link_list.values():
                is_url = self.validate_url(self.urlEntry.get())
                if is_url:
                    self.window = tk.Tk()######
                    self.window.geometry("470x300")
                    self.window.title("Link Name")
                    tk.Label(self.window,text="ENTER LINK NAME",width=66).place(x=1,y=45)
                    entry_name = tk.Entry(self.window,width=25,font=('arial',20))
                    entry_name.place(x=44,y=90)
                    entry_name.focus()
                    tk.Button(self.window,text="SET NAME",width=10,height=2,bg="gray77",command=lambda:self.set_name(entry_name.get())).place(x=193,y=180)
 
                else:
                    messagebox.showwarning("Invalid URL","Enter a valid URL.")
                    self.my_url.set("")
            else:
                value_name = self.get_key(self.urlEntry.get())
                messagebox.showwarning("ALREADY SAVED","The URL provided is already saved as \'{}\'".format(value_name))
        else:
            messagebox.showwarning("NO URL","No URL provided.")
 
 
    def search_name(self):
        c = 1
        self.my_list = []
        self.linkBox.delete(0,tk.END)
        for i in self.link_list.keys():
            if self.searchEntry.get().lower() in i.lower():
                self.linkBox.insert(tk.END,(str(c)+"- "+i))
                self.my_list.append(self.link_list[i])
                c+=1
        self.numLinks.configure(text='{} LINKS'.format(len(self.my_list)))
        self.showAll.configure(state='normal')
 
    def show_list(self):
        if len(self.link_list) > 0:
            self.my_list = []
            c = 1
            for i in self.link_list:
                self.linkBox.insert(tk.END,(str(c)+"- "+i))
                self.my_list.append(self.link_list[i])
                c+=1
            self.numLinks.configure(text='{} LINKS'.format(len(self.my_list)))
            self.showAll.configure(state='disabled')
 
    def set_name(self,entry_name):
        if entry_name != "":
            self.window.destroy()
            self.linkBox.delete(0,tk.END)
            self.link_list[entry_name] = self.urlEntry.get()
            self.update_json()
            self.show_list()
            self.numLinks.configure(text='{} LINKS'.format(len(self.link_list)))
 
    def update_json(self):
        with open("my_link_list.json", "w") as f:
            json.dump(self.link_list, f)
 
    def remove_link(self):
        any_selected = self.is_any_selected()
        if any_selected:
            message = messagebox.askquestion("REMOVE LINK",'Delete selected link/s from link list?')
            if message == "yes":
                for i in self.linkBox.curselection():
                    del self.link_list[self.get_key(self.my_list[i])]
                self.linkBox.delete(0,tk.END)
                self.update_json()
                if self.showAll["state"]=='disabled':########################
                    self.show_list()
                else:
                    self.search_name()########################
                self.numLinks.configure(text='{} LINKS'.format(len(self.link_list)))
 
    def get_key(self,val):
        for key, value in self.link_list.items():
            if val == value:
                return key
 
    def open_page(self):
        try:
            for i in self.linkBox.curselection():
                print(i)
                webbrowser.open_new(self.my_list[i])
        except Exception as e:
            messagebox.showwarning("Access trouble", str(e))
 
 
    def clear_selection(self):
        for i in self.linkBox.curselection():
            self.linkBox.selection_clear(i)
 
 
    def is_any_selected(self):
        for i in range(0,self.linkBox.size()):
            if self.linkBox.selection_includes(i):
                sel = True
                break
        else:
            sel = False
        return sel
 
    def init_task(self):
        self.any_selected = self.is_any_selected()
        if self.any_selected:
            t = threading.Thread(target=self.open_page)
            t.start()
        else:
            messagebox.showwarning("No Link Selected","Select a link to go.")
 
    def create_list_of_lists(self,dic):
        listas = []
        for k, v in dic.items():
            lista = []
            lista.append(k)
            lista.append(v)
            listas.append(lista)
        return listas
 
    def write_doc(self):
        if self.linkBox.size() > 0:
            doc = filedialog.asksaveasfilename(initialdir="/",
                  title="Save as", initialfile="saved links",defaultextension=".txt")
            if doc != "":
                new_file = open(doc,"w")
                x = PrettyTable()
                x.field_names = ["Link Name", "URL"]
                content = self.create_list_of_lists(self.link_list)
                x.add_rows(content)
                new_file.write(x.get_string())
                new_file.close()
                messagebox.showinfo("SAVED","File saved successfully")
        else:
            messagebox.showwarning("NO ITEMS","There's nothing to save.")
 
 
    def init_copy(self):
        tc = threading.Thread(target=self.copy_paste)
        tc.start()
 
    def get_key(self,val):
        for key, value in self.link_list.items():
            if val == value:
                return key
 
    def validate_url(self,url):
        try:
            result = urlparse(url)
            return all([result.scheme, result.netloc])
        except ValueError:
            return False
 
if __name__=="__main__":
    Collector()



Comentarios sobre la versión: 2.0 (0)


No hay comentarios
 

Comentar la versión: 2.0

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/s7204