Created
July 7, 2017 10:54
-
-
Save ihfazhillah/de6c73d76399d2e1c050c95422bb64ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# di https://gitlab.com/ihfazhillah/imagescrape-web/blob/master/scraper/utils/requests.py | |
# ubah jadi | |
class Request(object): | |
"""Represents a requests object""" | |
def __init__(self, expire_after=None, *args, **kwargs): | |
""" | |
params: | |
- expire_after: int in seconds | |
""" | |
self.expire_after = expire_after or EXPIRE | |
# 29/3/2017 disable cache, karena tidak fleksibel | |
# requests_cache.install_cache(path.join(BASE_PATH, 'cache'), | |
# 'sqlite', expire_after=expire_after) | |
def get(self, url): | |
"""params: | |
- url : a valid url you want to request. | |
Return: | |
dictionary object from json""" | |
# ubah yang ini | |
# resp = requests.get(url) | |
s = requests.Session() | |
s.mount("http://", requests.adapters.HTTPAdapters(max_retries=100)) | |
resp = s.get(url) | |
if resp.status_code is 200: | |
return resp.json() | |
else: | |
raise ValueError("Current status code is %s, not 200" | |
% resp.status_code) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment