gpt4 book ai didi

python - Crontab python django 问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:00:02 25 4
gpt4 key购买 nike

以下内容按预期工作:

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

我可以让 cronjab 工作并每分钟运行一次 echo“Hello World”。任何帮助将不胜感激,非常感谢,艾伦。

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!")

最佳答案

如果您使用的是虚拟环境,那么您需要激活环境,

也许是这样的:

*/1 * * * * /usr/share/str8RED/.env/bin/python /usr/share/str8RED/manage.py getLiveResults

关于python - Crontab python django 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40412272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com