Extracting image then thumbnail that image and display on index.html

Refresh

November 2018

Views

411 time

2

So I made my mind to use python goose for extracting the main image when url is inserted. I found good example here https://blog.openshift.com/day-16-goose-extractor-an-article-extractor-that-just-works/ the blog example is using flask, I tried to make the script for people using django Here is my media.py ( not sure if this works yet )

media.py

import json
from goose import Goose

def extract(request):
    url = request.args.get('url')
    g = Goose()
    article = g.extract(url=url)
    resposne = {'image':article.top_image.src}
    return json.dumps(resposne)

How do I use the image I get from above and put it in a thumbnail and display that on the index.html ? please, any help would be very appreciated. Merry Christmas

Edit 1 : I tried to convert below to django script but in my case only script image

from flask import Flask
from flask import jsonify
from flask import render_template
from flask import request
from goose import Goose

app = Flask(__name__)

@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html')

@app.route('/api/v1/extract')
def extract():
    url = request.args.get('url')
    g = Goose()
    article = g.extract(url=url)
    response = {'title' : article.title , 'text' : article.cleaned_text[:250], 'image': article.top_image.src}
    return jsonify(response)

if __name__ == "__main__":
    app.run(debug=True)

0 answers