Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
flickowoa committed Jan 15, 2024
1 parent 7ca2684 commit f930eb8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions update_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def gen_readme(name,repo,branch,img_files,img_urls):
if len(img_urls) >= 2:
img_urls = img_urls[:2]
for img in img_urls:
r += f"![{name}]({img})\n"
r += f"\n![{name}]({img})\n"
elif img_files:
if len(img_files) >= 2:
img_files = img_files[:2]
for img in img_files:
r += f"{repo}/blob/{branch}/{img}?raw=true\n"
r += f"\n{repo}/blob/{branch}/{img}?raw=true\n"

return r

Expand Down Expand Up @@ -60,7 +60,7 @@ def find_img_tags(rdme):
urls = []
imgs = re.findall("<img.*src=\"(.*?)\"",rdme)
for url in imgs:
if len(url) > 1: urls.append(url[0])
if url.startswith("http"): urls.append(url)
return urls

def find_urls(rdme):
Expand All @@ -69,10 +69,18 @@ def find_urls(rdme):

# fetch image and sort on size
images = {}
for url in [*md,*html]:
for i,url in enumerate([*md,*html]):
im = requests.get(url)
if im.status_code == 200:
im = Image.open(im.raw)
#check if image is valid
#save img to /tmp
with open(f"/tmp/{i}","wb") as f:
f.write(im.content)
try:
im = Image.open(f"/tmp/{i}")
except:
print("error opening image")
continue
images[url] = sum(im.size)
else:
print("error fetching image")
Expand Down Expand Up @@ -109,4 +117,3 @@ def find_urls(rdme):




0 comments on commit f930eb8

Please sign in to comment.