Advertisement
dredder_gun

automatic-per-server

Jun 11th, 2017
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from flask import Flask
  4. from flask import request
  5. import config
  6. import requests
  7. import time
  8.  
  9. app = Flask(__name__)
  10.  
  11. i = 0
  12.  
  13. def post_to_clojure():
  14.     try:
  15.         r = requests.post(config.uri)
  16.         print r.raw
  17.     except (RuntimeError, TypeError, NameError):
  18.         print "Error while query request"
  19.        
  20. @app.route('/start-timer', methods=['GET'])
  21. def start_timer():
  22.   period = int(float(request.args.get('period')))
  23.   global i
  24.   i = 1
  25.   while i == 1:
  26.     post_to_clojure()
  27.     time.sleep(period)
  28.  
  29. @app.route('/stop-timer', methods=['GET'])
  30. def stop_timer():
  31.     global i
  32.     i = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement