cache works
This commit is contained in:
parent
77afcb35a5
commit
65c4ae2ea0
26
app.py
26
app.py
|
|
@ -41,27 +41,17 @@ def map(url):
|
||||||
edges += '{' + 'from: "{}", to: "{}"'.format(key, value) + '},\n'
|
edges += '{' + 'from: "{}", to: "{}"'.format(key, value) + '},\n'
|
||||||
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', encoding='utf-8') as f:
|
||||||
f.write(nodes + "\n")
|
f.write(nodes + "end\n")
|
||||||
f.write(edges)
|
f.write(edges)
|
||||||
|
|
||||||
return nodes, edges
|
return nodes, edges
|
||||||
|
|
||||||
|
|
||||||
def load(url):
|
def load(url):
|
||||||
nodes = ""
|
with open('./cached/{}.txt'.format(url), 'r', encoding='utf-8') as f:
|
||||||
edges = ""
|
content = f.read()
|
||||||
end = False
|
nodes, edges = content.split("end\n")
|
||||||
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
|
return nodes, edges
|
||||||
|
|
||||||
#----------------------------------------------------------------------------#
|
#----------------------------------------------------------------------------#
|
||||||
|
|
@ -72,10 +62,11 @@ def load(url):
|
||||||
def index():
|
def index():
|
||||||
url = request.args.get("url")
|
url = request.args.get("url")
|
||||||
cached = os.listdir("./cached")
|
cached = os.listdir("./cached")
|
||||||
if url + '.txt' not in cached:
|
withoutProtocol = url.rsplit('/')[2]
|
||||||
|
if withoutProtocol + '.txt' not in cached:
|
||||||
nodes, edges = map(url)
|
nodes, edges = map(url)
|
||||||
else:
|
else:
|
||||||
nodes, edges = load(url)
|
nodes, edges = load(withoutProtocol)
|
||||||
|
|
||||||
return render_template('graph.html', nodes = nodes, edges = edges)
|
return render_template('graph.html', nodes = nodes, edges = edges)
|
||||||
|
|
||||||
|
|
@ -83,7 +74,6 @@ def index():
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -5,8 +5,9 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var color = 'gray';
|
var color = 'gray';
|
||||||
|
|
||||||
var nodes = [{{ nodes }}];
|
var nodes = [{{ nodes | safe }} ];
|
||||||
var edges = [{{ edges }}];
|
|
||||||
|
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