This commit is contained in:
Phill Ridout 2018-06-08 21:55:20 +01:00
parent 03400afc7c
commit 2e02060707
2 changed files with 8 additions and 8 deletions

View File

@ -109,14 +109,15 @@ def get_user_agent():
return browser_list[random_index] return browser_list[random_index]
def get_web_page(url, headers=None, update_openlp=False, proxy_mode=None): def get_web_page(url, headers=None, update_openlp=False, proxy=None):
""" """
Attempts to download the webpage at url and returns that page or None. Attempts to download the webpage at url and returns that page or None.
:param url: The URL to be downloaded. :param url: The URL to be downloaded.
:param header: An optional HTTP header to pass in the request to the web server. :param dict | None headers: An optional HTTP header to pass in the request to the web server.
:param update_openlp: Tells OpenLP to update itself if the page is successfully downloaded. :param update_openlp: Tells OpenLP to update itself if the page is successfully downloaded. Defaults to False.
Defaults to False. :param dict | ProxyMode | None proxy: ProxyMode enum or a dictionary containing the proxy servers, with their types
as the key e.g. {'http': 'http://proxyserver:port', 'https': 'https://proxyserver:port'}
""" """
if not url: if not url:
return None return None
@ -124,13 +125,13 @@ def get_web_page(url, headers=None, update_openlp=False, proxy_mode=None):
headers = {} headers = {}
if 'user-agent' not in [key.lower() for key in headers.keys()]: if 'user-agent' not in [key.lower() for key in headers.keys()]:
headers['User-Agent'] = get_user_agent() headers['User-Agent'] = get_user_agent()
if proxy_mode is None: if not isinstance(proxy, dict):
proxies = get_proxy_settings(mode=proxy_mode) proxy = get_proxy_settings(mode=proxy)
log.debug('Downloading URL = %s' % url) log.debug('Downloading URL = %s' % url)
retries = 0 retries = 0
while retries < CONNECTION_RETRIES: while retries < CONNECTION_RETRIES:
try: try:
response = requests.get(url, headers=headers, proxies=proxies, timeout=float(CONNECTION_TIMEOUT)) response = requests.get(url, headers=headers, proxies=proxy, timeout=float(CONNECTION_TIMEOUT))
log.debug('Downloaded page {url}'.format(url=response.url)) log.debug('Downloaded page {url}'.format(url=response.url))
break break
except OSError: except OSError:

View File

@ -199,7 +199,6 @@ def get_repo_name():
""" """
This returns the name of branch of the working directory. For example it returns *lp:~googol/openlp/render*. This returns the name of branch of the working directory. For example it returns *lp:~googol/openlp/render*.
""" """
return 'lp:~phill-ridout/openlp/proxies'
# Run the bzr command. # Run the bzr command.
bzr = Popen(('bzr', 'info'), stdout=PIPE, stderr=PIPE) bzr = Popen(('bzr', 'info'), stdout=PIPE, stderr=PIPE)
raw_output, error = bzr.communicate() raw_output, error = bzr.communicate()