Jose Osorio
Jose Osorio

Reputation: 939

How to run this script continuously in Heroku

I need to run this script in heroku to update my database. The data is retrieve from my facebook post.

I am not sure how to use the Heroku scheduler, what can I do?

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

Upvotes: 0

Views: 577

Answers (1)

yogodoshi
yogodoshi

Reputation: 131

Heroku scheduler is exactly what you are looking for, you can run this code hourly, daily, etc.

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

Upvotes: 1

Related Questions