-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpract4.py
executable file
·103 lines (75 loc) · 2.59 KB
/
pract4.py
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
# -*- coding: cp437 -*-
from Tkinter import *
from bs4 import BeautifulSoup
import sqlite3, urllib, tkMessageBox
def db_access():
con = sqlite3.connect('entradas.db')
con.text_factory = str
return con
def almacenar():
urllib.urlretrieve("http://www.sevillaguia.com/sevillaguia/agendacultural/agendacultural.asp", "entradas")
entradas = open("entradas", "r")
bs = BeautifulSoup(entradas)
lista = bs.find_all(class_=["LinkIndice", "TituloIndice"])
entradas.close()
con = db_access()
cursor = con.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS entradas(title text, link text, category text)")
for i in lista:
if i.get("class")[0] == "TituloIndice":
cat = i.string
else:
cursor.execute("INSERT INTO entradas VALUES (?, ?, ?)", (i.string, i.get("href"), cat))
con.commit()
con.close()
tkMessageBox.showinfo("","BD creada correctamente")
def mostrar(lista):
window = Toplevel()
sb = Scrollbar(window)
sb.pack(side = RIGHT, fill = Y)
text = Text(window, yscrollcommand = sb.set)
for i in lista:
for j in i:
text.insert(INSERT, str(j)+"\n")
text.insert(INSERT, "\n")
text.pack()
sb.config(command = text.yview)
def buscar_categoria():
def categoria_busqueda(event):
con = db_access()
cursor = con.cursor()
string = "%"+entry.get()+"%"
lista = cursor.execute("SELECT * FROM entradas WHERE category LIKE ?", (string,))
mostrar(lista)
con.close()
window = Toplevel()
label = Label(window, text = "Introduzca la categoría:")
entry = Entry(window)
label.pack(side = LEFT)
entry.bind("<Return>", categoria_busqueda)
entry.pack(side = RIGHT)
def buscar_evento():
def evento_busqueda(event):
con = db_access()
cursor = con.cursor()
string = entry.get()
lista = cursor.execute("SELECT * FROM entradas").fetchall()
lista = [i for i in lista if string in i[0]]
mostrar(lista)
con.close()
window = Toplevel()
label = Label(window, text = "Introduzca una palabra clave:")
entry = Entry(window)
label.pack(side = LEFT)
entry.bind("<Return>", evento_busqueda)
entry.pack(side = RIGHT)
top = Tk()
fr = Frame(top)
fr.pack()
almacenar = Button(fr, text = "Almacenar", command = almacenar)
almacenar.pack(side = LEFT)
listar = Button(fr, text = "Buscar Categoria", command = buscar_categoria)
listar.pack(side = LEFT)
buscar = Button(fr, text = "Buscar Evento", command = buscar_evento)
buscar.pack(side = LEFT)
top.mainloop()