File size: 1,017 Bytes
04dc39e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests

github_base = "https://raw.githubusercontent.com/yashraizada/yelp-review-sense/main/images/"
business_logo_dir = "business%20logo/"
business_stars_dir = "stars/"
user_avatars_dir = "avatars/"
image_format = ".png"

def is_image(image_url: str) -> bool:
    image_formats = ["image/png", "image/jpg", "image/jpeg"]
    
    if requests.head(image_url).headers["content-type"] in image_formats:
        return True
    return False

def get_business_logo_url(business_name: str) -> str:
    business_logo_url = github_base + business_logo_dir + business_name + image_format
    yelp_logo_url = github_base + business_logo_dir + "yelp" + image_format
    
    if is_image(business_logo_url):
        return business_logo_url
    return yelp_logo_url

def get_business_stars_url(business_stars: str) -> str:
    return github_base + business_stars_dir + str(business_stars) + image_format

def get_user_avatar_url(user_id: str) -> str:
    return github_base + user_avatars_dir + "default" + image_format