Skip to content

Instantly share code, notes, and snippets.

@ayush--s
Created July 11, 2020 19:50
Show Gist options
  • Save ayush--s/0bee63b1851179c73e26cd9787668305 to your computer and use it in GitHub Desktop.
Save ayush--s/0bee63b1851179c73e26cd9787668305 to your computer and use it in GitHub Desktop.
import os
from datetime import date
import requests
from slugify import slugify
BASE = "https://www.bing.com"
URL = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt={}"
MARKETS = {"en-US", "en-GB", "ja-JP"}
def download(url, filename):
resp = requests.get(BASE + url)
if resp.status_code == 200:
filename = "{}.jpg".format(filename)
with open(filename, "wb") as fp:
fp.write(resp.content)
def handle_event(event, lambda_context):
for mrkt in MARKETS:
url = URL.format(mrkt)
resp = requests.get(url)
img = resp.json()["images"][0]
filename = slugify("{}-{}".format(img["startdate"], img["title"]))
download(img["url"], filename)
if __name__ == "__main__":
handle_event(None, None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment