diff --git a/windowsAgent/source/biblio.ini b/windowsAgent/source/biblio.ini new file mode 100644 index 0000000..71c7067 --- /dev/null +++ b/windowsAgent/source/biblio.ini @@ -0,0 +1,9 @@ +[DATA] +databasePath=C:\Users\admin\Desktop\libri.xbb +csvPath=C:\Users\admin\Documents\libri.csv +serverUrl=http://192.168.1.107:5555/up.php +authCode=xmeQCwqrQcSQ7TQX2Yyw +significance=3 +verbose=1 +updateUserWait=100 +chunkSize=50 diff --git a/windowsAgent/source/do.py b/windowsAgent/source/do.py new file mode 100644 index 0000000..cc5635c --- /dev/null +++ b/windowsAgent/source/do.py @@ -0,0 +1,84 @@ +import storage +import pymsgbox, os, time, requests, uuid, configparser +config = configparser.ConfigParser() +config.read('biblio.ini') +path=config["DATA"]["databasePath"] +csvPath=config["DATA"]["csvPath"] +serverurl=config["DATA"]["serverUrl"] +auth=config["DATA"]["authCode"] +significance=int(config["DATA"]["significance"]) +verbose=bool(config["DATA"]["verbose"]) +upwait=int(config["DATA"]["updateUserWait"]) +chunkRowNum=int(config["DATA"]["chunkSize"]) +def vprint(data): + global verbose + if verbose: + print(data) +def upload(csvPath): + global serverurl + global auth + vprint("Generating nonce uuid") + uid=str(uuid.uuid4()) + data=auth+"\n"+uid+"\nBEGIN" + requests.post(serverurl, data=data) + vprint("Sent BEGIN") + accumulator="" + index=0 + for line in open(csvPath): + if index==0: + data=auth+"\n"+uid+"\nWRITE\n" + accumulator=data + accumulator+=line + index+=1 + if index>chunkRowNum: + vprint("Sent WRITE") + requests.post(serverurl, data=accumulator) + index=0 + requests.post(serverurl, data=accumulator) + vprint("Sent WRITE") + data=auth+"\n"+uid+"\nCONCLUDE" + requests.post(serverurl, data=data) + vprint("Sent CONCLUDE") + +if not storage.exists("lastUpdate"): + vprint("Last database update record has been initialized") + storage.save("lastUpdate",0) +if not storage.exists("updateTick"): + vprint("Update tick record has been initialized") + storage.save("updateTick",0) +if not storage.exists("lastCSVUpdate"): + vprint("Last csv upsate record has been initialized") + storage.save("lastCSVUpdate",0) + +while True: + vprint("Main loop entered") + try: + vprint("In try-catch wrapper") + if storage.load("lastUpdate")significance: + vprint("The counter has overflowed the significance threshold") + storage.save("updateTick",0) + vprint("Resetting the counter to 0 accordingly") + vprint("Displaying update dialog") + pymsgbox.alert('Il catalogo dei libri è stato aggiornato.\nSi prega di cliccare File > Esporta Archivio > Esporta > Sì', 'Catalogo aggiornato') + vprint("Dialog displayed, waiting "+str(upwait)+"s") + time.sleep(upwait) + vprint("Wait expired") + if storage.load("lastCSVUpdate")