-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
101 lines (70 loc) · 2.59 KB
/
gui.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
import tkinter as tk
import subprocess
neopets_list = [
"nimmo", "scorchio","jubjub","grarrl",
"skeith","korbat","lenny","wocky",
"bruce", "kiko","kau","usul",
"aisha","chia","eyrie","tuskaninny",
"flotsam","jetsam","kacheek","uni","buzz","lupe",
"elephante","gelert","mynci","kyrii",
"peophin","quiggle","shoyru","acara",
"zafara","blumaroo","techo","moehog",
"poogle", "kougra", "grundo", "koi",
"meerca", "chomby", "pteri", "krawk",
"tonu", "draik", "lxi", "yurble",
"ruki", "bori", "hissi", "lutari",
"xweetok", "ogrin", "gnorbu", "vandagyre",
]
root = tk.Tk()
root.title("Neopets Scraper")
root.geometry("700x500")
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
def add_selected_pet():
selection = neopets_listbox.curselection()
if selection:
selected_pet = neopets_listbox.get(selection[0])
if selected_pet not in selected_listbox.get(0, tk.END):
selected_listbox.insert(tk.END, selected_pet)
else:
print("Pet already in list")
else:
print("No selection")
def remove_selected_pet():
selection = selected_listbox.curselection()
if selection:
selected_listbox.delete(selection[0])
else:
print("No selection")
def run_scraper():
# Retrieve selected pets from selected_listbox
selected_pets = selected_listbox.get(0, tk.END)
if not selected_pets:
print("No pets selected")
return
# assemble list of pets to feed the scraper
pets_arguments = " ".join(selected_pets)
# Run scraper
subprocess.run(["python", "neopets.py", pets_arguments])
add_button = tk.Button(root, text="Add Neopet", command=add_selected_pet)
add_button.pack(side=tk.LEFT)
remove_button = tk.Button(root, text="Remove Neopet", command=remove_selected_pet)
remove_button.pack(side=tk.RIGHT)
run_scraper_button = tk.Button(root, text="Run Scraper", command=run_scraper)
run_scraper_button.pack(side=tk.BOTTOM)
# create the Neopets neopets_listbox
neopets_listbox = tk.Listbox(root, width=15, yscrollcommand=scrollbar.set)
for pet in neopets_list:
neopets_listbox.insert(tk.END, pet)
neopets_listbox.pack(side=tk.LEFT, fill=tk.BOTH)
scrollbar.config(command=neopets_listbox.yview)
# Second listbox for selected pets
selected_listbox = tk.Listbox(root, width=15)
selected_listbox.pack(side=tk.RIGHT, fill=tk.BOTH)
def get_neopets_listbox_selection():
selection = neopets_listbox.curselection()
if selection:
print(neopets_listbox.get(selection[0]))
else:
print("No selection")
root.mainloop()