Skip to content

Commit

Permalink
Fixed some calls by adding user agents
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelcortez committed Jan 26, 2025
1 parent c4d8702 commit f0136b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name="updater",
version="0.3.0",
version="0.3.1",
author="MCVSoftware",
author_email="support@mcvsoftware.com",
url="https://github.com/mcvsoftware/updater",
Expand Down
12 changes: 8 additions & 4 deletions updater/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __init__(self, endpoint: str, current_version: str, app_name: str = "", pass
self.current_version = current_version
self.app_name = app_name
self.password = password
self.update_version = None
self.update_description = None

def get_update_information(self) -> Dict[str, Any]:
""" Calls the provided URL endpoint and returns information about the available update sent by the server. The format should adhere to the json specifications for updates.
Expand All @@ -46,8 +48,10 @@ def get_update_information(self) -> Dict[str, Any]:
:rtype: dict
"""
response = urllib.request.urlopen(self.endpoint)
data: str = response.read()
headers = {"User-Agent": f"{self.app_name}/{self.current_version}"}
req = urllib.request.Request(self.endpoint, headers=headers)
with urllib.request.urlopen(req) as response:
data: str = response.read()
content: Dict[str, Any] = json.loads(data)
return content

Expand Down Expand Up @@ -97,8 +101,8 @@ def download_update(self, update_url: str, update_destination: str, chunk_size:
def _download_callback(transferred_blocks, block_size, total_size):
total_downloaded = transferred_blocks*block_size
pub.sendMessage("updater.update-progress", total_downloaded=total_downloaded, total_size=total_size)

filename, headers = urllib.request.urlretrieve(update_url, update_destination, _download_callback)
request = urllib.request.Request(update_url, headers={"User-Agent": f"{self.app_name}/{self.current_version}"})
filename, headers = urllib.request.urlretrieve(request, update_destination, _download_callback)
log.debug("Update downloaded")
return update_destination

Expand Down
4 changes: 3 additions & 1 deletion updater/wxupdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def on_new_update_available(self) -> bool:
:returns: True if user wants to download the update, False otherwise.
:rtype: bool
"""
dialog = wx.MessageDialog(None, self.new_update_msg, self.new_update_title, style=wx.YES|wx.NO|wx.ICON_WARNING)
dialog = wx.MessageDialog(None, self.new_update_msg.format(app_name=self.app_name, update_version=self.update_version, update_description=self.update_description), self.new_update_title.format(app_name=self.app_name), style=wx.YES|wx.NO|wx.ICON_WARNING)
response = dialog.ShowModal()
dialog.Destroy()
if response == wx.ID_YES:
Expand Down Expand Up @@ -156,6 +156,8 @@ def check_for_updates(self) -> None:
version_data = self.get_version_data(update_info)
if version_data[0] == False:
return None
self.update_version = version_data[0]
self.update_description = version_data[1]
response = self.on_new_update_available()
if response == False:
return None
Expand Down

0 comments on commit f0136b8

Please sign in to comment.