Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added geoip

  • Loading branch information...
commit 173a08d6bbad76b3f04284b931d80f6bd1992f0a 1 parent daf7e66
@jexp jexp authored
View
12 app.js
@@ -20,6 +20,7 @@ var express = require('express')
, content = require("./helpers/content")
, meetup = require("./helpers/meetup")
, paths = require("./helpers/path")
+ , geoip = require("./helpers/geoip")
var app = express();
@@ -69,6 +70,15 @@ app.configure(function(){
res.locals.run_experiment = app.get('env') == 'production' && res.locals.index_page
next();
});
+ app.use(function(req,res, next) {
+ try {
+ res.locals.region=geoip.region(req.connection.remoteAddress);
+ } catch(e) {
+ console.log("Error getting ip",req.connection.remoteAddress,e)
+ res.locals.region='US';
+ }
+ next();
+ });
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
@@ -301,7 +311,7 @@ app.locals.related = function(path,page) {
}
console.log(app.locals.related("java","java"))
-
+console.log(geoip.region('146.52.53.114'))
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
View
BIN  data/GeoIP.dat
Binary file not shown
View
1  helpers/calendar.js
@@ -56,6 +56,7 @@ function events(fun, filter) {
item.Group=meetup[1];
item.Meetup=meetup[2];
}
+ event_prop(item,'Area','US') // TODO
// console.log(item)
return item;
});
View
18 helpers/geoip.js
@@ -0,0 +1,18 @@
+var geoip = new require('maxmind-native').GeoIP('data/GeoIP.dat');
+
+var regions={ 'DE': ['DE','AT','CH'],
+ 'EU': ["DZ", "LU", "BH", "MT", "BY", "MC", "BE", "MA", "BA", "NL", "CY", "NG", "EG", "OM", "FI", "PK", "FR", "PL", "QA", "GH", "RU", "GG", "ZA", "IE", "ES", "IM", "SE", "IT", "JO", "SY", "KZ", "TN", "KE", "TR", "KW", "UA", "LB", "AE", "LI", "GB","UK"],
+ 'US' : ['US','CA']
+}
+function region(ipOrCountry) {
+ var country = ipOrCountry.length==2 ? ipOrCountry.toUpperCase() : geoip.getCountry(ipOrCountry, 'code');
+// console.log(country,ipOrCountry);
+ for (var region in regions) {
+ if ( regions[region].indexOf(country) != -1 ) return region;
+ }
+ return 'US'; // or WORLD ?
+}
+
+exports.region = region
+exports.country = function(ip) { return geoip.getCountry(ip, 'code'); }
+
View
1  package.json
@@ -10,6 +10,7 @@
"start": "node app"
},
"dependencies": {
+ "maxmind-native","0.1.2",
"rssparser" : "0.0.2",
"googleclientlogin" : "0.2.5",
"hooky-spreadsheets" : "0.0.4",
View
5 views/download/_download.ejs
@@ -3,7 +3,10 @@
<button class="btn btn-success dropdown-toggle" data-toggle="dropdown">Download <span
class="caret"></span></button>
<ul class="dropdown-menu">
- <% ["community","advanced","enterprise"].forEach(function(edition) { %>
+ <% ["community","advanced","enterprise"].forEach(function(edition) {
+ console.log(edition,version,platform);
+
+%>
<li><a href="<%= edition=='community' ? '/download_thanks':'http://info.neotechnology.com/download-Neo4j.html'%>?edition=<%= edition %>&amp;release=<%= version %>&amp;platform=<%= platform %>">
<%=: edition | capitalize %> <%= version %></a></li>
<% }) %>
View
2  views/foot.ejs
@@ -7,7 +7,7 @@
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/assets/js/jquery-1.8.1.min.js" type="text/javascript"></script>
-<script src="/assets/js/modernizr.js" type="text/javascript"></script>
+<!--script src="/assets/js/modernizr.js" type="text/javascript"></script-->
<script src="/assets/js/bootstrap.js" type="text/javascript"></script>
<script src="/assets/js/bootstrap-lightbox.js" type="text/javascript"></script>
<script src="/assets/js/bootstrap-transition.js" type="text/javascript"></script>
View
73 views/learn/events.ejs
@@ -1,59 +1,56 @@
<% include ../head %>
<div class="container">
- <!-- Example row of columns -->
- <div role="main" class="main row">
-
- <div class="span12">
-
+ <div role="main" class="main row span12">
<div class="inner">
<div id="apps" class="hero-unit path">
<h2><a><i class="icon icon-book"></i> <%= title %></a></h2>
<p class="lead">There are Neo4j related everywhere at every time. Pick one.</p>
</div>
- </div>
</div>
</div>
- <h3>Pernilla / Adam intro</h3>
-
- <p>If you want to learn more about Neo4j nothing beats a hands on experience. Listen to our community members and driver authors,
- talk to our engineers or discuss with our customers. There are many Neo4j Meetups, Trainings and Conferences happening everywhere and
- at any time.</p>
-
-
- <% var i;
- while (i<events.length) {
- %>
- <div class="thumbnails events row-fluid span12">
- <%
- for (var col=0;col<=4 && i+col < events.length;col++) {
- var event=events[i+col];
- %>
- <% include ../partials/_event %>
- <%
- }
- i+=4;
- %>
- </div>
- <%
- }
- events.forEach(function(event) { %>
- <% include ../partials/_event %>
- <% }); %>
+ <div role="main" class="main row span12">
+ <h3>Pernilla / Adam intro</h3>
+
+ <p>If you want to learn more about Neo4j nothing beats a hands on experience. Listen to our community members and driver authors,
+ talk to our engineers or discuss with our customers. There are many Neo4j Meetups, Trainings and Conferences happening everywhere and
+ at any time.</p>
+ </div>
+
+ Your region: <%= region %>
+
+ <% var i=0;
+ var myEvents = events.filter(function(event) { return !event['Area'] || event['Area']==region; });
+ while (i<myEvents.length) {
+ %>
+ <div class="thumbnails events row">
+ <%
+ for (var col=0;col<4 && i+col < myEvents.length;col++) {
+ var event=myEvents[i+col];
+ %>
+ <% include ../partials/_event %>
+ <%
+ }
+ i+=4;
+ %>
+ </div>
+ <%
+ }
+ %>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
- $('div.meetup').each(function() {
- var e=$(this);
- $.get("/meetup?group="+e.attr("group")+"&event="+e.attr("event"), function(data,err) {
- e.html(data);
- })
- })
+ $('div.meetup').each(function() {
+ var e=$(this);
+ $.get("/meetup?group="+e.attr("group")+"&event="+e.attr("event"), function(data,err) {
+ e.html(data);
+ })
+ })
})
</script>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.