Skip to content

Commit

Permalink
skip anything without a file URL re: #6
Browse files Browse the repository at this point in the history
  • Loading branch information
dphiffer committed May 24, 2024
1 parent 1903cb1 commit 89eea64
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions best_of_mltshp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def load_feed(url):
def get_media(entry):
url = re.search(r"https://mltshp.com/r/[a-zA-Z0-9]+", entry.description)
alt = re.search(r"alt=\"([^\"]*)\"", entry.description)
if not url or not alt:
return [None, None]
return [url[0], html.unescape(alt[1])]

def download_media(url):
Expand Down Expand Up @@ -127,6 +129,8 @@ def load_links():
links.append(entry.link)
save_links(links)
(url, alt_text) = get_media(entry)
if not url:
continue
(filename, content_type) = download_media(url)
attachment = upload_media(filename, content_type, alt_text)
os.remove(filename)
Expand Down

0 comments on commit 89eea64

Please sign in to comment.