Updated motd.py, is able to display waifus with icat
This commit is contained in:
		
							
								
								
									
										58
									
								
								motd.py
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								motd.py
									
									
									
									
									
								
							@@ -1,9 +1,12 @@
 | 
				
			|||||||
#!/bin/python
 | 
					#!/bin/python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from functools import cache
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import ueberzug.lib.v0 as ueberzug
 | 
					import random
 | 
				
			||||||
import curses
 | 
					#import ueberzug.lib.v0 as ueberzug
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
 | 
					import fnmatch
 | 
				
			||||||
from curses.textpad import Textbox, rectangle
 | 
					from curses.textpad import Textbox, rectangle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
modpath     = os.path.dirname(__file__)
 | 
					modpath     = os.path.dirname(__file__)
 | 
				
			||||||
@@ -22,11 +25,49 @@ minTermW    = 200
 | 
				
			|||||||
DIR=modpath + '/waifus'
 | 
					DIR=modpath + '/waifus'
 | 
				
			||||||
#print(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]))
 | 
					#print(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#filter waifus
 | 
				
			||||||
 | 
					waifulist = os.listdir(DIR)
 | 
				
			||||||
 | 
					waifus_raw = fnmatch.filter(waifulist, '*.256.png')
 | 
				
			||||||
 | 
					waifus = list(waifus_raw)
 | 
				
			||||||
 | 
					waifuindex = random.randint(1, len(waifus))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#print(modpath)
 | 
					#print(modpath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#######################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#If term Kitty
 | 
				
			||||||
 | 
					print(len(waifus))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if random.randint(0,1) == 0:
 | 
				
			||||||
 | 
					    if os.path.getsize(cachefile) != 0:
 | 
				
			||||||
 | 
					        f = open(cachefile, 'r')
 | 
				
			||||||
 | 
					        waifuindex = f.read()
 | 
				
			||||||
 | 
					        print(int(waifuindex))
 | 
				
			||||||
 | 
					        #print(len(waifus))
 | 
				
			||||||
 | 
					    #Else Add File
 | 
				
			||||||
 | 
					    ###############  
 | 
				
			||||||
 | 
					    if int(waifuindex) < len(waifus):
 | 
				
			||||||
 | 
					        waifu = waifus[int(waifuindex)]
 | 
				
			||||||
 | 
					        waifuindex = int(waifuindex) + 1
 | 
				
			||||||
 | 
					        f = open(cachefile, 'w')
 | 
				
			||||||
 | 
					        f.write(str(waifuindex))
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        waifuindex = random.randint(1, len(waifus))
 | 
				
			||||||
 | 
					        f = open(cachefile, 'w')
 | 
				
			||||||
 | 
					        f.write(str(waifuindex))
 | 
				
			||||||
 | 
					        waifu = waifus[int(waifuindex)] 
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					    waifu = waifus[int(waifuindex)]
 | 
				
			||||||
 | 
					#######################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#Declare static methods
 | 
				
			||||||
@staticmethod
 | 
					@staticmethod
 | 
				
			||||||
def showImage():
 | 
					def showImage():
 | 
				
			||||||
    print("showImage")
 | 
					    subprocess.run(["/usr/bin/kitty", "icat", DIR+"/"+waifu])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def showUname(unameArg):
 | 
					def showUname(unameArg):
 | 
				
			||||||
    os.system("/usr/bin/uname " + unameArg)
 | 
					    os.system("/usr/bin/uname " + unameArg)
 | 
				
			||||||
@@ -36,10 +77,9 @@ def showUname(unameArg):
 | 
				
			|||||||
def showUptime(uptimeArg):
 | 
					def showUptime(uptimeArg):
 | 
				
			||||||
    os.system("/usr/bin/uptime " + uptimeArg)
 | 
					    os.system("/usr/bin/uptime " + uptimeArg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def doLolcat():
 | 
					#def doLolcat():
 | 
				
			||||||
 | 
					#	if __name__ == '__main__':
 | 
				
			||||||
 | 
					#		showUname(unameArg)
 | 
				
			||||||
 | 
					#		showUptime(uptimeArg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					showImage()
 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == '__main__':
 | 
					 | 
				
			||||||
    showUname(unameArg)
 | 
					 | 
				
			||||||
    showUptime(uptimeArg)
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user