【问题标题】:How to run this script continuously in Heroku如何在 Heroku 中连续运行此脚本
【发布时间】:2015-06-29 12:15:33
【问题描述】:

我需要在 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'

谢谢

【问题讨论】:

    标签: python heroku scheduled-tasks job-scheduling


    【解决方案1】:

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

    他们有一个很好的教程,解释了如何在 rake 任务上打开这段代码并让它在你想要的时候运行:https://devcenter.heroku.com/articles/scheduler

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-18
      • 2017-05-15
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多