django save data once in a day to file after first script run

时间:2018-09-19 08:30:12

标签: python django

I'm a newbie in django. I'm providing some parsed content on a page from data, which was loaded from another web source via api. So, I'm wondering if there a way to load data one time in a day and then save it to a file, so my program will parse that data from a file for the rest of that day, not via api service? Where should I look for?

3 个答案:

答案 0 :(得分:2)

您可以编写一个cron作业,该作业每天运行并获取所需的数据,然后将其保存到计算机上的文件中(或者更好的是,保存到数据库中)。 Django Cron使这变得非常容易。

答案 1 :(得分:0)

如上所述,您可以编写脚本并使用系统cron。但是,由于您使用的是django和python,因此也可以使用https://django-cron.readthedocs.io/en/latest/installation.html,它允许您计划django中的代码执行。

答案 2 :(得分:0)

您可以使用Django-celery在特定时间或每天自动执行任何python函数。 Django-celery