diff options
author | Michael Kantor <michael@mikekantor.xyz> | 2024-01-09 22:02:20 -0500 |
---|---|---|
committer | Michael Kantor <michael@mikekantor.xyz> | 2024-01-09 22:02:20 -0500 |
commit | 270f3e6d77cc720b1b3f3c529b1b6aa5c63578a2 (patch) | |
tree | c65da331bc5306f820918f3a54ef51ac2ab746d9 /cusmodules |
Recreated git repo as screenshots were too large.
Diffstat (limited to 'cusmodules')
-rwxr-xr-x | cusmodules/appimg.py | 33 | ||||
-rwxr-xr-x | cusmodules/colors.py | 83 | ||||
-rwxr-xr-x | cusmodules/cuswidgets/ticker_gecko.py | 126 | ||||
-rwxr-xr-x | cusmodules/holiday.py | 50 | ||||
-rwxr-xr-x | cusmodules/wallpaper.py | 270 |
5 files changed, 562 insertions, 0 deletions
diff --git a/cusmodules/appimg.py b/cusmodules/appimg.py new file mode 100755 index 0000000..d0f420e --- /dev/null +++ b/cusmodules/appimg.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +import os +import re +from wallpaper import dmenu + +def main(): + home = os.path.expanduser('~') + appdir = home + '/Applications/' + apps = os.popen(f"ls {appdir}").read().strip('\n') + appslist = apps.split('\n') + appsec = re.sub('[0-9]|x86|_|\.|\-|AppImage', '', apps) + app = dmenu(appsec, "Apps:") + + if app == '': + return 1 + + for i in appslist: + try: + fnm = re.search(app, i).span() + print(fnm) + id_ = appslist.index(i) + print(id_) + + except Exception as e: + print(e) + pass + + appnm = appslist[id_] + os.system(appdir + appnm) + +if __name__ == '__main__': + main() + diff --git a/cusmodules/colors.py b/cusmodules/colors.py new file mode 100755 index 0000000..295fbd4 --- /dev/null +++ b/cusmodules/colors.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +import os +import sys +import json +import wallpaper +from pathlib import Path +from random import randint +from subprocess import run + +def random(colors): + colorcount = len(colors) - 1 + ranint = randint(0, colorcount) + rancol = colors[ranint] + + return rancol + +def setColor(home, color_dir, choice, **kwargs): + os.system(f'wal --theme {color_dir}/{choice}') + + with open(f"{home}/.cache/wal/colors.json", 'r') as f: + data = json.load(f) + + top_color = data["colors"].get('color8') + + bottom_color = data["colors"].get('color6') + + wallpaper.gen_pylogo(top_color, bottom_color) + + try: + if kwargs["norestart"] == True: + return 0 + + except: + pass + + #run(['qtile', 'shell', '-c', 'restart()']) + #run(['kill', '-SIGUSR1', os.popen('pidof qtile').read().strip('\n')]) + run(['qtile', 'shell', '-c', 'reload_config()']) + run([f'{home}/.local/bin/pywalfox', 'update']) + + return 0 + +def main(argc, argv): + home = str(Path.home()) + color_dir = f'{home}/.config/qtile/colors' + + try: + if argv[0] == '-c': + choice = argv[1] + + else: + choice = os.popen(f'ls {color_dir} | dmenu -p "Color:"').read().strip("\n") + + except: + choice = os.popen(f'ls {color_dir} | dmenu -p "Color:"').read().strip("\n") + + + if "" == choice: + return 0 + + elif "random" in choice: + colors = os.popen(f'ls {color_dir}').read().strip('\n').split('\n') + choice = random(colors) + + else: + pass + + setColor(home, color_dir, choice) + + return 0 + +if __name__ == '__main__': + sys.argv.pop(0) + argc = int(len(sys.argv)) + + try: + argv = sys.argv + + except: + argv = [] + + main(argc, argv) + diff --git a/cusmodules/cuswidgets/ticker_gecko.py b/cusmodules/cuswidgets/ticker_gecko.py new file mode 100755 index 0000000..1b7d1ee --- /dev/null +++ b/cusmodules/cuswidgets/ticker_gecko.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +import os +import sys +import json +import time +import requests +import subprocess +from datetime import datetime +from threading import Thread + +def match(currency): + currencies = { + "BTC": "bitcoin", + "ETH": "ethereum", + "XRP": "xrp", + "LTC": "litecoin", + "BCH": "bitcoin-cash", + "XMR": "monero", + "DOGE": "dogecoin" + } + + return currencies[currency] + +def Gecko(currs): + #prices = '' + prices = {} + + for i in currs: + curr = match(i) + + source = requests.get(f'https://api.coingecko.com/api/v3/coins/{curr}/').text + + data = json.loads(source) + + price = str(data['market_data']['current_price']['usd']) + + try: + if len(price[:price.index('.')]) > 3: + price = price[:2] + ',' + price[2:] + + except: + price = price[:2] + ',' + price[2:] + + price = '$' + price + + price = {i: price} + + prices.update(price) + + with open('/tmp/crprices.json', 'w') as f: + f.write(str(prices).replace("'", '"')) + +def main(): + global crpos + home = os.path.expanduser('~') + currs = [] + priced = '' + + try: + crpos += 1 + + except: + crpos = 0 + + try: + with open('/tmp/crprices.json', 'r') as f: + prices_str = f.read() + prices = json.loads(prices_str) + + for i in prices: + currs += i + + for i in prices: + if currs[len(currs) - 1] == i: + price = f'{i}: {prices[i]} |' + + else: + price = f'{i}: {prices[i]} | ' + + priced += price + + leng = len(priced) + + #print(crpos >= leng) + if crpos >= leng: + crpos = 0 + + crprices = f"{priced[crpos:]} {priced[:crpos]}" + + #print(priced) + #print(crpos) + #print(leng) + #print(crprices) + #print(crprices[:15], '\n') + return crprices[:15] + + except Exception as e: + with open(f'{home}/.local/share/ticker_gecko/ticker_gecko.log', 'w') as f: + f.write(e) + + return f'ERROR! Check "{home}/.local/share/ticker_gecko/ticker_gecko.log".' + +if __name__ == '__main__': + if sys.argv[1] == '--help' or sys.argv[1] == '-help' or sys.argv[1] == '--h' or sys.argv[1] == '-h': + print('Usage:\n\tStart server by running command: "/path/to/ticker_gecko.py".\n\tPut abbreviations of crypto in arguments: "/path/to/ticker_gecko.py BTC LTC" (will get price for bitcoin and litecoin)\n\tAdd main function to GenPollText widget in config.py: "\n\t\timport ticker_gecko\n\t\twidget.GenPollText(\n\t\t\tfunc=ticker_gecko.main,\n\t\t\tupdate_interval= 0.5),"') + sys.exit(0) + + currs = [] + argc = len(sys.argv) + for i in range(argc): + if i == 0: + pass + + else: + currs.append(sys.argv[i]) + + while True: + Gecko(currs) + + with open('/tmp/crprices.json', 'r') as f: + leng = len(f.read()) + + repeat_time = leng - ((len(currs) - 1) * 5) + + time.sleep(repeat_time) + diff --git a/cusmodules/holiday.py b/cusmodules/holiday.py new file mode 100755 index 0000000..a65a2a9 --- /dev/null +++ b/cusmodules/holiday.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +import os +import sys +from subprocess import run +from datetime import datetime +from os.path import expanduser +from calendar import monthrange + +def getHoliday(month, day): + if month == 1 and day == 1: + return 'none' + #return "new_year" + + #Arch birthday + elif month == 3 and day == 11: + return 'none' + #return 'arch_birthday' + + #April fools + elif month == 4 and day == 1: + return 'none' + #return 'april_fools' + + #Halloween + elif month == 10: + return 'halloween' + + #Thanksgiving + elif month == 11 and datetime.now().weekday() + 20 == day: + return 'thanksgiving' + + #Christmas + elif month == 12: + return 'xmas' + + else: + return 'none' + +def main(): + home = expanduser('~') + month = datetime.now().month + day = datetime.now().day + holiday = getHoliday(month, day) + + return holiday + +if __name__ == "__main__": + print(main()) + + sys.exit(0) diff --git a/cusmodules/wallpaper.py b/cusmodules/wallpaper.py new file mode 100755 index 0000000..8f02e4d --- /dev/null +++ b/cusmodules/wallpaper.py @@ -0,0 +1,270 @@ +#!/usr/bin/env python +import os +import sys +import json +import toml +import signal +from PIL import Image +from pathlib import Path +from random import randint +from subprocess import run + +import colors + +def dmenu(input_, prompt): + result = os.popen(f'echo "{input_}" | dmenu -p "{prompt}"').read().strip("\n") + + return result + +def gen_pylogo(top_color, bottom_color): + home = str(Path.home()) + run(['convert', f'{home}/.config/qtile/topsnake.png', '+level-colors', f"gray,'{top_color}'", '-transparent', 'gray', '/tmp/topsnake.png']) + + run(['convert', f'{home}/.config/qtile/bottomsnake.png', '+level-colors', f"gray,'{bottom_color}'", '-transparent', 'gray', '/tmp/bottomsnake.png']) + + run(['convert', '-size', '600x600', '-composite', '/tmp/bottomsnake.png', '/tmp/topsnake.png', '/tmp/python.png']) + + #run(['convert', '-size', '610x610', '-composite', f'{home}/.config/qtile/border.png', '/tmp/python.png', '/tmp/python.png']) + + run(['rm', '-r', '/tmp/topsnake.png', '/tmp/bottomsnake.png']) + +def preset(wall, mode): + global home + presets = os.popen(f"ls {home}/Pictures/Wallpapers/presets").read().strip('\n').split('\n') + wall = wall[:-3] + wall += 'json' + + if mode == 'find': + return wall in presets + + elif mode == 'set': + wall = presets.index(wall) + return presets[wall] + +def new(name, folder): + os.system(f"ln -s {home}/Pictures/Wallpapers/wallpapers/{name} {home}/Pictures/Wallpapers/wallpaperdirs/{folder}/{name}") + +def pywal(wall, loc): + global home + + if wall == 'archstylized.png': + nitro(wall, loc) + + os.system(f'wal --theme {home}/.config/qtile/colors/defaultcolors.json') + + return 0 + + + else: + pass + + os.system(f'wal -i {loc}/{wall}') + +def nitro(wall, loc): + global home + os.system(f'nitrogen --set-scaled {loc}/{wall}') + +def random(walls): + wallcount = len(walls) - 1 + ranint = randint(0, wallcount) + ranwall = walls[ranint] + + return ranwall + +if __name__ == '__main__': + #Set dir variables + home = str(Path.home()) + stdwalls = f'{home}/Pictures/Wallpapers/wallpapers' + hallo = f'{home}/Pictures/Wallpapers/halloweenwallpapers' + xmas = f'{home}/Pictures/Wallpapers/xmaswallpapers' + + if len(sys.argv) >= 2: + if sys.argv[1] == 'none': + wallpapers = os.popen(f'ls {stdwalls}').read().strip('\n').split('\n') + wall = random(wallpapers) + + if preset(wall, 'find'): + os.system(f'wal --theme {home}/Pictures/Wallpapers/presets/{preset(wall, "set")}') + run([f'{home}/.local/bin/pywalfox', 'update']) + + else: + + pywal(wall, stdwalls) + + with open(f"{home}/.cache/wal/colors.json", 'r') as f: + data = json.load(f) + + top_color = data["colors"].get('color8') + + bottom_color = data["colors"].get('color6') + + gen_pylogo(top_color, bottom_color) + + elif sys.argv[1] == 'halloween': + curr_dir = hallo + + wallpapers = os.popen(f'ls {curr_dir}').read().strip('\n').split('\n') + + walls = random(wallpapers) + + nitro(walls, curr_dir) + + colors.setColor(home, f'{home}/.config/qtile/colors', 'halloweencolors.json', norestart = True) + + run([f'{home}/.local/bin/pywalfox', 'update']) + + sys.exit(0) + + elif sys.argv[1] == 'xmas': + curr_dir = xmas + + wallpapers = os.popen(f'ls {curr_dir}').read().strip('\n').split('\n') + + walls = random(wallpapers) + + nitro(walls, curr_dir) + + colors.setColor(home, f'{home}/.config/qtile/colors', 'xmascolors.json', norestart = True) + + run([f'{home}/.local/bin/pywalfox', 'update']) + + sys.exit(0) + + elif sys.argv[1] == 'new': + new(sys.argv[2], sys.argv[3]) + + elif '-i' == sys.argv[1]: + if sys.argv[2][0] == '/': + indx = sys.argv[2].rindex('/') + curr_dir = sys.argv[2][:indx] + wall = sys.argv[2][indx + 1:] + + else: + curr_dir = os.getcwd() + wall = sys.argv[2] + + pywal(wall, curr_dir) + + run([f'{home}/.local/bin/pywalfox', 'update']) + + with open(f"{home}/.cache/wal/colors.json", 'r') as f: + data = json.load(f) + + top_color = data["colors"].get('color8') + + bottom_color = data["colors"].get('color6') + + gen_pylogo(top_color, bottom_color) + + try: + #subprocess.check_call(['qtile', 'shell', '-c', 'restart()']) + #run(['kill', '-SIGUSR1', os.popen('pidof qtile').read().strip('\n')]) + #run(['qtile', 'shell', '-c', 'restart()']) + run(['qtile', 'shell', '-c', 'reload_config()']) + + except: + os.system('killall dwm') + + elif 'a' in sys.argv[1]: + curr_dir = sys.argv[1] + 'wallpapers' + + wallpapers = os.popen(f'ls {home}/Pictures/Wallpapers/{curr_dir}').read().strip('\n').split('\n') + nitro(random(wallpapers), curr_dir) + + sys.exit(0) + + else: + pass + + #Inital prompt + walldirs = "All\n" + walldirs += os.popen(f"ls {home}/Pictures/Wallpapers/wallpaperdirs/").read().strip("\n") + #wallpaperchoice = os.popen(f'echo "{walldirs}" | dmenu -p "Wallpaper:"').read().strip("\n") + wallpaperchoice = dmenu(walldirs, "Wallpaper:") + + #Closes on ESC + if wallpaperchoice == '': + sys.exit(0) + + #Sets to other dirs + elif wallpaperchoice == "halloween": + #wallpaperchoice = os.popen(f'ls {hallo}/ | dmenu -p "Wallpaper:"').read().strip('\n') + wallpaperchoice = dmenu(os.popen(f"ls {hallo}").read().strip('\n'), "Wallpaper:") + + if wallpaperchoice == '': + sys.exit(0) + + curr_dir = hallo + + elif wallpaperchoice == "xmas": + #wallpaperchoice = os.popen(f'ls {xmas}/ | dmenu -p "Wallpaper:"').read().strip('\n') + wallpaperchoice = dmenu(os.popen(f"ls {xmas}").read().strip('\n'), "Wallpaper:") + + if wallpaperchoice == '': + sys.exit(0) + + curr_dir = xmas + + elif wallpaperchoice == "All": + #wallpaperchoice = os.popen(f'ls {stdwalls}/ | dmenu -p "Wallpaper:"').read().strip('\n') + wallpaperchoice = dmenu(os.popen(f"ls {stdwalls}").read().strip('\n'), "Wallpaper:") + + if wallpaperchoice == '': + sys.exit(0) + + curr_dir = stdwalls + + else: + #wallpaperchoice = os.popen(f'ls {home}/Pictures/Wallpapers/wallpaperdirs/{wallpaperchoice} | dmenu -p "Wallpaper:"').read().strip('\n') + wallpaperchoice = dmenu(os.popen(f"ls {home}/Pictures/Wallpapers/wallpaperdirs/{wallpaperchoice}").read().strip('\n'), "Wallpaper:") + + if wallpaperchoice == '': + sys.exit(0) + + curr_dir = stdwalls + + #Split to list + wallargs = wallpaperchoice.split(' ') + + #Handle random selection + if 'random' in wallargs: + wallpapers = os.popen(f'ls {home}/Pictures/Wallpapers/{curr_dir}').read().strip('\n').split('\n') + + wallargs[0] = random(wallpapers) + + #Set wallpaper with nitrogen + if ':nitro' in wallargs: + nitro(wallargs[0], curr_dir) + sys.exit(0) + + elif preset(wallargs[0], 'find') and ':auto' not in wallargs: + os.system(f'wal --theme {home}/Pictures/Wallpapers/presets/{preset(wallargs[0], "set")}') + + run([f'{home}/.local/bin/pywalfox', 'update']) + + #Set wallpaper with pywal + else: + pywal(wallargs[0], curr_dir) + run([f'{home}/.local/bin/pywalfox', 'update']) + + with open(f"{home}/.cache/wal/colors.json", 'r') as f: + data = json.load(f) + + top_color = data["colors"].get('color8') + + bottom_color = data["colors"].get('color6') + + gen_pylogo(top_color, bottom_color) + + try: + print('restarting qtile') + #subprocess.check_call(['qtile', 'shell', '-c', 'restart()']) + #run(['qtile', 'shell', '-c', 'restart()']) + #run(['kill', '-SIGUSR1', os.popen('pidof qtile').read().strip('\n')]) + run(['qtile', 'shell', '-c', 'reload_config()']) + #os.system('qtile shell -c "restart()"') + + except: + print('killing dwm') + os.system('killall dwm') + #pass |