def get(queue, url, parent): """Get the URL and queue the response.""" with book("get({url})", parent, url=url): try: response = requests.get(url) except Exception as e: queue.put(e) else: queue.put(response.status_code)
def get(queue, url, parent): """Get the URL and queue the response.""" book.distribute(to.File(path=logbox)) with book("get({url})", parent, url=url): try: response = requests.get(url) except Exception as e: queue.put(e) else: queue.put(response.status_code)
def task(): data = json.loads(request.data) with book('api', data["parent"]): book.conclude(status=200) return jsonify({"status": 200})
from flask import Flask, jsonify, request from jotting import book import json # Server # ------ app = Flask(__name__) @app.route("/api/task", methods=["PUT"]) def task(): data = json.loads(request.data) with book('api', data["parent"]): book.conclude(status=200) return jsonify({"status": 200}) # Client # ------ with book('put') as b: route = '/api/task' data = json.dumps({'parent': b.tag}) app.test_client().put(route, data=data)
import requests from jotting import book urls = ("https://google.com", "not-here") responses = [] for u in urls: with book("getting %s" % u): r = requests.get(u) r.raise_for_status() responses.append(r)