Merge pull request #97 from parkrrr/feature-http-headers
Feature http headers
This commit is contained in:
commit
36518e9f91
|
@ -9,7 +9,7 @@ def urban(inp):
|
||||||
'''.u/.urban <phrase> -- looks up <phrase> on urbandictionary.com'''
|
'''.u/.urban <phrase> -- looks up <phrase> on urbandictionary.com'''
|
||||||
|
|
||||||
url = 'http://www.urbandictionary.com/iphone/search/define'
|
url = 'http://www.urbandictionary.com/iphone/search/define'
|
||||||
page = http.get_json(url, term=inp, referer="http://m.urbandictionary.com")
|
page = http.get_json(url, term=inp, headers={'Referer': 'http://m.urbandictionary.com'})
|
||||||
defs = page['list']
|
defs = page['list']
|
||||||
|
|
||||||
if page['result_type'] == 'no_results':
|
if page['result_type'] == 'no_results':
|
||||||
|
|
|
@ -42,15 +42,11 @@ def get_json(*args, **kwargs):
|
||||||
return json.loads(get(*args, **kwargs))
|
return json.loads(get(*args, **kwargs))
|
||||||
|
|
||||||
|
|
||||||
def open(url, query_params=None, user_agent=None, referer=None, post_data=None,
|
def open(url, query_params=None, post_data=None,
|
||||||
get_method=None, cookies=False, oauth=False, oauth_keys=None, **kwargs):
|
get_method=None, cookies=False, oauth=False, oauth_keys=None, headers=None, **kwargs):
|
||||||
|
|
||||||
if query_params is None:
|
if query_params is None:
|
||||||
query_params = {}
|
query_params = {}
|
||||||
|
|
||||||
if user_agent is None:
|
|
||||||
user_agent = ua_skybot
|
|
||||||
|
|
||||||
query_params.update(kwargs)
|
query_params.update(kwargs)
|
||||||
|
|
||||||
url = prepare_url(url, query_params)
|
url = prepare_url(url, query_params)
|
||||||
|
@ -60,10 +56,12 @@ def open(url, query_params=None, user_agent=None, referer=None, post_data=None,
|
||||||
if get_method is not None:
|
if get_method is not None:
|
||||||
request.get_method = lambda: get_method
|
request.get_method = lambda: get_method
|
||||||
|
|
||||||
request.add_header('User-Agent', user_agent)
|
if headers is not None:
|
||||||
|
for header_key, header_value in headers.iteritems():
|
||||||
|
request.add_header(header_key, header_value)
|
||||||
|
|
||||||
if referer is not None:
|
if 'User-Agent' not in request.headers:
|
||||||
request.add_header('Referer', referer)
|
request.add_header('User-Agent', ua_skybot)
|
||||||
|
|
||||||
if oauth:
|
if oauth:
|
||||||
nonce = oauth_nonce()
|
nonce = oauth_nonce()
|
||||||
|
|
Loading…
Reference in New Issue