improved persitence
This commit is contained in:
parent
edf4961c14
commit
32b051f890
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
.vscode/
|
||||||
cached/
|
|
||||||
|
|
|
||||||
40
app.py
40
app.py
|
|
@ -1,8 +1,6 @@
|
||||||
from flask import Flask, request, render_template
|
from flask import Flask, request, render_template
|
||||||
import os
|
import os
|
||||||
import urlchecker
|
|
||||||
import sitemapper
|
import sitemapper
|
||||||
import _pickle as cPickle
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
#----------------------------------------------------------------------------#
|
#----------------------------------------------------------------------------#
|
||||||
|
|
@ -12,46 +10,42 @@ import sys
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
def map(url):
|
def graph(url):
|
||||||
|
|
||||||
#print(url)
|
|
||||||
obj = sitemapper.url(url)
|
obj = sitemapper.url(url)
|
||||||
obj.run_check(url)
|
obj.run_check(url)
|
||||||
|
|
||||||
nodes = ""
|
nodes = []
|
||||||
drawn = []
|
drawn = []
|
||||||
for key, values in obj.sites.items():
|
for key, values in obj.sites.items():
|
||||||
label = key.rsplit('/')[-1]
|
label = key.rsplit('/')[-1]
|
||||||
if label == "":
|
if label == "":
|
||||||
label = key.rsplit('/')[-2]
|
label = key.rsplit('/')[-2]
|
||||||
nodes += '{' + 'id: "{}", label: "{}", group: {}'.format(key, label, 0) + '},\n'
|
nodes.append('{' + "id: '{}', label: '{}', group: {}".format(key, label, 0) + '}')
|
||||||
drawn.append(key)
|
drawn.append(key)
|
||||||
|
|
||||||
for key, values in obj.sites.items():
|
for key, values in obj.sites.items():
|
||||||
for value in values:
|
for value in values:
|
||||||
if value not in drawn and value not in obj.sites:
|
if value not in drawn and value not in obj.sites:
|
||||||
nodes += '{' + 'id: "{}", label: "{}", group: {}'.format(value, value, 1) + '},\n'
|
nodes.append('{' + "id: '{}', label: '{}', group: {}".format(value, value, 1) + '}')
|
||||||
drawn.append(value)
|
drawn.append(value)
|
||||||
|
|
||||||
nodes = nodes[:-2] + "\n"
|
edges = []
|
||||||
|
|
||||||
edges = ""
|
|
||||||
for key, values in obj.sites.items():
|
for key, values in obj.sites.items():
|
||||||
for value in values:
|
for value in values:
|
||||||
edges += '{' + 'from: "{}", to: "{}"'.format(key, value) + '},\n'
|
edges.append('{' + "from: '{}', to: '{}'".format(key, value) + '}')
|
||||||
edges = edges[:-2] + "\n"
|
|
||||||
|
|
||||||
with open('./cached/' + url.rsplit('/')[2] + '.txt', 'w', encoding='utf-8') as f:
|
with open('./cached/' + url.rsplit('/')[2] + '.json', 'w', encoding='utf-8') as f:
|
||||||
f.write(nodes + "end\n")
|
f.write(json.dumps({"nodes": nodes,"edges": edges}))
|
||||||
f.write(edges)
|
|
||||||
|
|
||||||
return nodes, edges
|
return nodes, edges
|
||||||
|
|
||||||
|
|
||||||
def load(url):
|
def load(url):
|
||||||
with open('./cached/{}.txt'.format(url), 'r', encoding='utf-8') as f:
|
with open('./cached/{}.json'.format(url), 'r', encoding='utf-8') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
nodes, edges = content.split("end\n")
|
jsonContent = json.loads(content)
|
||||||
|
nodes = jsonContent["nodes"]
|
||||||
|
edges = jsonContent["edges"]
|
||||||
return nodes, edges
|
return nodes, edges
|
||||||
|
|
||||||
#----------------------------------------------------------------------------#
|
#----------------------------------------------------------------------------#
|
||||||
|
|
@ -61,14 +55,18 @@ def load(url):
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
#url = request.args.get("url")
|
#url = request.args.get("url")
|
||||||
url = "https://www.google.com"
|
url = "https://www.google.de"
|
||||||
cached = os.listdir("./cached")
|
cached = os.listdir("./cached")
|
||||||
withoutProtocol = url.rsplit('/')[2]
|
withoutProtocol = url.rsplit('/')[2]
|
||||||
if withoutProtocol + '.txt' not in cached:
|
if withoutProtocol + '.json' not in cached:
|
||||||
nodes, edges = map(url)
|
nodes, edges = graph(url)
|
||||||
else:
|
else:
|
||||||
nodes, edges = load(withoutProtocol)
|
nodes, edges = load(withoutProtocol)
|
||||||
|
|
||||||
|
str1 = ","
|
||||||
|
nodes = str1.join(nodes)
|
||||||
|
edges = str1.join(edges)
|
||||||
|
|
||||||
return render_template('graph.html', nodes = nodes, edges = edges)
|
return render_template('graph.html', nodes = nodes, edges = edges)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -5,9 +5,9 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var color = 'gray';
|
var color = 'gray';
|
||||||
|
|
||||||
var nodes = [{{ nodes | safe }} ];
|
var nodes = [{{ nodes | safe }}] ;
|
||||||
|
|
||||||
var edges = [{{ edges | safe }} ];
|
var edges = [{{ edges | safe }}] ;
|
||||||
|
|
||||||
// create a network
|
// create a network
|
||||||
var container = document.getElementById('mynetwork');
|
var container = document.getElementById('mynetwork');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue