Skip to content

Commit 6576a1c

Browse files
committed
final adjustmenst for version 1.0
1 parent 1b27ecd commit 6576a1c

3 files changed

Lines changed: 111 additions & 108 deletions

File tree

grabber.py

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,34 @@
1-
from __future__ import unicode_literals
1+
import os
2+
from tkinter import Label
3+
from tkinter import StringVar
4+
from tkinter import Grid
5+
from tkinter import Tk
6+
from tkinter import OptionMenu
7+
from tkinter import Entry
8+
from tkinter import Button
9+
from tkinter import PhotoImage
10+
from misc import *
11+
from tkinter import *
12+
from tkinter.ttk import *
13+
from ttkthemes import themed_tk as tk
214
from pybooru import Moebooru
315
import requests
4-
import os
5-
import psutil
6-
7-
def checkDiskSpace():
8-
path = "/"
9-
bytes_avail = psutil.disk_usage(path).free
10-
gigabytes_avail = bytes_avail / 1024 / 1024 / 1024
11-
return gigabytes_avail
12-
13-
def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\r"):
14-
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
15-
filledLength = int(length * iteration // total)
16-
bar = fill * filledLength + '-' * (length - filledLength)
17-
print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd)
18-
if iteration == total:
19-
print()
2016

2117
def grab(*grab_tags:str, grab_count:int, source:str):
2218
client = Moebooru(site_url="https://"+source)
2319
posts = client.post_list(tags=grab_tags, limit=grab_count)
2420
count = 0
25-
os.system("cls")
26-
print("\u001b[31;1m" + " __ __ _ _ ___ ")
27-
print("\u001b[31;1m" + "| \ \<_>| |__ ___ | . \ ___ ___ ___ ")
28-
print("\u001b[31;1m" + "| || || / /<_> || _// . \| . \| . \ ")
29-
print("\u001b[31;1m" + "|_|_|_||_||_\_\<___||_| \___/| _/| _/ ")
30-
print("\u001b[31;1m" + " |_| |_| ")
31-
print("\u001b[32m" + "Start grabbing...")
21+
printAwesomeASCII()
3222
if(len(grab_count) == 0):
3323
print("No grab count specified!")
3424
print("returning...")
35-
os.system('python gui.py')
25+
gui()
3626
else:
3727
if((float(checkDiskSpace())-(float(grab_count)*5/1024)) >= 0):
3828
if(not posts):
3929
print("There wasn't any post to grab!")
4030
print("returning...")
41-
os.system('python gui.py')
31+
gui()
4232
else:
4333
print("=============================================================")
4434
printProgressBar(0, int(grab_count), prefix = 'Progress:', suffix = 'Complete', length = 50)
@@ -53,8 +43,75 @@ def grab(*grab_tags:str, grab_count:int, source:str):
5343
printProgressBar(count, int(grab_count), prefix="Progress:", suffix="Complete", length=50)
5444
print("=============================================================")
5545
print("Finished grabbing")
56-
os.system('python gui.py')
46+
gui()
5747
else:
5848
print("Not enough disk space!")
5949
print("returning...")
60-
os.system('python gui.py')
50+
gui()
51+
52+
def start_grabbing(window, source, tags, count, c1, c2, c3):
53+
window.destroy()
54+
if c3 == 1:
55+
tags += " rating:s"
56+
else:
57+
if c1 == 1:
58+
tags += " rating:e "
59+
if c2 == 1:
60+
tags += "rating:q "
61+
grab(tags, grab_count=count, source=source)
62+
63+
def callback(input):
64+
if str.isdigit(input) or input == "":
65+
maxlength = 5
66+
if len(input) is None or len(input) <= maxlength:
67+
return True
68+
else:
69+
return False
70+
else:
71+
return False
72+
73+
def gui():
74+
window = tk.ThemedTk()
75+
window.get_themes()
76+
window.set_theme("black")
77+
window.geometry("400x400")
78+
window.title("Moebooru Image Grabber - MikaPopp")
79+
window.resizable(False, False)
80+
81+
source_list = ["Yande.re", "Konachan.com"]
82+
value_option_source = StringVar()
83+
84+
background_picture = PhotoImage(file=os.getcwd()+"/resources/bg.png")
85+
background_label = Label(image=background_picture)
86+
background_label.place(x=0, y=0, relwidth=1, relheight=1)
87+
label_source = Label(text="Source:", background="black")
88+
label_source.grid(row=0)
89+
dropdown_source = OptionMenu(window, value_option_source, source_list[0], *source_list)
90+
dropdown_source.grid(row=1)
91+
label_rating = Label(text="Rating (optional):", background="black")
92+
label_rating.grid(row=2)
93+
var_one = IntVar()
94+
var_two = IntVar()
95+
var_three = IntVar()
96+
check_rating_explicit = Checkbutton(window, text="Explicit", variable=var_one)
97+
check_rating_explicit.grid(row=3)
98+
check_rating_questionable = Checkbutton(window, text="Questionable", variable=var_two)
99+
check_rating_questionable.grid(row=4)
100+
check_rating_safe = Checkbutton(window, text="Safe", variable=var_three)
101+
check_rating_safe.grid(row=5)
102+
label_tags = Label(text="Tags (optional):", background="black")
103+
label_tags.grid(row=6)
104+
entry_tags = Entry(width=15)
105+
entry_tags.grid(row=7, padx=15)
106+
label_count = Label(text="Count:", background="black")
107+
label_count.grid(row=8)
108+
entry_count = Entry(window, width=15)
109+
reg = window.register(callback)
110+
entry_count.config(validate="key", validatecommand=(reg, "%P"))
111+
entry_count.grid(row=9)
112+
button_start = Button(text="Start", state=ACTIVE, width=4, command=lambda:start_grabbing(window=window, source=value_option_source.get(), tags=entry_tags.get(),
113+
count=entry_count.get(), c1=var_one.get(), c2=var_two.get(), c3=var_three.get()))
114+
button_start.grid(row=10)
115+
window.mainloop()
116+
117+
gui()

gui.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

misc.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import unicode_literals
2+
import os
3+
import psutil
4+
5+
def checkDiskSpace():
6+
path = "/"
7+
bytes_avail = psutil.disk_usage(path).free
8+
gigabytes_avail = bytes_avail / 1024 / 1024 / 1024
9+
return gigabytes_avail
10+
11+
def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\r"):
12+
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
13+
filledLength = int(length * iteration // total)
14+
bar = fill * filledLength + '-' * (length - filledLength)
15+
print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd)
16+
if iteration == total:
17+
print()
18+
19+
def printAwesomeASCII():
20+
os.system("cls")
21+
print("\u001b[31;1m" + " __ __ _ _ ___ ")
22+
print("\u001b[31;1m" + "| \ \<_>| |__ ___ | . \ ___ ___ ___ ")
23+
print("\u001b[31;1m" + "| || || / /<_> || _// . \| . \| . \ ")
24+
print("\u001b[31;1m" + "|_|_|_||_||_\_\<___||_| \___/| _/| _/ ")
25+
print("\u001b[31;1m" + " |_| |_| ")
26+
print("\u001b[32m" + "Start grabbing...")

0 commit comments

Comments
 (0)