Spaces:
Sleeping
Sleeping
Commit
路
b7f1ecd
1
Parent(s):
3d1bd05
AppState product_name
Browse files
app.py
CHANGED
@@ -15,6 +15,9 @@ app = FastAPI()
|
|
15 |
async def read_root():
|
16 |
return {"message": "Hello, World!"}
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
class LoginException(HTTPException):
|
20 |
"""Custom exception for login failures."""
|
@@ -55,8 +58,8 @@ async def siloshot_making(page, fabric_name):
|
|
55 |
# Zbieranie nazwy produktu z nag艂贸wka h1 o klasie ng-star-inserted
|
56 |
product_name_element = soup.find('h1', class_='ng-star-inserted')
|
57 |
if product_name_element:
|
58 |
-
product_name = product_name_element.text.strip()
|
59 |
-
print(f'Product name collected: {product_name}')
|
60 |
else:
|
61 |
raise Exception('Product name not found in the page.')
|
62 |
|
@@ -153,7 +156,7 @@ async def download_images(img_urls, fabric_name):
|
|
153 |
if angle_match:
|
154 |
# Create a file name using the product name and the angle
|
155 |
angle_value = angle_match.group(1)
|
156 |
-
img_name = f"{angle_value}_{fabric_name}.png"
|
157 |
else:
|
158 |
# Default file name if the angle is not found
|
159 |
img_name = "product_unknown.jpg"
|
@@ -200,7 +203,7 @@ async def process_images(username, password, product_url, fabric_name):
|
|
200 |
|
201 |
img = await siloshot_making(page, fabric_name)
|
202 |
img_urls = generate_urls(img, start_angle=0, end_angle=360, step=10)
|
203 |
-
zip_buffer = await download_images(img_urls, fabric_name)
|
204 |
await browser.close()
|
205 |
return zip_buffer
|
206 |
|
|
|
15 |
async def read_root():
|
16 |
return {"message": "Hello, World!"}
|
17 |
|
18 |
+
class AppState:
|
19 |
+
product_name = None
|
20 |
+
|
21 |
|
22 |
class LoginException(HTTPException):
|
23 |
"""Custom exception for login failures."""
|
|
|
58 |
# Zbieranie nazwy produktu z nag艂贸wka h1 o klasie ng-star-inserted
|
59 |
product_name_element = soup.find('h1', class_='ng-star-inserted')
|
60 |
if product_name_element:
|
61 |
+
AppState.product_name = product_name_element.text.strip()
|
62 |
+
print(f'Product name collected: {AppState.product_name}')
|
63 |
else:
|
64 |
raise Exception('Product name not found in the page.')
|
65 |
|
|
|
156 |
if angle_match:
|
157 |
# Create a file name using the product name and the angle
|
158 |
angle_value = angle_match.group(1)
|
159 |
+
img_name = f"{AppState.product_name}_{angle_value}_{fabric_name}.png"
|
160 |
else:
|
161 |
# Default file name if the angle is not found
|
162 |
img_name = "product_unknown.jpg"
|
|
|
203 |
|
204 |
img = await siloshot_making(page, fabric_name)
|
205 |
img_urls = generate_urls(img, start_angle=0, end_angle=360, step=10)
|
206 |
+
zip_buffer = await download_images(img_urls, fabric_name, AppState.product_name)
|
207 |
await browser.close()
|
208 |
return zip_buffer
|
209 |
|