Hello. I am developing a football predictions website. Part of it uses the Understat library which uses the BeautifulSoup library to import some data from Understat.com.
An example Python script using Understat is this:
import asyncio
import json
import aiohttp
from understat import Understat
async def main():
async with aiohttp.ClientSession() as session:
understat = Understat(session)
fixtures = await understat.get_league_results(
"epl",
2020
)
print(json.dumps(fixtures))
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
In my local development site I have been calling my Python script via this code in a PHP script, which pulls in a json file:
$pyscript = 'get_league_results_20_21.py';
$python = 'C:/Users/Nick/AppData/Local/Programs/Python/Python38/python.exe';
$cmd = "$python $pyscript";
exec($cmd, $output);
$results = json_decode($output[0], true);
When my site is live, 3 such scripts need to be run daily or even hourly via a cron job.
My hosting provider has told me their shared hosting does not support Python and I would need to spend around 5x as much to upgrade to a VPS, which would be over-budget.
Can the Understat library and Python scripts be hosted on pythonanywhere.com and called from a PHP file on another host? If so, can the free version do that?
(I did open an account here, set up a Python 3.8 virtual environment, and installed Understat in it via pip, but got stuck after that and haven't been able to get my scripts working so far.)