Skip to content

Instantly share code, notes, and snippets.

@thefinn93
Created May 28, 2012 03:12
Show Gist options
  • Save thefinn93/2817003 to your computer and use it in GitHub Desktop.
Save thefinn93/2817003 to your computer and use it in GitHub Desktop.
CJDNS registery
CREATE TABLE IF NOT EXISTS `nodes` (
`name` text NOT NULL,
`lat` double NOT NULL,
`lon` double NOT NULL,
`icon` text NOT NULL,
`ip` text NOT NULL,
`publickey` text NOT NULL,
`password` text NOT NULL,
`fcip` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
#!/usr/bin/env python
import httplib2
import sys
import requests
import json
from urllib import urlencode
from BeautifulSoup import BeautifulSoup
h = httplib2.Http("/tmp/.cache")
sys.stderr.write("Doadloding node list...\n");
r, content = h.request("http://[fc5d:baa5:61fc:6ffd:9554:67f0:e290:7535]/nodes/list.json", "GET")
nodes = json.loads(content)['nodes']
sys.stderr.write("Downloaded " + str(len(nodes)) + " nodes, checking for geolocation...\n");
geo = []
for i in nodes:
sys.stderr.write("Loading " + i['ip'] + "...\t")
r,infopage = h.request("http://[fc5d:baa5:61fc:6ffd:9554:67f0:e290:7535]/node/details/" + i['ip'], "GET")
soup = BeautifulSoup(infopage)
loc = soup.findAll(id='location-print')
if len(loc):
geocode = json.loads(requests.get("https://maps.googleapis.com/maps/api/geocode/json?" + urlencode({'address':loc[0].contents[0]}) + "&sensor=false").content)
if geocode['status'] == "OK":
sys.stderr.write("located in " + loc[0].contents[0] + "\n")
geo.append({"name":i['name'],"ip":i['ip'],"lat":geocode['results'][0]['geometry']['location']['lat'],"lon":geocode['results'][0]['geometry']['location']['lng']})
else:
sys.stderr.write("located in " + loc[0].contents[0] + ", which Google can't translate into a lat/lon: " + geocode['status'] + "\n")
else:
sys.stderr.write("Not specificed\n")
for node in geo:
sys.stderr.write("Logging " + node['name'] + " to stdout...\n")
print("INSERT INTO nodes (`name`,`lat`,`lon`,`fcip`) VALUES ('" + node['name'] + "', '" + str(node['lat']) + "', '" + str(node['lon']) + "', '" + node['ip'] + "');")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment