L
L
lemonlimelike2020-07-05 00:03:57
Python
lemonlimelike, 2020-07-05 00:03:57

How to call a script in cmd?

Hello! I am using pysimplegui to create the interface. Wrote a parser. Now I want to connect the parser to my interface. At first, I wanted each parsed page to be displayed in the output field (in the interface). I wrote everything, launched it, but it turns out that until the parser finishes its work, the entire interface simply stops working and nothing appears in the output field. So everything is in sync. I read about asynchrony in pySimpleGui and decided to rewrite the script a bit. Launched. It started working, but for some reason only one entry appeared in the output field and the entire interface stopped working again. I looked at how much RAM it eats and how this application loads the processor and it turned out that it consumes quite well because of this asynchrony.

I decided to do so. By clicking on the Start button in the interface, launch the parser itself so that the command line opens and the parser starts working. How to do it? How to make a script call? To run it on the command line

Here is my GUI code:

import PySimpleGUI as sg
import parser as ps


layout = [
    [
    	sg.Text(text='Login',background_color='#fff',text_color='#000'), sg.InputText(size=(20,10),key='login_input'), 
    	sg.Text(text='Password',background_color='#fff',text_color='#000'),sg.InputText(size=(20,10),key='password_input'),
    	sg.Button(button_text='Check Auth',key='check_auth',enable_events=True,button_color=('#000','#fff'),pad=((50,0),(0,0)),tooltip='Проверка логина и пароля')
    ],
    [sg.Text(text='File',background_color='#fff',text_color='#000'),sg.InputText(key='file_input'),sg.FileBrowse()],
    [sg.Text(text='Минимальное кол-во товаров на складе',background_color='#fff',text_color='#000'),sg.InputText(size=(10,2),key='min_count_input')],
    [sg.Text(text='Максимальное кол-во дней',background_color='#fff',text_color='#000'),sg.InputText(size=(10,2),key='max_delivery_input')],
    [sg.Checkbox(text='Использовать Tor?',key='check_parse',enable_events=True,default=True)],
    [sg.Output(size=(88, 20))],
    [sg.Submit(), sg.Cancel()]
]

window = sg.Window('File Compare', layout,background_color='#fff',button_color=('#000','#fff'))
parser = ps.Parser()

while True:                             # The Event Loop
    event, values = window.read()
    print(event, values)
    if event in (None, 'Exit', 'Cancel'):
        break
    if event == 'Submit':
    	try:
    		list_data = parser.get_list_data(values['file_input'])
    	except Exception as e:
    		print('Error with file: ',e.args)
    	try:
           parser.run(values['min_count_input'],values['max_delivery_input'],list_data)
    	except Exception as e:
    		print('Не хватает данных для парсинга. Заполните поля. ',e.args)
    	print('Hello')

window.close()


The parser code does not need to be inserted here. Regular parser.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question