From: LeonardoBizzoni Date: Thu, 11 Nov 2021 12:53:03 +0000 (+0100) Subject: initial windows support X-Git-Url: http://git.leonardobizzoni.com/?a=commitdiff_plain;h=68c652324ceff9ddbe3d1fd6708f086a25345fa0;p=holonotify initial windows support --- diff --git a/holonotify.py b/holonotify.py index cfb6dd6..dd8590d 100755 --- a/holonotify.py +++ b/holonotify.py @@ -1,9 +1,8 @@ #!/usr/bin/env python import os -import threading import time -import psutil +import platform import urllib.request import json @@ -14,6 +13,9 @@ liveAnnouced = list() live = list() ended = list() blacklist = list() +running = True +checkedPs = False +psCount = 0 def updateValues(): global live, ended, blacklist @@ -30,41 +32,55 @@ def main(): notBlacklist = True chName = ch["channel"]["name"].lower() + # check if the vtuber is in the blacklist for name in blacklist: if (name in chName): notBlacklist = False break - + # check if the live has already been announces and its not blacklisted if(chName not in liveAnnouced and notBlacklist): chIcon = utils.getIcon(chName) - os.system(f'''notify-send -i {chIcon} "{chName} is live!" "{ch["title"]}"''') - liveAnnouced.append(chName) + if(platform.system() == "Windows"): + from plyer import notification + notification.notify(title=chName + " is live!", message=ch["title"]) + else: + os.system(f'''notify-send -i {chIcon} "{chName} is live!" "{ch["title"]}"''') + + liveAnnouced.append(chName) + # check if the live has ended and remove it from the live already announced if(ch["yt_video_key"] in ended): liveAnnouced.remove(ch["channel"]["name"]) -if __name__ == "__main__": - running = True - checkedPs = False - psCount = 0 +def linuxCheckProc(): + global checkedPs, psCount, running + if checkedPs == False and platform.system() == "Linux": + import psutil + for pid in psutil.pids(): + try: + p = psutil.Process(pid) + if p.name() == "python": + if psCount >= 1: + running = False + break + if "holonotify" in p.cmdline()[1]: + psCount += 1 + except: + continue + checkedPs = True + +def windowsCheckProc(): + # TODO + pass + +if __name__ == "__main__": while running: main() # If there's another instance running, show who's live and quit - if checkedPs == False: - for pid in psutil.pids(): - try: - p = psutil.Process(pid) - if p.name() == "python": - if psCount >= 1: - running = False - break - if "holonotify" in p.cmdline()[1]: - psCount += 1 - except: - continue - checkedPs = True - + linuxCheckProc() + windowsCheckProc() + if running: time.sleep(60*5) diff --git a/utils.py b/utils.py index e76621b..c61ead1 100644 --- a/utils.py +++ b/utils.py @@ -1,7 +1,9 @@ import os +import platform def getBlacklist(): blacklist = list() + # TODO: path to blacklist on windows blacklistFile = os.path.expanduser("~") + "/.config/holoBlacklist" if (os.path.isfile(blacklistFile)): @@ -9,17 +11,17 @@ def getBlacklist(): for x in f.read().splitlines(): if(x == "fubuki" or x == "shirakami"): blacklist.append("フブキ") - elif(x == "mel"): - blacklist.append("夜空メルチャンネル") elif (x == "akirose" or x == "aki" or x == "rosenthal"): blacklist.append("アキロゼ") else: blacklist.append(x) - return blacklist def getIcon(name): - abspath = os.path.dirname(os.path.abspath(__file__)) + "/Icons/" + if(platform.system() == "Windows"): + abspath = os.path.dirname(os.path.abspath(__file__)) + "\\Icons\\" + else: + abspath = os.path.dirname(os.path.abspath(__file__)) + "/Icons/" # JP if ("フブキ" in name): @@ -85,7 +87,7 @@ def getIcon(name): elif ("botan" in name): return abspath + "botan.jpg" - # JP col cazzo + # JP males elif ("shien" in name): return abspath + "shien.jpg" elif ("oga" in name): @@ -120,7 +122,7 @@ def getIcon(name): return abspath + "amelia.jpg" elif ("irys" in name): return abspath + "irys.jpg" - elif ("sana" in name): + elif ("tsukumoto" in name): return abspath + "sana.jpg" elif ("fauna" in name): return abspath + "fauna.jpg"