Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Added words available to download
Browse files Browse the repository at this point in the history
  • Loading branch information
navaneeth committed Sep 17, 2013
1 parent d128875 commit 53b839d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 59 deletions.
35 changes: 3 additions & 32 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,12 @@
<head>
<meta charset="utf-8">
<title>Page Not Found :(</title>
<style>
::-moz-selection { background: #fe57a1; color: #fff; text-shadow: none; }
::selection { background: #fe57a1; color: #fff; text-shadow: none; }
html { padding: 30px 10px; font-size: 20px; line-height: 1.4; color: #737373; background: #f0f0f0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
html, input { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
body { max-width: 500px; _width: 500px; padding: 30px 20px 50px; border: 1px solid #b3b3b3; border-radius: 4px; margin: 0 auto; box-shadow: 0 1px 10px #a7a7a7, inset 0 1px 0 #fff; background: #fcfcfc; }
h1 { margin: 0 10px; font-size: 50px; text-align: center; }
h1 span { color: #bbb; }
h3 { margin: 1.5em 0 0.5em; }
p { margin: 1em 0; }
ul { padding: 0 0 0 40px; margin: 1em 0; }
.container { max-width: 380px; _width: 380px; margin: 0 auto; }
/* google search */
#goog-fixurl ul { list-style: none; padding: 0; margin: 0; }
#goog-fixurl form { margin: 0; }
#goog-wm-qt, #goog-wm-sb { border: 1px solid #bbb; font-size: 16px; line-height: normal; vertical-align: top; color: #444; border-radius: 2px; }
#goog-wm-qt { width: 220px; height: 20px; padding: 5px; margin: 5px 10px 0 0; box-shadow: inset 0 1px 1px #ccc; }
#goog-wm-sb { display: inline-block; height: 32px; padding: 0 10px; margin: 5px 0 0; white-space: nowrap; cursor: pointer; background-color: #f5f5f5; background-image: -webkit-linear-gradient(rgba(255,255,255,0), #f1f1f1); background-image: -moz-linear-gradient(rgba(255,255,255,0), #f1f1f1); background-image: -ms-linear-gradient(rgba(255,255,255,0), #f1f1f1); background-image: -o-linear-gradient(rgba(255,255,255,0), #f1f1f1); -webkit-appearance: none; -moz-appearance: none; appearance: none; *overflow: visible; *display: inline; *zoom: 1; }
#goog-wm-sb:hover, #goog-wm-sb:focus { border-color: #aaa; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); background-color: #f8f8f8; }
#goog-wm-qt:focus, #goog-wm-sb:focus { border-color: #105cb6; outline: 0; color: #222; }
input::-moz-focus-inner { padding: 0; border: 0; }
</style>
</head>
<body>
<div class="container">
<h1>Not found <span>:(</span></h1>
<p>Sorry, but the page you were trying to view does not exist.</p>
<p>It looks like this was the result of either:</p>
<ul>
<li>a mistyped address</li>
<li>an out-of-date link</li>
</ul>
<script>
var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),GOOG_FIXURL_SITE = location.host;
</script>
<script src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
</div>
</div>
</body>
</html>

8 changes: 7 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
var v = require('varnam'),
path = require('path'),
supportedLangs = ['ml', 'hi', 'gu'],
datadir = process.env.OPENSHIFT_DATA_DIR || "";
datadir = process.env.OPENSHIFT_DATA_DIR || "",
fs = require('fs');

function render404(res) {
res.status(404).sendfile('404.html');
}

function getSymbolsFilePath(langCode) {
return "vst/" + langCode + "-unicode.vst";
Expand Down Expand Up @@ -36,6 +41,7 @@ function getVarnamHandle(langCode) {
return handles[langCode];
}

exports.render404 = render404;
exports.getVarnamHandle = getVarnamHandle;
exports.supportedLangs = supportedLangs;
exports.getSymbolsFilePath = getSymbolsFilePath;
Expand Down
57 changes: 56 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var v = require('varnam'),
path = require('path')
path = require('path'),
helper = require('./helpers.js');

var datadir = process.env.OPENSHIFT_DATA_DIR || ""
console.log("Learning data will be stored in " + datadir)
Expand Down Expand Up @@ -68,12 +69,66 @@ function learn (req, res) {
else {
res.status(201).send("Success");
}

connection.release();
});
}
});
};

function wordsToDownload (req, res) {
var langCode = req.param('langCode'),
year = req.param('year'),
month = req.param('month'),
date = req.param('date'),
handle = helper.getVarnamHandle (langCode);

if (handle === undefined || isNaN (year) || isNaN (month) || isNaN (date)) {
helper.render404 (res);
return;
}

if (year.length != 4 || month.length > 2 || date.length > 2) {
helper.render404 (res);
return;
}

if (month.length == 1)
month = '0' + month;

if (date.length == 1)
date = '0' + date;

var dateStamp = year + '-' + month + '-' + date;
db.getConnection (function (err, connection) {
var q = 'select word, confidence from words_to_download where '
+ ' date(d) > date(trim(?)) and lang_code = trim(?) order by word';
if (err) {
res.status(500).send(err.message);
}
else {
connection.query(q, [dateStamp, langCode], function (err, rows, fields) {
if (err) {
res.status(500).send(err.message);
}
else {
res.set('Content-Type', 'text/plain');
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
res.write(row.word + ' ' + row.confidence + '\n');
}
res.end();
}
connection.release();
});
}
});

}

exports.supported_languages = supported_languages;
exports.tl = transliterate;
exports.rtl = reverse_transliterate;
exports.learn = learn;
exports.wordsToDownload = wordsToDownload;
exports.learn = learn;
20 changes: 11 additions & 9 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
var functions = require('../lib')

/*
* GET home page.
*/

exports.index = function(req, res){
res.render('index', { title: 'Express' });
};
var functions = require('../lib');
var helper = require('../lib/helpers.js');

app.get('/editor', function(req, res) {
res.render('editor');
Expand All @@ -18,3 +11,12 @@ app.get('/supported_languages', functions.supported_languages);
app.get('/tl', functions.tl);
app.get('/rtl', functions.rtl);
app.post('/learn', functions.learn);
app.get('/words/:langCode/:year/:month/:date', functions.wordsToDownload);

app.get('/', function(req, res) {
res.render('index', { title: 'Varnam' });
});

app.get("*", function(req, res) {
helper.render404(res);
});
20 changes: 4 additions & 16 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
// OpenShift sample Node application

var express = require('express');
var fs = require('fs');
var http = require('http')
, path = require('path');

var db = require("./lib/varnamdb");

// Local cache for static content [fixed and loaded at startup]
var zcache = { 'index.html': '' };
zcache['index.html'] = fs.readFileSync('./index.html'); // Cache index.html

// Create "express" server.
app = express();

Expand All @@ -20,23 +15,14 @@ app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
// app.use(express.logger('dev'));
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
});

var routes = require('./routes')

app.get('/', routes.index);

// Handler for GET /
app.get('/', function(req, res){
res.send(zcache['index.html'], {'Content-Type': 'text/html'});
app.use(app.router);
});

// Get the environment variables we need.
Expand Down Expand Up @@ -82,6 +68,8 @@ child.on('exit', function () {

child.start();

var routes = require('./routes')

// And start the app on that interface (and port).
app.listen(port, ipaddr, function() {
console.log('%s: Node server started on %s:%d ...', Date(Date.now() ),
Expand Down

0 comments on commit 53b839d

Please sign in to comment.