2019-04-22 15:04:52 +00:00
|
|
|
from flask import Flask, request
|
|
|
|
|
import os
|
|
|
|
|
import urlchecker
|
|
|
|
|
import sitemapper
|
|
|
|
|
import _pickle as cPickle
|
|
|
|
|
import json
|
2019-05-01 12:26:11 +00:00
|
|
|
import sys
|
2019-04-22 15:04:52 +00:00
|
|
|
#----------------------------------------------------------------------------#
|
|
|
|
|
# App Config.
|
|
|
|
|
#----------------------------------------------------------------------------#
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------#
|
|
|
|
|
# Controllers.
|
|
|
|
|
#----------------------------------------------------------------------------#
|
|
|
|
|
|
|
|
|
|
@app.route('/test/')
|
|
|
|
|
def index():
|
|
|
|
|
url = request.args.get("url")
|
2019-04-27 12:23:56 +00:00
|
|
|
#print(url)
|
2019-04-22 15:04:52 +00:00
|
|
|
obj = sitemapper.url(url)
|
2019-04-27 12:23:56 +00:00
|
|
|
obj.run_check(url)
|
2019-05-01 12:26:11 +00:00
|
|
|
|
|
|
|
|
nodes = ""
|
|
|
|
|
drawn = []
|
|
|
|
|
for key, values in obj.sites.items():
|
|
|
|
|
label = key.rsplit('/')[-1]
|
|
|
|
|
if label == "":
|
|
|
|
|
label = key.rsplit('/')[-2]
|
|
|
|
|
nodes += '{' + 'id: "{}", label: "{}", group: {}'.format(key, label, 0) + '},\n'
|
|
|
|
|
drawn.append(key)
|
2019-04-22 15:04:52 +00:00
|
|
|
|
2019-05-01 12:26:11 +00:00
|
|
|
for key, values in obj.sites.items():
|
|
|
|
|
for value in values:
|
|
|
|
|
if value not in drawn and value not in obj.sites:
|
|
|
|
|
nodes += '{' + 'id: "{}", label: "{}", group: {}'.format(value, value, 1) + '},\n'
|
|
|
|
|
drawn.append(value)
|
2019-04-22 15:04:52 +00:00
|
|
|
|
2019-05-01 12:26:11 +00:00
|
|
|
nodes = nodes[:-2] + "\n"
|
2019-04-29 09:03:24 +00:00
|
|
|
|
|
|
|
|
edges = ""
|
|
|
|
|
for key, values in obj.sites.items():
|
|
|
|
|
for value in values:
|
2019-05-01 12:26:11 +00:00
|
|
|
edges += '{' + 'from: "{}", to: "{}"'.format(key, value) + '},\n'
|
|
|
|
|
edges = edges[:-2] + "\n"
|
2019-04-29 09:03:24 +00:00
|
|
|
|
2019-05-01 12:26:11 +00:00
|
|
|
with open('./cached/' + url.rsplit('/')[2] + '.txt', 'w') as f:
|
|
|
|
|
f.write(nodes)
|
|
|
|
|
f.write(edges)
|
2019-04-29 09:03:24 +00:00
|
|
|
|
|
|
|
|
results = '''
|
|
|
|
|
<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: {
|
2019-05-01 12:26:11 +00:00
|
|
|
improvedLayout:true,
|
|
|
|
|
randomSeed: 10,
|
|
|
|
|
|
2019-04-29 09:03:24 +00:00
|
|
|
},
|
|
|
|
|
height: '100%',
|
|
|
|
|
width: '100%',
|
|
|
|
|
nodes: {
|
|
|
|
|
shape: 'dot',
|
2019-05-01 12:26:11 +00:00
|
|
|
size: 8,
|
2019-04-29 09:03:24 +00:00
|
|
|
font: {
|
2019-05-01 12:26:11 +00:00
|
|
|
size: 5,
|
2019-04-29 09:03:24 +00:00
|
|
|
color: '#ffffff'
|
|
|
|
|
},
|
2019-05-01 12:26:11 +00:00
|
|
|
borderWidth: 1
|
2019-04-29 09:03:24 +00:00
|
|
|
},
|
|
|
|
|
edges: {
|
2019-05-01 12:26:11 +00:00
|
|
|
width: 1,
|
|
|
|
|
color: {
|
|
|
|
|
color:'#356b6b',
|
|
|
|
|
highlight:'#4286f4',
|
|
|
|
|
hover: '#41f4f4',
|
|
|
|
|
inherit: 'from',
|
|
|
|
|
opacity:1.0
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
interaction: {
|
|
|
|
|
hoverConnectedEdges: true,
|
|
|
|
|
tooltipDelay: 200
|
2019-04-29 09:03:24 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
network = new vis.Network(container, data, options);
|
2019-05-01 12:26:11 +00:00
|
|
|
network.on("stabilizationIterationsDone", function () {
|
|
|
|
|
network.setOptions( { physics: false } );
|
|
|
|
|
});
|
2019-04-29 09:03:24 +00:00
|
|
|
</script>
|
|
|
|
|
'''
|
|
|
|
|
return results
|
2019-04-22 15:04:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
port = int(os.environ.get('PORT', 80))
|
2019-05-01 12:26:11 +00:00
|
|
|
sys.setrecursionlimit(2000)
|
2019-04-22 15:04:52 +00:00
|
|
|
app.run(host='0.0.0.0', port=port)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|