Skip to content

Commit

Permalink
Merge pull request #2054 from feederbox826/ts-newimg
Browse files Browse the repository at this point in the history
Handle new TeamSkeet image paths
  • Loading branch information
feederbox826 authored Sep 30, 2024
2 parents dbd94d0 + fc08318 commit 0e8181d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions scrapers/Teamskeet/TeamskeetAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@
print("If you have pip (normally installed with python), run this command in a terminal (cmd): pip install requests", file=sys.stderr)
sys.exit()

def try_img(imgurl):
def try_url(url):
return requests.head(url).status_code == 200

def try_img_replacement(imgurl):
# members/full - 1600x900
# bio_big - 1500x844
# shared/hi - 1280x720
# shared/med - 765x430
for replacement in ['members/full', 'bio_big']:
for replacement in ['members/full', 'bio_big', 'shared/hi']:
newurl = imgurl.replace('shared/med', replacement)
if requests.head(newurl).status_code == 200:
return newurl
# try shared/hi on /tour url for MYLF
if 'mylf' in imgurl:
newurl = imgurl.replace('mylf/alm', 'mylf/alm/tour/pics').replace('shared/med', 'shared/hi')
if requests.head(newurl).status_code == 200:
if (try_url(newurl)):
return newurl
# try shared/hi on /tour url
# get the subsite name
subsite = imgurl.split("/")[4]
# replace with /tour/pics
tourHi = imgurl.replace(f"/{subsite}", f"/{subsite}/tour/pics").replace('shared/med', 'shared/hi')
if (try_url(tourHi)):
return tourHi
# fallback to original image
return imgurl

def save_json(api_json, url):
try:
Expand Down Expand Up @@ -231,7 +238,7 @@ def save_json(api_json, url):
# the scraped value and the higher resolution version.

# try to (and check) higher res images if possible
high_res = try_img(scene_api_json.get('img'))
high_res = try_img_replacement(scene_api_json.get('img'))

log.debug(f"Image before: {scrape['image']}")
log.debug(f"Image after: {high_res}")
Expand Down

0 comments on commit 0e8181d

Please sign in to comment.