简体   繁体   English

如何在Heroku中连续运行此脚本

[英]How to run this script continuously in Heroku

I need to run this script in heroku to update my database. 我需要在heroku中运行此脚本以更新数据库。 The data is retrieve from my facebook post. 数据是从我的Facebook帖子中检索的。

I am not sure how to use the Heroku scheduler, what can I do? 我不确定如何使用Heroku调度程序,该怎么办?

from facepy import GraphAPI
import json
#import psycopg2
#import mysql.connector

my_token = ....
graph = GraphAPI(my_token)

# Get my latest posts
my_posts = graph.get("me?fields=posts.limit(1){message}", page=False, retry=1, limit=1)

with open('content.json', 'w') as outfile:
  json.dump(my_posts, outfile, indent = 4)

with open('content.json') as data_file:    
    da = json.load(data_file)

a =  da["posts"]["data"][0]["message"]
#fecha = da["posts"]["data"][0]["created_time"]
b=a[0:4]

if b == 'Temp':
    temp = a[5:7]
    hum = a[13:15]
    id = a[20:23]
    print temp
    print hum
    print indent

else:
    print 'error'

Thanks 谢谢

Heroku scheduler is exactly what you are looking for, you can run this code hourly, daily, etc. Heroku调度程序正是您所需要的,您可以每小时,每天等运行此代码。

They have an excellent tutorial that explains how you turn this code on a rake task and make it run whenever you want: https://devcenter.heroku.com/articles/scheduler 他们有一个很好的教程,解释了如何在rake任务上启用此代码,并使其在需要时运行: https : //devcenter.heroku.com/articles/scheduler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM