-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·68 lines (52 loc) · 1.62 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
/*
https://developer.foursquare.com/docs/api/getting-started
*/
const request = require('request');
const publicIp = require('public-ip');
const geoip = require('geoip-lite');
const dateformat = require('dateformat');
const path = require('path');
const ini = require('ini');
const fs = require('fs');
const os = require('os');
var configFile = path.join(os.homedir(), '.foursquare-here.ini'),
config = {
foursquare: {
client_id: '',
client_secret: ''
}
};
if(!fs.existsSync(configFile)) {
console.warn("\nCreation of empty config: "+ configFile);
console.warn("\nfill using your API auth data, https://it.foursquare.com/developers/apps\n\n");
fs.writeFileSync(configFile, ini.stringify(config) );
}
config = ini.parse(fs.readFileSync(configFile, 'utf-8'));
module.exports = {
init: function(keyword) {
publicIp.v4().then(function(ip) {
var geo = geoip.lookup(ip);
console.log('My Location: ', ip, geo.city, geo.ll);
request({
url: 'https://api.foursquare.com/v2/venues/explore',
method: 'GET',
qs: {
query: keyword,
client_id: config.foursquare.client_id,
client_secret: config.foursquare.client_secret,
ll: geo.ll.join(','),
v: dateformat(new Date(),'yyyymmdd'),
limit: 1
}
}, function(err, res, body) {
if (err) {
console.error(err);
} else {
var out = JSON.parse(body).response.groups[0].items[0].venue;
console.log( JSON.stringify(out,null,4) );
}
});
});
}
};