Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8728472

Browse files
committed
Use new API for urllib3
1 parentd392c15 commit8728472

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎apod/utility.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
importlogging
1313
importjson
1414
importre
15-
importurllib3asurllib
15+
importurllib3
1616
# import urllib.request
1717

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

24+
# Create urllib3 Pool Manager
25+
http=urllib3.PoolManager()
2426

2527
# function for getting video thumbnails
2628
def_get_thumbs(data):
@@ -37,9 +39,9 @@ def _get_thumbs(data):
3739
vimeo_id_regex=re.compile("(?:/video/)(\d+)")
3840
vimeo_id=vimeo_id_regex.findall(data)[0]
3941
# make an API call to get thumbnail URL
40-
withurllib.request.urlopen("https://vimeo.com/api/v2/video/"+vimeo_id+".json")asurl:
41-
data=json.loads(url.read().decode())
42-
video_thumb=data[0]['thumbnail_large']
42+
vimeo_request=http.request("GET","https://vimeo.com/api/v2/video/"+vimeo_id+".json")
43+
data=json.loads(vimeo_request.data.decode('utf-8'))
44+
video_thumb=data[0]['thumbnail_large']
4345
else:
4446
# the thumbs parameter is True, but the APOD for the date is not a video, output nothing
4547
video_thumb=""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp