From b81fcac344903add669a770223f1689c36e2b9e8 Mon Sep 17 00:00:00 2001 From: Redume Date: Sat, 9 Jul 2022 10:12:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BE=20=D1=82=D0=BE=D0=BC=20=D0=B5=D1=81=D0=BB=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=BA=20=D1=81=D0=B0=D0=B9=D1=82=D1=83=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=81=D0=B0=20=D1=81=20=D0=BA=D0=B0=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=D0=BA=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 6a39531..44e4214 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ class Nasa: @staticmethod def autorun(): path = os.path.dirname(os.path.realpath(__file__)) - address = os.path.join(path, "main.py") + address = os.path.join(path, "main.exe") key_value = "Software/Microsoft/Windows/CurrentVersion/Run" user = getpass.getuser() key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, key_value, 0, reg.KEY_ALL_ACCESS) @@ -29,17 +29,21 @@ class Nasa: print("Программа добавлена в автозапуск") def download_photo(self): - full_page = requests.get(self.url, headers=self.headers) - soup = BeautifulSoup(full_page.content, 'html.parser') - lnk = str - for link in soup.select("img"): - lnk = link["src"] - print(f"Сохарняю картинку — {self.url + lnk}") + try: + full_page = requests.get(self.url, headers=self.headers) + soup = BeautifulSoup(full_page.content, 'html.parser') + lnk = str + for link in soup.select("img"): + lnk = link["src"] + print(f"Сохарняю картинку — {self.url + lnk}") - img = urllib.request.urlopen(self.url + lnk).read() - out = open(self.photoName, "wb") - out.write(img) - out.close() + img = urllib.request.urlopen(self.url + lnk).read() + out = open(self.photoName, "wb") + out.write(img) + out.close() + self.set_wallpaper() + except requests.exceptions.ConnectionError: + return print("Нет подключения к интернету") def set_wallpaper(self): path = os.path.abspath(self.photoName) @@ -48,7 +52,6 @@ class Nasa: def start(self): self.download_photo() - self.set_wallpaper() print("Можно закрывать программу") if ctypes.windll.shell32.IsUserAnAdmin() != 0: elevate(show_console=False, graphical=False)