generated from adgsenpai/ADGWEBSDK
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
79 lines (71 loc) · 3.28 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ADGSTUDIOS - server.py
from flask import Flask, Request, jsonify, redirect, request, render_template
from flask_graphql import GraphQLView
import graphene
from graphqlbackend import Query
import graphqlbackend as gb
from flask_cors import CORS, cross_origin
import os
import dblayer as db
import requests
import json
import cloudscraper
from bs4 import BeautifulSoup
import re
import urllib.parse
view_func = GraphQLView.as_view(
'graphql', schema=graphene.Schema(query=Query), graphiql=True)
app = Flask(__name__, template_folder='./pages')
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
app.add_url_rule('/graphql', view_func=view_func)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
@app.route('/api/v1/getnfts', methods=['GET', 'POST'])
def getnfts():
if request.method == 'POST':
if request.data:
return jsonify(gb.get_address(request.data['walletaddress']))
else:
return 'invalid request'
@app.route('/api/v1/returnNFTLink/<contractAddress>/<tokenID>')
def returnNFTLink(contractAddress,tokenID):
try:
url = "https://opensea.io/assets/{0}/{1}".format(contractAddress,tokenID)
scraper = cloudscraper.create_scraper(
browser={'browser': 'firefox', 'platform': 'windows', 'mobile': False})
html = scraper.get(url).content
soup = BeautifulSoup(html, 'lxml')
if len(soup.findAll('source')) > 0:
return {'video':re.findall('"([^"]*)"', str(soup.findAll('source')[0]))[1]}
for x in soup.findAll('meta'):
if 'https://lh3.googleusercontent.com' in str(x):
return {'image':re.findall('"([^"]*)"', str(x))[0]}
except Exception as e:
print(e)
return 'failed'
@app.route('/viewnfts/<walletaddress>', methods=['GET'])
def viewnfts(walletaddress):
try:
df = gb.get_address(urllib.parse.unquote_plus(walletaddress))
except:
return render_template('viewnft.html',walletaddress="Please enter a valid wallet address")
nftimagelink = []
for index, row in df.iterrows():
nftimagelink.append(returnNFTLink(row['ContractAddress'],row['tokenID']))
df['NFTImageLink'] = nftimagelink
payload = ''
for index, row in df.iterrows():
try:
if row['NFTImageLink']['image']:
payload += '<tr>' +'<td>'+str(row['tokenID']) +'</td>'+ '<td>'+str(row['ContractAddress']) +'</td>'+ '<td>'+'<img style="width:310px" src="{0}">'.format(str(row['NFTImageLink']['image']))+'</img>'+'</td>'+ '</tr>'
except:
try:
payload += '<tr>' +'<td>'+str(row['tokenID']) +'</td>'+ '<td>'+str(row['ContractAddress']) +'</td>'+ '<td>'+'<video autoplay loop muted style="width:310px" controls="controls" src="{0}">'.format(str(row['NFTImageLink']['video']))+'</video>'+'</td>'+ '</tr>'
except:
payload += '<tr>' +'<td>'+str(row['tokenID']) +'</td>'+ '<td>'+str(row['ContractAddress']) +'</td>'+'<td>'+'No NFT Render Data Found'+'</td>'+ '</tr>'
return render_template('viewnft.html', blockchainaddress=walletaddress,payload=payload)
@app.route('/')
def home():
return render_template('index.html')
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)