Guest User

Untitled

a guest
Jan 1st, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. var port = 4000;
  2. var express = require("express");
  3. var bodyParser = require('body-parser');
  4. var get_pharmacy = require("./routes/get_pharmacy.js");
  5. var app = express();
  6. var path = require("path");
  7. var cron = require('cron');
  8.  
  9. app.use('/static',express.static(path.join(__dirname, 'static')));
  10. app.use(bodyParser.json()); // support json encoded bodies
  11. app.use(bodyParser.urlencoded({ extended: true }));
  12. app.use("/get_pharmacy", get_pharmacy);
  13.  
  14. var job1 = new cron.CronJob({
  15. cronTime: '55 59 21 * * 1-7', // 00 00 22
  16. onTick: function() {
  17. var deleter = require("/home/ahmet/development_nuri/deleter.js");
  18. },
  19. start: false,
  20. timeZone: 'America/Los_Angeles'
  21. });
  22.  
  23. var job2 = new cron.CronJob({
  24. cronTime: '00 00 22 * * 1-7', // 00 00 22
  25. onTick: function() {
  26. var istanbul = require("/home/ahmet/development_nuri/scrap.js");
  27. },
  28. start: false,
  29. timeZone: 'America/Los_Angeles'
  30. });
  31. job1.start();
  32. job2.start();
  33.  
  34. process.on('uncaughtException', function (err) {
  35. console.log('UNCAUGHT', err.stack);
  36. });
  37.  
  38. app.listen(port);
  39.  
  40. var express = require("express");
  41. var mysql = require('mysql');
  42. var con = mysql.createConnection({
  43. host: "localhost",
  44. user: "root",
  45. password: "159487aa",
  46. database: "eczane",
  47. debug: false
  48. });
  49. var cities = [];
  50.  
  51. const router = express.Router();
  52.  
  53. setInterval(function () {
  54. con.query('SELECT 1');
  55. }, 5000);
  56.  
  57. function swap(a,b)
  58. {
  59. var temp=a;
  60.  
  61. }
  62.  
  63. function sortMeThender(data)
  64. {
  65.  
  66. var array = []
  67. for(var i=0; i<data.length; i++)
  68. {
  69. for(var x=0; x<data.length; x++)
  70. {
  71. if(data[i]["distance"] < data[x]["distance"])
  72. {
  73. var temp=data[x];
  74. data[x]=data[i];
  75. data[i]=temp;
  76. }
  77. }
  78. }
  79.  
  80. array.push(data[0]);
  81. array.push(data[1]);
  82. array.push(data[2]);
  83. array.push(data[3]);
  84. array.push(data[4]);
  85. return array;
  86.  
  87. }
  88.  
  89. router.route("/")
  90. .post(function(request, response) {
  91.  
  92. var lat = request.body.lat;
  93. var long = request.body.long;
  94.  
  95. con.query("select name,adress,town,city,phone,latitude,longitude from eczane", function (err, result) {
  96. if (err) throw err;
  97. cities.push(result);
  98. for (var i = 0; i < cities[0].length; i++) {
  99. cities[0][i]["distance"] = getDistanceFromLatLonInKm(lat, long, cities[0][i]["latitude"], cities[0][i]["longitude"]);
  100. }
  101. response.send(sortMeThender(cities[0]));
  102. });
  103.  
  104. function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
  105.  
  106. var R = 6371; // Radius of the earth in km
  107. var dLat = deg2rad(lat2-lat1); // deg2rad below
  108. var dLon = deg2rad(lon2-lon1);
  109. var a =
  110. Math.sin(dLat/2) * Math.sin(dLat/2) +
  111. Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
  112. Math.sin(dLon/2) * Math.sin(dLon/2)
  113. ;
  114. var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  115. var d = R * c; // Distance in km
  116. return d * 1000;
  117. }
  118.  
  119. function deg2rad(deg) {
  120. return deg * (Math.PI/180)
  121. }
  122. });
  123.  
  124. module.exports = router;
Add Comment
Please, Sign In to add comment