Commit fffac646 authored by ZettaScript's avatar ZettaScript

Initial commit (v0.1.0)

parents
Pipeline #3674 failed with stages
in 1 minute and 11 seconds
This diff is collapsed.
# WorldWotMap
WorldWotMap v0.1.0, © 2018 Pascal Engélibert, Licence GNU AGPL v3
Ceci est une carte affichant les comptes Ğ1 et leurs certifications. La carte peut être incomplète, car il est facultatif de renseigner sa position géographique sur Cesium+.
Voir la carte en ligne : https://zettascript.org/tux/g1/worldwotmap.html
Une partie de duniter.db est exportée en JSON par `gencache.py` (opération faite par le serveur). Les données Cesium+ sont chargées par le navigateur depuis une instance Cesium.
## Installation
Générez le cache JSON à partir de duniter.db (il vous faut un serveur Duniter pour cela) (et python3-sqlite3) :
python3 gencache.py -d /chemin/vers/duniter.db -e
WorldWotMap nécessite jQuery et Leaflet. Modifiez les chemins dans le HTML en fonction de votre serveur.
https://leafletjs.com/
https://jquery.com/
C'est aussi plus joli avec une belle police, par exemple Proza Libre. https://fontlibrary.org/en/font/proza-libre
#!/usr/bin/env python3
"""
Dependances: python-sqlite3
Licence CC-0 (Public domain)
Compatible with WorldWotMap v0.1.0
"""
import math, sqlite3, sys, os, json
def getargv(argv, arg, default=""):
if arg in argv and len(argv) > argv.index(arg)+1:
return argv[argv.index(arg)+1]
else:
return default
def getCertsList(db):
certs = []
c = db.cursor()
c.execute("SELECT * FROM `c_index`")
while True:
data = c.fetchone()
if not data:
break
certs.append([data[1], data[2], data[6], data[7], data[11]])
return certs
def getIdentitiesList(db):
ids = {}
c = db.cursor()
c.execute("SELECT * FROM `i_index`")
while True:
data = c.fetchone()
if not data:
break
ids[data[2]] = [data[1], data[2], data[7], data[11]]
return ids
def exportJSON(outfile, data):
f = open(outfile, "w")
f.write(json.dumps(data))
f.close()
if __name__ == "__main__":
if "--help" in sys.argv:
print("""Duniter DB extractor
Licence CC0
Options:
-d <path> Change duniter.db path
default: ~/.config/duniter/duniter_default/duniter.db
-e <path> Export db in JSON to <path>
default: duniterdb.json
""")
exit()
dbpath = os.path.expanduser(getargv(sys.argv, "-d", "~/.config/duniter/duniter_default/duniter.db"))
db = sqlite3.connect(dbpath)
if "-e" in sys.argv:
exportJSON(getargv(sys.argv, "-e", "duniterdb.json"), {"certs":getCertsList(db), "ids":getIdentitiesList(db)})
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<title>WorldWotMap Ğ1</title>
<link rel="stylesheet" href="/js/leaflet/leaflet.css" />
<style type="text/css">
@font-face {
font-family: ProzaLibre;
font-weight: normal;
font-style: normal;
src: url(/fonts/ProzaLibre-Regular.ttf);
}
@font-face {
font-family: ProzaLibre;
font-weight: bold;
font-style: normal;
src: url(/fonts/ProzaLibre-Medium.ttf);
}
@font-face {
font-family: ProzaLibre;
font-weight: normal;
font-style: italic;
src: url(/fonts/ProzaLibre-Italic.ttf);
}
html, body {
margin: 0;
padding: 0;
}
body {
scroll-behavior: smooth;
background-color: #f2efe9;
}
#header {
width: calc(100% - 20px);
min-width: 200px;
margin: 0 10px;
padding: 0;
padding-bottom: 16px;
font-family: ProzaLibre, Verdana, sans-serif;
}
#header h1 {
font-size: 42px;
font-weight: bold;
}
#header-text {
max-width: 700px;
margin: auto;
}
#mapctn {
display: table;
}
#map {
display: table-cell;
width: 100%;
height: 100vh;
margin: 0;
padding: 0;
min-width: 200px;
min-height: 200px;
}
#mapmenu {
display: table-cell;
min-width: 200px;
font-family: ProzaLibre, Verdana, sans-serif;
}
#mapmenu li {
list-style-type: none;
}
a, a:visited {
color: #c8191b;
}
</style>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/leaflet/leaflet.js"></script>
</head>
<body>
<div id="header">
<div id="header-text">
<h1>WorldWotMap</h1>
<a href="#map">&#11015; Voir la map &#11015;</a>
<p>WorldWotMap v0.1.0, &copy; 2018 <a href="https://zettascript.org/contact.php">Pascal Engélibert</a> (<a href="https://www.gnu.org/licenses/agpl.html">Licence GNU AGPL v3</a>)</p>
<p>Ceci est une carte affichant les comptes Ğ1 et leurs certifications. La carte peut être incomplète, car il est facultatif de renseigner sa position géographique sur Cesium+.</p>
<a href="gencache.py">Programme Python pour exporter les données de duniter.db</a>
</div>
</div>
<div id="mapctn">
<div id="map"></div>
<div id="mapmenu">
<ul>
<li><a href="#header">&#11014; Haut de page &#11014;</a></li>
<li>Bleu&nbsp;: wallet</li>
<li>Rouge&nbsp;: identité</li>
</ul>
</div>
</div>
<script type="text/javascript">
class Account {
constructor(pubkey, title, pos, address, city, point) {
this.pubkey = pubkey;
this.title = title;
this.pos = pos;
this.address = address;
this.city = city;
this.point = point;
}
}
var accounts = {};
var map = L.map("map").setView([46.725, 2.834], 6);
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
$.post("https://g1.data.duniter.fr/user/profile/_search", '{"query":{"bool":{"must":[{"exists":{"field":"geoPoint"}}]}},"from":1000,"size":1000,"_source":["title","geoPoint","avatar._content_type","address","city","description"]}', function(data) {
var accounts_data = data["hits"]["hits"];
for(var i=0; i < accounts_data.length; i ++) {
var account = accounts_data[i];
var point = L.circle([account["_source"]["geoPoint"]["lat"], account["_source"]["geoPoint"]["lon"]], {
color: "#08f",
fillColor: "#08f",
fillOpacity: 0.1,
radius: 50
}).addTo(map);
point.bindPopup("<b>"+account["_source"]["title"]+"</b><br/>"+account["_id"]);
accounts[account["_id"]] = new Account(account["_id"], account["_source"]["title"], [account["_source"]["geoPoint"]["lat"], account["_source"]["geoPoint"]["lon"]], account["_source"]["address"], account["_source"]["city"], point);
}
$.get("duniterdb.json", null, function(data) {
for(id in data["ids"]) {
if(id in accounts) {
accounts[id].point.setStyle({color: "red", fillColor: "red"});
}
}
for(var i=0; i < data["certs"].length; i ++) {
if(data["certs"][i][0] in accounts && data["certs"][i][1] in accounts && data["certs"][i][3] == 0)
L.polyline([accounts[data["certs"][i][0]].pos, accounts[data["certs"][i][1]].pos], {color:'black', weight:1, opacity:0.3}).addTo(map);
}
});
});
</script>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment