예제 #1
0
파일: web.py 프로젝트: ninz/flask-demo
def lookup_oembed():
    from flask import current_app
    content_url = request.form.get('content_url')
    (discovered_format, oembed_url) = discovery.get_oembed_url(
        content_url, max_width=300, max_height=300)
    current_app.logger.debug(oembed_url)
    response = requests.get(oembed_url)
    oembed_fields = json.loads(response.text)
    return jsonify(oembed_fields)
예제 #2
0
파일: api.py 프로젝트: ninz/flask-demo
def create():
    json_data = request.get_json(force=True)
    try:
        (discovered_format, oembed_url) = get_oembed_url(json_data['scrap'], max_width=300, max_height=300)
    except PyEmbedDiscoveryError:
        return error("Invalid oEmbed resource URL", 400)
    except KeyError:
        return error("POST to /api/scraps takes one parameter, scrap", 400)

    response = requests.get(oembed_url)
    oembed_fields = json.loads(response.text)
    s = Scrapbook(json_data['scrap'], **oembed_fields)
    db_session.add(s)
    db_session.commit()
    return jsonify({"scrap": url_for('get', **{'scrap_id': s.id})}), 201