def api(): counter = Counter.get_create(label='Test') counter.increment() date = datetime.datetime.now() dateStr = date.strftime('%c') times = 'time' if counter.count == 1 else 'times' response = RESPONSE_TEMPLATE.format(count=counter.count, times=times, date=dateStr) return jsonify(response=response)
def post(self, server_type, server_id): """Create a new Counter""" form = ns.payload server_group_id = get_group_id(server_type, server_id) if (Counter.query.filter_by(server_group_id=server_group_id).filter( func.lower(Counter.name) == form["name"].lower()).first() is not None): abort(400, f"Counter {form['name']} already exists") response = None if "response" in form: response = form["response"] if response is None: # response could still be None from the post data response = f"Counter {form['name']}" + " is now at {}" counter = Counter( server_group_id=server_group_id, name=form["name"], count=form.get("count", 0), response=response, ) db.session.add(counter) db.session.commit() return counter
def reset(): counter = Counter.get_create(label='Test') counter.reset() return jsonify(response=counter.count)
def do_something(amount): for counter in Counter.list(): counter.increment(amount=amount)
def index(): counter = Counter.get_create(label='Test') counter.increment() return render_template('counter.html', counters=Counter.list())
def ping_once(amount): for counter in Counter.list(): counter.increment(amount=amount)