Created
April 10, 2013 18:26
-
-
Save trevorstarick/5357170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var github = require("github"); | |
var request = require('request'); | |
var mysql = require('mysql'); | |
var city, username, longitude, latitude; | |
var connection = mysql.createConnection({ | |
host : "localhost", | |
user : "mysql", | |
password : "batman", | |
database : "geolocation" | |
}); | |
connection.connect(); | |
var github = new github({version: "3.0.0"}); | |
github.authenticate({ | |
type: "oauth", | |
token: "a1fcf3751e2c17657a5f50705cf6650f7b611c4c" | |
}); | |
function main(){ | |
github.events.get({page: 1, per_page: 1},function(err, res){ | |
username = res[0]['actor']['login']; | |
}); | |
github.user.getFrom({user: username}, function(err, res){ | |
city = res['location']; | |
}); | |
getlocation(city); | |
console.log(username+', '+city+', '+latitude+', '+longitude); | |
//io.sockets.emit('location', {lat: latitude, lng: longitude}); | |
} | |
function timestamp(){return Math.round((new Date()).getTime() / 1000);} | |
function getlocation(city){ | |
request('http://maps.googleapis.com/maps/api/geocode/json?address='+city+'&sensor=false', function(err,res,body){ | |
body = JSON.parse(body); | |
if (body['status'] == "OK") { | |
latitude = body["results"][0]["geometry"]["location"]['lat']; | |
longitude = body["results"][0]["geometry"]["location"]['lng']; | |
connection.query("INSERT INTO location (city,longitude,latitude,username,timestamp) VALUES('"+city+"','"+longitude+"','"+latitude+"','"+username+"','"+timestamp()+"');", function(err,rows,fields){}); | |
} | |
}); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment