Open a Pycharm Pyhton project fom another Pycharm Python project
I am not a programmer, so please bear with me if I'm inaccurate or don't really understand the replies.
I use pycharm, it works really well for me, python scripts are called projects in pycharm and I am running a couple of webscraping scripts to retrieve competitor prices on the internet. They are quite simple but work rather well. In order to go through the process I have to call every script (one for every competitor) independently, wait for it to finish, then I call the other one, etc. I could actually call or run all them simultaneously but it gets visually very messy, there are errors sometimes and it's just simpler to run one at a time, and get the results, they take 10-15 minutes each tops.
But I can't just sit around to wait for them to finish. I tried merging them into one large project but that was really messy, as every webpage has nuances, differences, I use different variables for every page to allow for differences, it's just simpler this way. But it is time consuming and basically forces me to stay put while running them.
I am trying to automate the process and am using tkinter to write a small project that would (ideally) call or run each one, one at a time, and I also hope to retrieve an exit code as well from every project that runs, in order for me to know if the project/script ran properly or not.
I have tkinter semi sorted out and have managed to get buttons, a clock, etc up and running (I am planning on running this script four times a day, every 3 hours approximately). I am confident I can do the GUI tkinter bit.
But I have been unable to call / run / import a pycharm project from another pycharm project. Here's the last iteration of what I have been trying out and using (these are called when pressing a button on the tkinter GUI:
# create button, link it to run web price scraper program
webscraperbutton = Button(self, text="Run", command=self.run_price_scraper)
# place button at (400,100)
webscraperbutton.place(x=200, y=100)
def run_price_scraper(self):
# exec(open('/Users/manuel/PycharmProjects/PriceScraper/main.py').read())
# os.system("/Users/manuel/PycharmProjects/PriceScraper/main.py")
# subprocess.call('/Users/manuel/PycharmProjects/PriceScraper/main.py', shell=True)
They are all #d as I have been trying various combinations but nothing works so far.
Here are the errors I get:
subprocess.call('/Users/manuel/PycharmProjects/PriceScraper/main.py', shell=True)
from: can't read /var/mail/selenium
from: can't read /var/mail/selenium.webdriver.chrome.options
from: can't read /var/mail/selenium.webdriver.support.select
from: can't read /var/mail/selenium.webdriver.common.by
from: can't read /var/mail/selenium.webdriver.support.ui
from: can't read /var/mail/selenium.webdriver.support
/Users/manuel/PycharmProjects/PriceScraper/main.py: line 8: import: command not found
/Users/manuel/PycharmProjects/PriceScraper/main.py: line 12: syntax error near unexpected token `('
/Users/manuel/PycharmProjects/PriceScraper/main.py: line 12: `chrome_options = Options()'
From os.system("/Users/manuel/PycharmProjects/PriceScraper/main.py") same error
from: can't read /var/mail/selenium
from: can't read /var/mail/selenium.webdriver.chrome.options
from: can't read /var/mail/selenium.webdriver.support.select
from: can't read /var/mail/selenium.webdriver.common.by
from: can't read /var/mail/selenium.webdriver.support.ui
from: can't read /var/mail/selenium.webdriver.support
/Users/manuel/PycharmProjects/PriceScraper/main.py: line 8: import: command not found
/Users/manuel/PycharmProjects/PriceScraper/main.py: line 12: syntax error near unexpected token `('
/Users/manuel/PycharmProjects/PriceScraper/main.py: line 12: `chrome_options = Options()'
From exec(open('/Users/manuel/PycharmProjects/PriceScraper/main.py').read())
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line
1884, in __call__
return self.func(*args)
File "/Users/manuel/PycharmProjects/PYGUI/main.py", line 31, in run_stock_scraper
exec(open('/Users/manuel/PycharmProjects/PriceScraper/main.py').read())
File "<string>", line 402, in <module>
File "<string>", line 29, in site_login
NameError: name 'driver' is not defined
How can I, in a simple way, just call or run another pycharm project, let it run through and get an exit code ?
I have thought of trying to make a Python app out of every project / script, and try calling an app instead, but I have no idea if that is even doable.
Any help is very welcome.
Thanks
Manolo
Please sign in to leave a comment.