Spaces:
Build error
Build error
Commit
•
04dc39e
1
Parent(s):
c755746
Create images.py
Browse files
images.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
github_base = "https://raw.githubusercontent.com/yashraizada/yelp-review-sense/main/images/"
|
4 |
+
business_logo_dir = "business%20logo/"
|
5 |
+
business_stars_dir = "stars/"
|
6 |
+
user_avatars_dir = "avatars/"
|
7 |
+
image_format = ".png"
|
8 |
+
|
9 |
+
def is_image(image_url: str) -> bool:
|
10 |
+
image_formats = ["image/png", "image/jpg", "image/jpeg"]
|
11 |
+
|
12 |
+
if requests.head(image_url).headers["content-type"] in image_formats:
|
13 |
+
return True
|
14 |
+
return False
|
15 |
+
|
16 |
+
def get_business_logo_url(business_name: str) -> str:
|
17 |
+
business_logo_url = github_base + business_logo_dir + business_name + image_format
|
18 |
+
yelp_logo_url = github_base + business_logo_dir + "yelp" + image_format
|
19 |
+
|
20 |
+
if is_image(business_logo_url):
|
21 |
+
return business_logo_url
|
22 |
+
return yelp_logo_url
|
23 |
+
|
24 |
+
def get_business_stars_url(business_stars: str) -> str:
|
25 |
+
return github_base + business_stars_dir + str(business_stars) + image_format
|
26 |
+
|
27 |
+
def get_user_avatar_url(user_id: str) -> str:
|
28 |
+
return github_base + user_avatars_dir + "default" + image_format
|