executable_weather.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/python
  2. import subprocess
  3. from pathlib import Path
  4. import json
  5. import pickle
  6. import time
  7. import threading
  8. import requests
  9. from bs4 import BeautifulSoup
  10. OUT = f"{Path.home()}/.config/hypr/store/dynamic_out.txt"
  11. # PREV_PATH = f"{Path.home()}/.config/hypr/store/prev.txt"
  12. prev = None
  13. city = "sergiyev posad"
  14. # creating url and requests instance
  15. url = "https://www.google.com/search?q="+"weather"+city+"&hl=en"
  16. html = requests.get(url).content
  17. def print(ar):
  18. with open(OUT,"w") as f:
  19. f.write(json.dumps(ar))
  20. # with open(f"{Path.home()}/.config/hypr/im_here","w") as f:
  21. # f.write("")
  22. global PAUSE_MEDIA
  23. PAUSE_MEDIA = False
  24. def notif_watcher():
  25. soup = BeautifulSoup(html, 'html.parser')
  26. temp = soup.find('div', attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text
  27. str_temp = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text
  28. data = str_temp.split('\n')
  29. sky = data[1]
  30. listdiv = soup.findAll('div', attrs={'class': 'BNeawe s3v9rd AP7Wnd'})
  31. strd = listdiv[5].text
  32. pos = strd.find('Wind')
  33. other_data = strd[pos:]
  34. print({"class": "playing", "text": f"{sky.lower()} {temp}"})
  35. time.sleep(60)
  36. def start_watcher():
  37. while 1:
  38. notif_watcher()
  39. time.sleep(0.5)
  40. t = threading.Thread(target=start_watcher)
  41. t.start()
  42. t.join()