Skip to content

Instantly share code, notes, and snippets.

@maxtortime
Created April 17, 2018 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxtortime/3e8fb224914cf8a4a953d5f5a803e18f to your computer and use it in GitHub Desktop.
Save maxtortime/3e8fb224914cf8a4a953d5f5a803e18f to your computer and use it in GitHub Desktop.
python apscheduler example
import json
import time
import os
import requests
import collection
import logging
import time
from apscheduler.schedulers.blocking import BlockingScheduler
logging.basicConfig(filename='logs/'+time.strftime("%Y-%m-%d-%H-%M-%S") +'.log', level=logging.INFO)
sched = BlockingScheduler()
@sched.scheduled_job('cron', day_of_week='mon-sun', hour=23)
def batch():
# url = "http://52.78.14.28:3000/saveStatistic"
# url = "http://localhost:3000/saveStatistic"
data = collection.get_data()
file_path = os.path.join('results', 'dashboard_' + time.strftime("%Y%m%d_%H%M%S")) + '.json'
with open(file_path, 'w') as f:
json.dump(data, f)
logging.info("[{0}] {1} has saved successfully...".format(time.strftime("%Y-%m-%d_%H:%M:%S"), file_path))
# headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
# r = requests.post(url, data=json.dumps(data), headers=headers)
# print(time.strftime("%Y/%m/%d, %H:%M:%S"), r.status_code, r.reason)
if __name__ == '__main__':
sched.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment