Добавление тостов

This commit is contained in:
Данил 2022-07-12 12:11:17 +03:00
parent b81fcac344
commit c93795878c
4 changed files with 19 additions and 56 deletions

21
LICENSE
View file

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2022 Redume
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,26 +0,0 @@
## Инструкция
1. Скачайте все необходимые модули
```
pip install -r requirements.txt
```
2. Запустите main.py
```
python main.py
```
## Участники проекта ✨
<table>
<tr>
<td align="center">
<a href="https://github.com/redume"><img src="https://avatars.githubusercontent.com/u/49362257?v=3?s=100" width="100px;" alt=""/><br /><sub><b>Redume</b></sub></a><br />
<a href="#code" title="Код">💻</a>
<a href="#ideas" title="Идеи">🤔</a>
<a href="#projectManagement" title="Управление проектом">📆</a></td>
<td align="center"><a href="https://github.com/Murzify"><img src="https://avatars.githubusercontent.com/u/59001661?v=3?s=100" width="100px;" alt=""/><br /><sub><b>Murzify</b></sub></a><br />
<a href="#code" title="Помощь с кодом">💻</a>
</tr>
</table>

24
main.py
View file

@ -1,3 +1,5 @@
from win10toast import ToastNotifier
from bs4 import BeautifulSoup
from elevate import elevate
import requests
@ -16,9 +18,9 @@ class Nasa:
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"
self.toaster = ToastNotifier()
@staticmethod
def autorun():
def autorun(self):
path = os.path.dirname(os.path.realpath(__file__))
address = os.path.join(path, "main.exe")
key_value = "Software/Microsoft/Windows/CurrentVersion/Run"
@ -26,7 +28,10 @@ class Nasa:
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)
print("Программа добавлена в автозапуск")
self.toaster.show_toast("EveryDayPhotoNasa",
"Программа добавлена в автозапуск.",
duration=5,
icon_path=None)
def download_photo(self):
try:
@ -35,7 +40,6 @@ class Nasa:
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")
@ -43,20 +47,24 @@ class Nasa:
out.close()
self.set_wallpaper()
except requests.exceptions.ConnectionError:
return print("Нет подключения к интернету")
return self.toaster.show_toast("EveryDayPhotoNasa",
"Не получилось подключится к сайту, проверьте подключение к интернету.",
duration=5,
icon_path=None)
def set_wallpaper(self):
path = os.path.abspath(self.photoName)
print("Установлено фоновое изображение")
ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0)
self.toaster.show_toast("EveryDayPhotoNasa",
"Обои поставлены.",
duration=5,
icon_path=None)
def start(self):
self.download_photo()
print("Можно закрывать программу")
if ctypes.windll.shell32.IsUserAnAdmin() != 0:
elevate(show_console=False, graphical=False)
self.autorun()
print("Программа добавлена в автозапуск, можете закрывать программу")
if __name__ == "__main__":

View file

@ -1,4 +1,6 @@
beautifulsoup4==4.11.1
requests~=2.28.0
schedule~=1.1.0
elevate~=0.1.3
elevate~=0.1.3
future~=0.18.2
win10toast~=0.9