-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
39 lines (28 loc) · 1.25 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, render_template, Blueprint,redirect,url_for,request
from list_tweets import list_all_tweets
import requests
from bs4 import BeautifulSoup
app = Flask(__name__)
@app.route("/")
def hello():
return redirect(url_for('.get_tweet'))
@app.route("/tweet")
def get_tweet():
name = "geeksambhu"
tweet_list= list_all_tweets(name)
return render_template("tweet_index.html", tweets=tweet_list, name=name)
@app.route('/insta', methods=['GET', 'POST'])
def index():
if request.method == 'POST' and 'iurl' in request.form: # basic Flask structure
url = request.form['iurl']
raw = requests.get(url) # make a request to the URL
soup = BeautifulSoup(raw.text, 'html.parser') # get the HTML
links = soup.find(property="og:image") # find meta with property=og:image
# "og:video" if you want to download a video
image = links.get('content') # get its content
while image != '':
return render_template("get_insta.html", name="geeksambhu",image=image)
# '<img src="' + image + '"' + 'align="center">' # insert content in img tag
return render_template('get_insta.html',name="geeksambhu",image=None)
if __name__ == "__main__":
app.run(debug=True)