From bb54837cf7f7d8e21cb606530041ca15bc6d11ff Mon Sep 17 00:00:00 2001 From: Redume Date: Fri, 8 Jul 2022 00:21:16 +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=20=D0=B0=D0=B2=D1=82=D0=BE=D0=B7=D0=B0=D0=BF=D1=83=D1=81?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 4 ++++ 2 files changed, 64 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/main.py b/main.py new file mode 100644 index 0000000..e00081f --- /dev/null +++ b/main.py @@ -0,0 +1,60 @@ +from bs4 import BeautifulSoup +from pyqadmin import admin +import requests + +import ctypes +import os +import urllib +import schedule +import winreg as reg +import getpass + + + + +class Nasa: + + def __init__(self): + self.url = "https://apod.nasa.gov/apod/" + self.headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'} + self.photoName = "everydayphotonasa.jpg" + + @staticmethod + @admin + def autorun(): + path = os.path.dirname(os.path.realpath(__file__)) + address = os.path.join(path, "main.py") + key_value = "Software/Microsoft/Windows/CurrentVersion/Run" + user = getpass.getuser() + key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, key_value, 0, reg.KEY_ALL_ACCESS) + reg.SetValueEx(key, user, 0, reg.REG_SZ, address) + reg.CloseKey(key) + + 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}") + + img = urllib.request.urlopen(self.url + lnk).read() + out = open(self.photoName, "wb") + out.write(img) + out.close() + + def set_wallpaper(self): + path = os.path.abspath(self.photoName) + ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0) + + def start(self): + self.autorun() + self.download_photo() + self.set_wallpaper() + + +if __name__ == "__main__": + schedule.every(1).days.do(Nasa().start) + while True: + schedule.run_pending() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9699a2f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +beautifulsoup4==4.11.1 +requests~=2.28.0 +schedule~=1.1.0 +pyqadmin~=1.0.0 \ No newline at end of file