From 9e28068226e7aed994860aca4cbcbb38cf0fc72f Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 19 Apr 2021 10:07:09 -0700 Subject: [PATCH 1/4] add json export of all nodes --- xmrnodes/app.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/xmrnodes/app.py b/xmrnodes/app.py index 4763954..41ca8a3 100644 --- a/xmrnodes/app.py +++ b/xmrnodes/app.py @@ -7,7 +7,7 @@ import click from os import makedirs from random import shuffle from datetime import datetime, timedelta -from flask import Flask, request, redirect +from flask import Flask, request, redirect, jsonify from flask import render_template, flash, url_for from urllib.parse import urlparse from xmrnodes.helpers import determine_crypto, is_onion, make_request @@ -54,6 +54,35 @@ def index(): form=form ) +@app.route("/nodes.json") +def nodes_json(): + nodes = Node.select().where( + Node.validated==True + ) + nodes = [n for n in nodes] + xmr_nodes = [n for n in nodes if n.crypto == "monero"] + wow_nodes = [n for n in nodes if n.crypto == "wownero"] + return jsonify({ + "monero": { + "mainnet": { + "healthy": [n.url for n in xmr_nodes if n.available and n.nettype == "mainnet"], + "unhealthy": [n.url for n in xmr_nodes if not n.available and n.nettype == "mainnet"], + }, + "stagenet": { + "healthy": [n.url for n in xmr_nodes if n.available and n.nettype == "stagenet"], + "unhealthy": [n.url for n in xmr_nodes if not n.available and n.nettype == "stagenet"], + }, + "testnet": { + "healthy": [n.url for n in xmr_nodes if n.available and n.nettype == "testnet"], + "unhealthy": [n.url for n in xmr_nodes if not n.available and n.nettype == "testnet"], + } + }, + "wownero": { + "healthy": [n.url for n in wow_nodes if n.available], + "unhealthy": [n.url for n in wow_nodes if not n.available], + } + }) + @app.route("/resources") def resources(): return render_template("resources.html") @@ -177,7 +206,7 @@ def export(): def import_(): all_nodes = [] export_dir = f"{config.DATA_DIR}/export.txt" - with open(export_dir, 'r') as f: + with open(export_dir, "r") as f: for url in f.readlines(): try: n = url.rstrip().lower() From cbc6022a430ee74c18ed2c955e052c4b82e70fe6 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 19 Apr 2021 10:13:50 -0700 Subject: [PATCH 2/4] change xmr_nodes json route --- xmrnodes/app.py | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/xmrnodes/app.py b/xmrnodes/app.py index 41ca8a3..68901c3 100644 --- a/xmrnodes/app.py +++ b/xmrnodes/app.py @@ -54,33 +54,19 @@ def index(): form=form ) -@app.route("/nodes.json") -def nodes_json(): +@app.route("/xmr_nodes.json") +def xmr_nodes_json(): nodes = Node.select().where( Node.validated==True + ).where( + Node.nettype=="mainnet" + ).where( + Node.crypto=="monero" ) nodes = [n for n in nodes] - xmr_nodes = [n for n in nodes if n.crypto == "monero"] - wow_nodes = [n for n in nodes if n.crypto == "wownero"] return jsonify({ - "monero": { - "mainnet": { - "healthy": [n.url for n in xmr_nodes if n.available and n.nettype == "mainnet"], - "unhealthy": [n.url for n in xmr_nodes if not n.available and n.nettype == "mainnet"], - }, - "stagenet": { - "healthy": [n.url for n in xmr_nodes if n.available and n.nettype == "stagenet"], - "unhealthy": [n.url for n in xmr_nodes if not n.available and n.nettype == "stagenet"], - }, - "testnet": { - "healthy": [n.url for n in xmr_nodes if n.available and n.nettype == "testnet"], - "unhealthy": [n.url for n in xmr_nodes if not n.available and n.nettype == "testnet"], - } - }, - "wownero": { - "healthy": [n.url for n in wow_nodes if n.available], - "unhealthy": [n.url for n in wow_nodes if not n.available], - } + "clear": [n.url for n in nodes if n.is_tor == False], + "onion": [n.url for n in nodes if n.is_tor == True] }) @app.route("/resources") From 3b08d61a2b7b6813c31446a33bdb5136cc725cc2 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 19 Apr 2021 10:18:16 -0700 Subject: [PATCH 3/4] updating nodes.json route again --- xmrnodes/app.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/xmrnodes/app.py b/xmrnodes/app.py index 68901c3..9cc9628 100644 --- a/xmrnodes/app.py +++ b/xmrnodes/app.py @@ -54,14 +54,34 @@ def index(): form=form ) -@app.route("/xmr_nodes.json") -def xmr_nodes_json(): +@app.route("/nodes.json") +def nodes_json(): + nodes = Node.select().where( + Node.validated==True + ).where( + Node.nettype=="mainnet" + ) + xmr_nodes = [n for n in nodes if n.crypto == "monero"] + wow_nodes = [n for n in nodes if n.crypto == "wownero"] + return jsonify({ + "monero": { + "clear": [n.url for n in xmr_nodes if n.is_tor == False], + "onion": [n.url for n in xmr_nodes if n.is_tor == True] + }, + "wownero": { + "clear": [n.url for n in wow_nodes if n.is_tor == False], + "onion": [n.url for n in wow_nodes if n.is_tor == True] + } + }) + +@app.route("/wow_nodes.json") +def wow_nodes_json(): nodes = Node.select().where( Node.validated==True ).where( Node.nettype=="mainnet" ).where( - Node.crypto=="monero" + Node.crypto=="wownero" ) nodes = [n for n in nodes] return jsonify({ From 12c1d9b076dfb4c0e629bc31de0533abc53babf3 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 11 Jun 2021 14:15:16 -0700 Subject: [PATCH 4/4] include one more lib for pysocks --- Makefile | 4 ++++ requirements.txt | 1 + 2 files changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 94691a4..3108acf 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +setup: + python3 -m venv .venv + .venv/bin/pip install -r requirements.txt + up: docker-compose up -d diff --git a/requirements.txt b/requirements.txt index 6e9873d..8d2f218 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ peewee gunicorn arrow flask_wtf +pysocks