2019-05-06 12:04:01 +00:00
|
|
|
from flask import Flask, request, render_template
|
2019-04-22 15:04:52 +00:00
|
|
|
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__)
|
|
|
|
|
|
|
|
|
|
|
2019-05-06 12:04:01 +00:00
|
|
|
def map(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:
|
2019-05-06 12:04:01 +00:00
|
|
|
f.write(nodes + "\n")
|
2019-05-01 12:26:11 +00:00
|
|
|
f.write(edges)
|
2019-04-29 09:03:24 +00:00
|
|
|
|
2019-05-06 12:04:01 +00:00
|
|
|
return nodes, edges
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load(url):
|
|
|
|
|
nodes = ""
|
|
|
|
|
edges = ""
|
|
|
|
|
end = False
|
|
|
|
|
with open('./cached/{}.txt'.format(url)) as f:
|
|
|
|
|
for line in f:
|
|
|
|
|
if "end" in line:
|
|
|
|
|
end = True
|
|
|
|
|
continue
|
|
|
|
|
if not end:
|
|
|
|
|
nodes += line
|
|
|
|
|
else:
|
|
|
|
|
edges += line
|
|
|
|
|
|
|
|
|
|
return nodes, edges
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------#
|
|
|
|
|
# Controllers.
|
|
|
|
|
#----------------------------------------------------------------------------#
|
|
|
|
|
|
|
|
|
|
@app.route('/test/')
|
|
|
|
|
def index():
|
|
|
|
|
url = request.args.get("url")
|
|
|
|
|
cached = os.listdir("./cached")
|
|
|
|
|
if url + '.txt' not in cached:
|
|
|
|
|
nodes, edges = map(url)
|
|
|
|
|
else:
|
|
|
|
|
nodes, edges = load(url)
|
|
|
|
|
|
|
|
|
|
return render_template('graph.html', nodes = nodes, edges = edges)
|
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-05-06 12:04:01 +00:00
|
|
|
load('www.google.de')
|
2019-04-22 15:04:52 +00:00
|
|
|
app.run(host='0.0.0.0', port=port)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|