'''Created Sep 20, 2021 Levi''' # coding: utf-8 import subprocess as sp import json import configparser import pprint from json.decoder import JSONDecodeError from time import sleep from multiprocessing.pool import ThreadPool from threading import Event import psutil import telegram from yaspin import yaspin from declarations import (count_down, pretty_exc) # In "C:\Program Files\Java\jre1.8.0_333\lib\security\java.security" file comment the # jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \ # DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \ # include jdk.disabled.namedCurves # lines event = Event() config = configparser.ConfigParser() config.read('bot') bot = telegram.Bot(token=config['AUTH']['token2']) proc_name = 'javaw.exe' days = '"30"' url = f'"https://webserviced.anaf.ro/SPVWS2/rest/listaMesaje?zile={days}"' pin = '"111555"' java_executable = '"C:/Program Files/Java/jre1.8.0_333/bin/javaw.exe" -jar' jar_package = 'C:/Users/DECEL/SPV/target/ApelSPV-1.0-SNAPSHOT.jar' def kill_proc(name, timeout, pool_=None): # print('waiting') # event.wait() while timeout >= 0: # print(timeout, '' * 3, end='\r') sleep(1) timeout -= 1 if pool_: pool_.close() for proc in psutil.process_iter(): # check whether the process name matches if proc.name() == name: proc.kill() def run_proc1(): proc_1 = sp.run(f'{java_executable} {jar_package} {url} {pin}', shell=True, capture_output=True, text=True) # print(event.is_set()) # event.set() # print(event.is_set()) return proc_1.stdout if __name__ == '__main__': # run_proc1() messages = [] while True: try: pool = ThreadPool(processes=1) async_result = pool.apply_async(run_proc1) kill_proc(proc_name, 10, pool_=pool) return_val = async_result.get() return_val = json.loads(return_val) for message in return_val['mesaje']: # print(message) if message['tip'] != 'RECIPISA': messages.append(message) pprint.pprint(messages, indent=2) # print(return_val['titlu']) # print('last message type', return_val['mesaje'][0]['tip']) # if return_val['mesaje'][0]['tip'] != 'RECIPISA': # bot.send_message(chat_id=config['AUTH']['chatid'], text=return_val['mesaje'][0]['detalii']) break # count_down(1800, d_type='h', up_down='down') except JSONDecodeError as exc_: # pretty_exc(exc_) print(return_val[:7]) # count_down(10, d_type='h', up_down='down') # with yaspin() as ys: # ys.text = 'reloading in 10 seconds' print('reloading in 10 seconds') sleep(10) # time consuming code