started load func

This commit is contained in:
Patrice Matz 2019-05-06 14:04:01 +02:00
parent 285d1cc6c5
commit 77afcb35a5
6 changed files with 94 additions and 68 deletions

Binary file not shown.

Binary file not shown.

100
app.py
View File

@ -1,4 +1,4 @@
from flask import Flask, request from flask import Flask, request, render_template
import os import os
import urlchecker import urlchecker
import sitemapper import sitemapper
@ -11,13 +11,9 @@ import sys
app = Flask(__name__) app = Flask(__name__)
#----------------------------------------------------------------------------#
# Controllers.
#----------------------------------------------------------------------------#
@app.route('/test/') def map(url):
def index():
url = request.args.get("url")
#print(url) #print(url)
obj = sitemapper.url(url) obj = sitemapper.url(url)
obj.run_check(url) obj.run_check(url)
@ -46,74 +42,48 @@ def index():
edges = edges[:-2] + "\n" edges = edges[:-2] + "\n"
with open('./cached/' + url.rsplit('/')[2] + '.txt', 'w') as f: with open('./cached/' + url.rsplit('/')[2] + '.txt', 'w') as f:
f.write(nodes) f.write(nodes + "\n")
f.write(edges) f.write(edges)
results = ''' return nodes, edges
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css">
<div id="mynetwork" style = "background-color: grey;"></div>
<script type="text/javascript">
var color = 'gray';
var nodes = [
''' + nodes + '''
];
var edges = [
''' + edges + '''
];
// create a network def load(url):
var container = document.getElementById('mynetwork'); nodes = ""
var data = { edges = ""
nodes: nodes, end = False
edges: edges with open('./cached/{}.txt'.format(url)) as f:
}; for line in f:
var options = { if "end" in line:
autoResize: true, end = True
layout: { continue
improvedLayout:true, if not end:
randomSeed: 10, nodes += line
else:
edges += line
}, return nodes, edges
height: '100%',
width: '100%', #----------------------------------------------------------------------------#
nodes: { # Controllers.
shape: 'dot', #----------------------------------------------------------------------------#
size: 8,
font: { @app.route('/test/')
size: 5, def index():
color: '#ffffff' url = request.args.get("url")
}, cached = os.listdir("./cached")
borderWidth: 1 if url + '.txt' not in cached:
}, nodes, edges = map(url)
edges: { else:
width: 1, nodes, edges = load(url)
color: {
color:'#356b6b', return render_template('graph.html', nodes = nodes, edges = edges)
highlight:'#4286f4',
hover: '#41f4f4',
inherit: 'from',
opacity:1.0
},
},
interaction: {
hoverConnectedEdges: true,
tooltipDelay: 200
}
};
network = new vis.Network(container, data, options);
network.on("stabilizationIterationsDone", function () {
network.setOptions( { physics: false } );
});
</script>
'''
return results
if __name__ == '__main__': if __name__ == '__main__':
port = int(os.environ.get('PORT', 80)) port = int(os.environ.get('PORT', 80))
sys.setrecursionlimit(2000) sys.setrecursionlimit(2000)
load('www.google.de')
app.run(host='0.0.0.0', port=port) app.run(host='0.0.0.0', port=port)

View File

@ -1671,6 +1671,7 @@
{id: "http://www.sriw.de", label: "http://www.sriw.de", group: 1}, {id: "http://www.sriw.de", label: "http://www.sriw.de", group: 1},
{id: "http://www.geodatendienstekodex.de/images/pdf/Datenschutz-Kodex.pdf?layoutId=54130", label: "http://www.geodatendienstekodex.de/images/pdf/Datenschutz-Kodex.pdf?layoutId=54130", group: 1}, {id: "http://www.geodatendienstekodex.de/images/pdf/Datenschutz-Kodex.pdf?layoutId=54130", label: "http://www.geodatendienstekodex.de/images/pdf/Datenschutz-Kodex.pdf?layoutId=54130", group: 1},
{id: "https://support.google.com/legal/troubleshooter/1114905?rd=1#ts=1115658%2C1115689%2C2364966%2C1115789", label: "https://support.google.com/legal/troubleshooter/1114905?rd=1#ts=1115658%2C1115689%2C2364966%2C1115789", group: 1} {id: "https://support.google.com/legal/troubleshooter/1114905?rd=1#ts=1115658%2C1115689%2C2364966%2C1115789", label: "https://support.google.com/legal/troubleshooter/1114905?rd=1#ts=1115658%2C1115689%2C2364966%2C1115789", group: 1}
end
{from: "https://www.google.de/about/company/facts/", to: "https://about.google/"}, {from: "https://www.google.de/about/company/facts/", to: "https://about.google/"},
{from: "https://www.google.de/about/company/facts/", to: "https://about.google/"}, {from: "https://www.google.de/about/company/facts/", to: "https://about.google/"},
{from: "https://www.google.de/about/company/facts/", to: "https://about.google/"}, {from: "https://www.google.de/about/company/facts/", to: "https://about.google/"},

View File

55
templates/graph.html Normal file
View File

@ -0,0 +1,55 @@
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css">
<div id="mynetwork" style = "background-color: grey;"></div>
<script type="text/javascript">
var color = 'gray';
var nodes = [{{ nodes }}];
var edges = [{{ edges }}];
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {
autoResize: true,
layout: {
improvedLayout:true,
randomSeed: 10,
},
height: '100%',
width: '100%',
nodes: {
shape: 'dot',
size: 8,
font: {
size: 5,
color: '#ffffff'
},
borderWidth: 1
},
edges: {
width: 1,
color: {
color:'#356b6b',
highlight:'#4286f4',
hover: '#41f4f4',
inherit: 'from',
opacity:1.0
},
},
interaction: {
hoverConnectedEdges: true,
tooltipDelay: 200
}
};
network = new vis.Network(container, data, options);
network.on("stabilizationIterationsDone", function () {
network.setOptions( { physics: false } );
});
</script>
</html>