Hi all,
I made a scheduled task that would run every day at a specified time, and opened up a bash where I would import all the libraries needed, I ran the task and the first time, it worked, and now when I run it on PythonAnywhere and all future tasks, I got the following error:
Traceback (most recent call last):
File "/home/TheSilentWaiter/applePriceNotifier.py", line 1, in <module>
from serpapi import GoogleSearch
ImportError: cannot import name 'GoogleSearch' from 'serpapi' (/home/TheSilentWaiter/.local/lib/python3.10/site-packages/serpapi/__init__.py)
I've been bashing my head on this but I cannot find to get a solution. I did the right imports in my code, the code works perfectly locally, I tried reinstalling all the libraries and I still run into that error. My code doesn't work anymore on the cloud here on PythonAnywhere and everything I run the script, it goes into the error. I am just doing a simple script to scrape a stock, below is my code:
from serpapi import GoogleSearch
import time,yagmail
def getPrice(ticker):
params = {
"api_key": "{REDACTED}",
"engine": "google_finance",
"q": f"{ticker}:NASDAQ"
}
search = GoogleSearch(params)
results = search.get_dict()
return results['summary']['price']
currentPrice = float(getPrice("META")[1:])
print(currentPrice)
sender = '{REDACTED}'
receiver = '{REDACTED}'
yag = yagmail.SMTP(user = sender, password ="{REDACTED}")
if(currentPrice > 468.24):
subject = "Apple is above what you wanted!"
contents = f"""
Apple Stock Price is currently above 468.24. The current price is {currentPrice}
"""
yag.send(to=receiver, subject=subject, contents=contents)
else:
subject = "Apple is BELOW what you wanted!"
contents = f"""
Apple Stock Price is currently BELOW 468.24. The current price is {currentPrice}
"""
yag.send(to=receiver, subject=subject, contents=contents)
print("Sent Email")
Thanks in advanced. I have the paid version as well.