Alan Tingey Alan Tingey - 2 years ago 146
Python Question

Crontab python django issue

The following works as expected:

python /usr/share/str8RED/ getLiveResults

However, nothing happens when I use the following cronjob:

*/1 * * * * python /usr/share/str8RED/ getLiveResults

Using the link below I have managed to create a error log:

This informs me that:

Traceback (most recent call last):
File "/usr/share/str8RED/", line 8, in <module>
from import execute_from_command_line
ImportError: No module named

I can get cronjab working and running every minute with echo "Hello World". Any help would be appreciated, many thanks, Alan.

Contents of

from import BaseCommand
from straightred.models import StraightredTeam
from straightred.xmlsoccer import XmlSoccer

#The class must be named Command, and subclass BaseCommand
class Command(BaseCommand):
# Show this when the user types help
help = "My test command"

# A command must define handle()
def handle(self, *args, **options):

xmlsoccer = XmlSoccer(api_key='XYZ', use_demo=False)
teams = xmlsoccer.call_api(method='GetAllTeamsByLeagueAndSeason',
league='English League Championship')

numberOfTeamsUpdated = 0

for team in teams:

if '{}Team_Id' in team.keys():
teamUpdate = StraightredTeam(teamid=team['{}Team_Id'],
numberOfTeamsUpdated = numberOfTeamsUpdated + 1

self.stdout.write("Hello world!")

Answer Source

If you are using virtual env, then you need to activate the environment,

maybe something like:

*/1 * * * * /usr/share/str8RED/.env/bin/python /usr/share/str8RED/ getLiveResults
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download