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

时间:2015-04-22 03:49:27

标签: python heroku scheduled-tasks job-scheduling

我需要在heroku中运行此脚本来更新我的数据库。数据从我的Facebook帖子中检索。

我不知道如何使用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'

谢谢

1 个答案:

答案 0 :(得分:1)

Heroku调度程序正是您所寻找的,您可以每小时,每天等运行此代码。

他们有一个很好的教程,解释了如何在rake任务上转换代码并让它随时运行:https://devcenter.heroku.com/articles/scheduler