Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var port = 4000;
- var express = require("express");
- var bodyParser = require('body-parser');
- var get_pharmacy = require("./routes/get_pharmacy.js");
- var app = express();
- var path = require("path");
- var cron = require('cron');
- app.use('/static',express.static(path.join(__dirname, 'static')));
- app.use(bodyParser.json()); // support json encoded bodies
- app.use(bodyParser.urlencoded({ extended: true }));
- app.use("/get_pharmacy", get_pharmacy);
- var job1 = new cron.CronJob({
- cronTime: '55 59 21 * * 1-7', // 00 00 22
- onTick: function() {
- var deleter = require("/home/ahmet/development_nuri/deleter.js");
- },
- start: false,
- timeZone: 'America/Los_Angeles'
- });
- var job2 = new cron.CronJob({
- cronTime: '00 00 22 * * 1-7', // 00 00 22
- onTick: function() {
- var istanbul = require("/home/ahmet/development_nuri/scrap.js");
- },
- start: false,
- timeZone: 'America/Los_Angeles'
- });
- job1.start();
- job2.start();
- process.on('uncaughtException', function (err) {
- console.log('UNCAUGHT', err.stack);
- });
- app.listen(port);
- var express = require("express");
- var mysql = require('mysql');
- var con = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "159487aa",
- database: "eczane",
- debug: false
- });
- var cities = [];
- const router = express.Router();
- setInterval(function () {
- con.query('SELECT 1');
- }, 5000);
- function swap(a,b)
- {
- var temp=a;
- }
- function sortMeThender(data)
- {
- var array = []
- for(var i=0; i<data.length; i++)
- {
- for(var x=0; x<data.length; x++)
- {
- if(data[i]["distance"] < data[x]["distance"])
- {
- var temp=data[x];
- data[x]=data[i];
- data[i]=temp;
- }
- }
- }
- array.push(data[0]);
- array.push(data[1]);
- array.push(data[2]);
- array.push(data[3]);
- array.push(data[4]);
- return array;
- }
- router.route("/")
- .post(function(request, response) {
- var lat = request.body.lat;
- var long = request.body.long;
- con.query("select name,adress,town,city,phone,latitude,longitude from eczane", function (err, result) {
- if (err) throw err;
- cities.push(result);
- for (var i = 0; i < cities[0].length; i++) {
- cities[0][i]["distance"] = getDistanceFromLatLonInKm(lat, long, cities[0][i]["latitude"], cities[0][i]["longitude"]);
- }
- response.send(sortMeThender(cities[0]));
- });
- function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
- var R = 6371; // Radius of the earth in km
- var dLat = deg2rad(lat2-lat1); // deg2rad below
- var dLon = deg2rad(lon2-lon1);
- var a =
- Math.sin(dLat/2) * Math.sin(dLat/2) +
- Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
- Math.sin(dLon/2) * Math.sin(dLon/2)
- ;
- var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
- var d = R * c; // Distance in km
- return d * 1000;
- }
- function deg2rad(deg) {
- return deg * (Math.PI/180)
- }
- });
- module.exports = router;
Add Comment
Please, Sign In to add comment