[英]How can I run the python script which contain libraries from php hosted on heroku?
[英]How do I automate a python script to run every hour in a Django website hosted on Heroku?
我的项目涉及一个 Django 网站,该网站使用从 web 抓取脚本生成的 a.csv 文件中的数据,该文件需要托管在 web 上。 我的开发操作系统是 Windows 10。当我的开发服务器运行时,它最初执行主应用程序的views.py
文件下的脚本:
exec(open('homepage/scrape.py').read())
其中homepage
是项目主要应用程序的名称, scrape.py
是 web 抓取脚本。
我需要做的是让这个scrape.py
每小时运行一次,并且能够在 Heroku 测功机和我的 Windows 开发环境上工作。
谢谢。
我最近构建了一个功能非常相似的应用程序。 谢天谢地,解决方案非常简单。
首先,我创建了一个包含实际调度功能的clock.py
文件。
from apscheduler.schedulers.blocking import BlockingScheduler
from django import setup
from scrape import scrape #this is the package you referred to in your question, theoretically
setup() #got to make sure everything is running before this kicks in
@sched.scheduledc_job('interval', hours=1)
def hourly_scrape():
update = scrape()
sched.start()
然后我在我的Procfile
中添加了一个名为clock
的单独测功机来完成这项工作。
clock: python clock.py --log-file -
只要您更新您的requirements.txt
并在线获得另一个测功机,您就可以轻松上钩。 另外,不要忘记你必须扩大你的测功机。 从命令行看起来像这样:
$ heroku ps:scale clock=1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.