From 3a2e4f64d02edf5e75da108d01f4d75a0c80666d Mon Sep 17 00:00:00 2001 From: Ulises Date: Sat, 18 Jun 2016 23:04:07 +0200 Subject: [PATCH] =?UTF-8?q?Configuraci=C3=B3n,=20dependencias=20y=20archiv?= =?UTF-8?q?o=20principal=20a=C3=B1adidos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.js | 8 +++ package.json | 25 +++++++ server.js | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 config.js create mode 100644 package.json create mode 100644 server.js diff --git a/config.js b/config.js new file mode 100644 index 0000000..fecb835 --- /dev/null +++ b/config.js @@ -0,0 +1,8 @@ +var pjson = require('./package.json'); + +var config = { + version: pjson.version, + sheetCode: "", +}; + +module.exports = config; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..7a284ad --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "curratelo", + "version": "0.0.1", + "description": "Ofertas de empleo de claidad para desarrolladores de calidad", + "main": "server.js", + "scripts": { + "start": "node server.js" + }, + "author": "Ulises Gascón", + "contributors": [ + { + "name": "Roberto Moryion", + "url": "https://github.com/astur4", + "hireable": true + } + ], + "license": "GPL-3.0", + "dependencies": { + "firebase": "3.0.5", + "jade": "1.11.0", + "pillars": "0.3.7", + "rsj": "0.0.4", + "scheduled": "0.4.5" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..80d613a --- /dev/null +++ b/server.js @@ -0,0 +1,179 @@ +var project = require('pillars'), + Scheduled = require("scheduled"), + jade = require('jade'), + config = require('./config'), + firebase = require('firebase'), + ProviderRSS = require('./providers/rss'), + ProviderSheets = require('./providers/sheets'), + fs = require('fs'); + +// Prototypes +String.prototype.textCleaner = function() { + var _self = this; + var finalText; + + finalText = _self.replace(/(<([^>]+)>)/ig,""); + finalText = finalText.replace(/(&([^>]+);)/ig,""); + finalText = finalText.replace(/\r?\n|\r/, " "); + + if (finalText.length > 400){ + finalText = finalText.substring(0,400) + ' ...'; + } + + return finalText; +}; + + +Date.prototype.getWeek = function(){ + var today = new Date(); + var StartDate = new Date(); + StartDate.setDate(StartDate.getDate() - 6); + return [StartDate.getTime(), today.getTime()]; +}; + +Date.prototype.isInFrame = function(dateTarget){ + var _self = this; + var currentWeek = _self.getWeek(); + return _self.getTime() <= currentWeek[1] && _self.getTime() >= currentWeek[0]; +}; + +// Inicialización de Firebase +firebase.initializeApp({ + serviceAccount: ".secret/serviceAccountCredentials.json", + databaseURL: config.databaseURL +}); + +// Fuentes RSS +var betabeers = new ProviderRSS({ + url: "https://betabeers.com/post/feed/", + provider_db: "betabeers", + provider: "Betabeers Empleos", + provider_logo: "https://betabeers.com/static/img/ios_icon.png", + outstanding: false +}); + +var stackoverflow = new ProviderRSS({ + url: "http://stackoverflow.com/jobs/feed", + provider_db: "stackoverflow", + provider: "Stackoverflow Jobs", + provider_logo: "http://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico", + outstanding: false +}); + +var github = new ProviderRSS({ + url: "https://jobs.github.com/positions.atom", + provider_db: "github", + provider: "Github Jobs", + provider_logo: "https://jobs.github.com/images/layout/invertocat.png", + outstanding: false +}); + +// Fuentes SHEETS +var destacados = new ProviderSheets({ + id: config.sheetCode, + provider_db: "destacados", + outstanding: true +}); + + +// Starting the project +project.services.get('http').configure({ + port: process.env.PORT || 8080 +}).start(); + + +// Template Engine +var templated = global.templated; +templated.addEngine('jade', function compiler(source, path) { + return jade.compile(source, { + filename: path, + pretty: false, + debug: false, + compileDebug: false + }); +}); + + +// Routes definition +var index = new Route({ + id: "index", + path: "/" + }, + function(gw) { + gw.render('./templates/index.jade', {datos: datos}); + }); + +var estatics = new Route({ + id: 'estatics', + path: '/*:path', + directory: { + path: './public', + listing: true + } +}); + + +// Adding Routes to Pillars +project.routes.add(index); +project.routes.add(estatics); + + +// Gestión de tareas automáticas +var datos; + +var rssJob = new Scheduled({ + id: "rssJob", + pattern: "2 * * * * *", // xx:02 + task: function(){ + github.uploadJobs(); + stackoverflow.uploadJobs(); + betabeers.uploadJobs(); + } +}).start(); + +var sheetJob = new Scheduled({ + id: "sheetJob", + pattern: "0 * * * * *", // xx:00 + task: function(){ + destacados.uploadJobs(); + } +}).start(); + + +var updateView = new Scheduled({ + id: "updateView", + pattern: "5 * * * * *", // xx:05 + task: function(){ + firebase.database().ref('/data/').once('value').then(function(snapshot) { + datos = snapshot.val(); + + if(!datos.betabeers){ + console.log("ERROR con Betabeers"); + } + + if(!datos.stackoverflow){ + console.log("ERROR con Stackoverflow"); + } + + if(!datos.github){ + console.log("ERROR con Github"); + } + if(!datos.destacados){ + console.log("ERROR con Destacados"); + } + var finalBlock = JSON.stringify(datos, null, 2); + fs.writeFile('datos.json', finalBlock, "UTF-8", function (err){ + if (err) { + throw err; + } + console.log('Copia de la base de datos en datos.json'); + }); + + + }); + } +}).start(); + +rssJob.launch(); +sheetJob.launch(); +updateView.launch(); \ No newline at end of file