【发布时间】:2016-11-04 06:58:22
【问题描述】:
以下按预期工作:
python /usr/share/str8RED/manage.py getLiveResults
但是,当我使用以下 cronjob 时,没有任何反应:
*/1 * * * * python /usr/share/str8RED/manage.py getLiveResults
使用下面的链接,我设法创建了一个错误日志:
http://matthewwittering.com/blog/django-tips/running-a-django-management-commands-with-crontab.html
这告诉我:
Traceback (most recent call last):
File "/usr/share/str8RED/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
我可以通过 echo "Hello World" 让 cronjab 每分钟都工作和运行。任何帮助将不胜感激,非常感谢,艾伦。
getLiveResults.py 的内容:
from django.core.management 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',
seasonDateString='1617',
league='English League Championship')
numberOfTeamsUpdated = 0
for team in teams:
if '{http://xmlsoccer.com/Team}Team_Id' in team.keys():
teamUpdate = StraightredTeam(teamid=team['{http://xmlsoccer.com/Team}Team_Id'],
teamname=team['{http://xmlsoccer.com/Team}Name'],
country=team['{http://xmlsoccer.com/Team}Country'],
stadium=team['{http://xmlsoccer.com/Team}Stadium'],
homepageurl=team['{http://xmlsoccer.com/Team}HomePageURL'],
wikilink=team['{http://xmlsoccer.com/Team}WIKILink'],
currentteam=1)
teamUpdate.save()
numberOfTeamsUpdated = numberOfTeamsUpdated + 1
self.stdout.write("Hello world!")
【问题讨论】:
-
getliveResults是做什么的? -
如果你使用的是虚拟环境,那么你需要激活环境,