From 5112439712748d61af3b6e5d7d933bcf22657618 Mon Sep 17 00:00:00 2001 From: Shikiryu Date: Fri, 13 Sep 2024 00:59:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Add=20Quickposes=20model=20downl?= =?UTF-8?q?oad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- src/window/app.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2fcfc81..c0f2b03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ pyinstaller==5.13.1 pygame~=2.4.0 customtkinter~=5.1.3 configparser~=5.3.0 -CTkToolTip~=0.4 \ No newline at end of file +CTkToolTip~=0.4 +requests~=2.32.3 \ No newline at end of file diff --git a/src/window/app.py b/src/window/app.py index eb95851..50752e7 100644 --- a/src/window/app.py +++ b/src/window/app.py @@ -1,8 +1,16 @@ +import io +import os +import tempfile import tkinter from pathlib import Path from tkinter import * from tkinter import filedialog + +from datetime import datetime import customtkinter +import requests +from PIL import Image + from src.entity.config import Config from src.util import Util from src.window.image import ImageWindow @@ -25,6 +33,10 @@ class App: self.title = customtkinter.CTkLabel(root, text="Drawing Training") self.title.pack() + self.download_from_reference = customtkinter.CTkButton(root, text="Download 3 images from sketch daily", + command=self.download_from_reference) + self.download_from_reference.pack() + self.folder_selector = customtkinter.CTkButton(root, text="Select a folder", command=self.select_folder) self.folder_selector.pack() @@ -49,7 +61,8 @@ class App: self.buttons = [] for i, timer in enumerate(timers): - new_button = customtkinter.CTkButton(self.button_frame, width=10, text=timer, command=lambda t=timer: self.set_timer_in_seconds(t)) + new_button = customtkinter.CTkButton(self.button_frame, width=10, text=timer, + command=lambda t=timer: self.set_timer_in_seconds(t)) new_button.pack(side=tkinter.LEFT, fill=X, expand=True) self.buttons.append(new_button) @@ -83,6 +96,31 @@ class App: self.find_images_in_folder() self.check_lets_draw() + def download_from_reference(self): + dt = datetime.now() + ts = int(datetime.timestamp(dt)) + url = 'https://quickposes.com/ajax/getPosesForSlider/Chiaroscuro?_=' + str(ts) + + resp_json = requests.get(url=url) + if resp_json.status_code == 200: + data = resp_json.json() + c = 0 + for src in data: + if c >= 3: + break + buffer = tempfile.SpooledTemporaryFile(max_size=1e9) + r = requests.get('https://quickposes.com/assets/poses/' + src['src'], stream=True) + if r.status_code == 200: + downloaded = 0 + for chunk in r.iter_content(chunk_size=1024): + downloaded += len(chunk) + buffer.write(chunk) + buffer.seek(0) + i = Image.open(io.BytesIO(buffer.read())) + i.save(os.path.join(self.selected_folder, src['src']), quality=85) + buffer.close() + c += 1 + def find_images_in_folder(self): if Path(self.selected_folder).exists(): self.found_images = list( @@ -99,7 +137,8 @@ class App: def set_timer_in_seconds(self, user_data): # resetting buttons states for button in self.buttons: - button.configure(fg_color=(Util.get_default_button_color() if user_data != button.cget("text") else Util.get_default_active_button_color())) + button.configure(fg_color=(Util.get_default_button_color() if user_data != button.cget( + "text") else Util.get_default_active_button_color())) self.custom = False if user_data == "Custom":