Skip to content

Commit

Permalink
Merge pull request #60 from dsvdmeer/urllib3
Browse files Browse the repository at this point in the history
Use new API for urllib3
  • Loading branch information
MilesCrabbe authored Sep 24, 2021
2 parents 4da565a + 8728472 commit 2c748e4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apod/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import logging
import json
import re
import urllib3 as urllib
import urllib3
# import urllib.request

LOG = logging.getLogger(__name__)
Expand All @@ -21,6 +21,8 @@
# location of backing APOD service
BASE = 'https://apod.nasa.gov/apod/'

# Create urllib3 Pool Manager
http = urllib3.PoolManager()

# function for getting video thumbnails
def _get_thumbs(data):
Expand All @@ -37,9 +39,9 @@ def _get_thumbs(data):
vimeo_id_regex = re.compile("(?:/video/)(\d+)")
vimeo_id = vimeo_id_regex.findall(data)[0]
# make an API call to get thumbnail URL
with urllib.request.urlopen("https://vimeo.com/api/v2/video/" + vimeo_id + ".json") as url:
data = json.loads(url.read().decode())
video_thumb = data[0]['thumbnail_large']
vimeo_request = http.request("GET", "https://vimeo.com/api/v2/video/" + vimeo_id + ".json")
data = json.loads(vimeo_request.data.decode('utf-8'))
video_thumb = data[0]['thumbnail_large']
else:
# the thumbs parameter is True, but the APOD for the date is not a video, output nothing
video_thumb = ""
Expand Down

0 comments on commit 2c748e4

Please sign in to comment.