From 0b25bc4e83a2d6b80a0de20391172e30f6d7251a Mon Sep 17 00:00:00 2001 From: MatMasIt Date: Tue, 5 Oct 2021 21:15:21 +0200 Subject: [PATCH] new file browser --- l.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 l.py diff --git a/l.py b/l.py new file mode 100644 index 0000000..bcefe2c --- /dev/null +++ b/l.py @@ -0,0 +1,62 @@ +import sys +import npyscreen +import datetime +import subprocess +import glob +import os +def shell(command): + try: + output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT) + except Exception as e: + output = str(e.output) + return output + +class TestMenuForm(npyscreen.ActionForm): + def create(self): + self.lastC = False + self.lastH = 0 + self.date = self.add(npyscreen.TitleDateCombo, name = "Data") + self.heavy = self.add(npyscreen.TitleSlider, out_of=10, name = "Carico del giorno") + self.content = self.add(npyscreen.MultiLineEdit, + value = "", + max_height=20, rely=9) + def while_editing(self): + try: + partsDate = self.date.value.strftime("%Y-%m-%d").split("-") + except: + return False + if self.heavy.value!=self.lastH: + if len(partsDate)==3: + open(glob.glob(partsDate[0]+'/'+str(int(partsDate[1]))+'_*/'+partsDate[2]+'_*/main.md')[0].replace("main.md","howhard"),"w+").write(str(self.heavy.value)) + if self.content.value!=self.lastC and self.lastC!=False: + open(glob.glob(partsDate[0]+'/'+str(int(partsDate[1]))+'_*/'+partsDate[2]+'_*/main.md')[0],"w").write(self.content.value) + self.lastH = self.heavy.value + self.lastC = self.content.value + if len(partsDate)==3: + val = shell('cat '+partsDate[0]+'/'+str(int(partsDate[1]))+'_*/'+partsDate[2]+'_*/main.md') + if len(glob.glob(partsDate[0]+'/'+str(int(partsDate[1]))+'_*/'+partsDate[2]+'_*/howhard')): + howhard=shell('cat '+partsDate[0]+'/'+str(int(partsDate[1]))+'_*/'+partsDate[2]+'_*/howhard') + try: + howhard = float(howhard) + except: + howhard = 0.0 + else: + howhard = 0.0 + try: + val=val.decode("utf-8") + except: + None + self.content.value = val + self.heavy.value = howhard + return False +class TestApp(npyscreen.NPSAppManaged): + def onStart(self): + testMenuForm = TestMenuForm(name="Diario") + self.registerForm('MAIN', testMenuForm) + + +def main(args): + App = TestApp() + App.run() +if __name__ == '__main__': + main(sys.argv)