1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | const _HP = require("./classHotels.js");
|
16 | const _CONTROLLER = require("./bot_controller.js");
|
17 |
|
18 | const slave = _CONTROLLER.os.hostname().replace('slave','');
|
19 | const socket = _CONTROLLER.io.connect('http://192.168.254.89:88/', {
|
20 | query:'slave='+slave,
|
21 | reconnect: true
|
22 | });
|
23 |
|
24 |
|
25 |
|
26 | let currentip = '0.0.0.0';
|
27 | let errjobcounter = 0;
|
28 | let ipischanging = false;
|
29 | let client;
|
30 | let mobile;
|
31 | let api;
|
32 | let hostip;
|
33 | let hostport;
|
34 |
|
35 |
|
36 |
|
37 | const ADULT = {
|
38 | ERROR: 0,
|
39 | ONE : 1,
|
40 | TWO : 2
|
41 | };
|
42 | const JOB = {
|
43 | DONE:1,
|
44 | CITY_ID_LEFT:0
|
45 | };
|
46 |
|
47 |
|
48 | Number.prototype.isActive = function () {
|
49 | return(this!=0)
|
50 | };
|
51 | Object.prototype.prepareNextRequest = function (callback) {
|
52 |
|
53 | const arg = this;
|
54 |
|
55 |
|
56 | if(arg.cityid[0]=='' || !arg.cityid[0] || !arg.dates[0]){
|
57 | hp_bot.job.getNewJob(true)
|
58 |
|
59 | return null;
|
60 | }
|
61 |
|
62 |
|
63 | let city = arg.name.split(' ').join('+');
|
64 | let countcity = arg.cityid.length-1;
|
65 | let countdate = arg.dates.length-1;
|
66 |
|
67 |
|
68 | callback(arg.dates[countdate], city ,arg.cityid[countcity]);
|
69 | };
|
70 |
|
71 |
|
72 | const hp_bot = {
|
73 | "constructor": function JOB(_api=-1,_mobile=-1,_client='WDS',_host='192.168.56.1',_port='88') {
|
74 |
|
75 |
|
76 | api = _api;
|
77 | mobile = _mobile;
|
78 | client = _client;
|
79 | hostip = _host;
|
80 | hostport = _port;
|
81 |
|
82 |
|
83 |
|
84 | _CONTROLLER.start();
|
85 |
|
86 | socket.emit('slaves',slave)
|
87 |
|
88 |
|
89 | setInterval(()=>{
|
90 | socket.emit(slave,'says hello')
|
91 | },1000)
|
92 | },
|
93 | "init": function init() {
|
94 | setTimeout( async function start(){
|
95 |
|
96 |
|
97 | let job = await hp_bot.job.searchJob()
|
98 | console.log(job)
|
99 |
|
100 | async function startForeach()
|
101 | {
|
102 | job.prepareNextRequest(async function (startdate,cityname,cityid) {
|
103 |
|
104 | var bot = -5;
|
105 |
|
106 | if(mobile.isActive())
|
107 | bot = await hp_bot.bot.mobile(job,startdate,cityname,cityid);
|
108 |
|
109 | else if(api.isActive())
|
110 | bot = await hp_bot.bot.api(job,startdate,cityname,cityid)
|
111 |
|
112 | else
|
113 | bot = await hp_bot.bot.standart(job,startdate,cityname,cityid);
|
114 |
|
115 |
|
116 |
|
117 | if( bot == JOB.DONE )
|
118 | {
|
119 |
|
120 | console.log("=> JOB done <=")
|
121 | _HP.hotels.Booking = []
|
122 |
|
123 | hp_bot.job.saveJob([])
|
124 | hp_bot.job.nextJob(hp_bot.init)
|
125 | }
|
126 |
|
127 | else if( bot == JOB.CITY_ID_LEFT)
|
128 | {
|
129 | setTimeout(async function(){
|
130 | console.log("== next => ")
|
131 | job = await hp_bot.job.getOldJob();
|
132 | console.log(job)
|
133 | startForeach();
|
134 | },1000)
|
135 |
|
136 | }
|
137 |
|
138 | })
|
139 | }
|
140 |
|
141 | startForeach();
|
142 |
|
143 | },1800)
|
144 | },
|
145 | job: {
|
146 | 'getNewJob' : function getNewJob(rebootOnError=true) {
|
147 | console.log("");
|
148 | console.log("GETTING NEW JOB FROM DB... CLIENT:" +client );
|
149 |
|
150 | let data = "";
|
151 | let clientVersion = '2217'
|
152 |
|
153 | return new Promise(resolve=>{
|
154 |
|
155 |
|
156 |
|
157 | function makeRequest(clientversion){
|
158 | console.log('clientversion '+clientversion)
|
159 |
|
160 | _CONTROLLER.http.get('http://www.yieldagent.ch/relay/cityov/requestJobV8.php?version='+clientVersion+'&client='+client, function(res) {
|
161 | if (res.statusCode >= 200 && res.statusCode < 400)
|
162 | {
|
163 | res.on('data', function(data_) { data += data_.toString(); });
|
164 | res.on('end', function() {
|
165 | _CONTROLLER.parseXML(data, function (err, result) {
|
166 |
|
167 | try
|
168 | {
|
169 | if (result)
|
170 | {
|
171 |
|
172 | clientVersion = result.Request.$.clientVersion;
|
173 |
|
174 |
|
175 | _CONTROLLER.fs.writeFile('./clientVersion.txt', clientVersion, 'utf8', function readFileCallback(err, data) {
|
176 | if (err)
|
177 | console.log(err);
|
178 |
|
179 | else
|
180 | console.log("new Client Version "+clientVersion)
|
181 |
|
182 | });
|
183 |
|
184 |
|
185 | let ids = [];
|
186 | let city = result.Request.CityConfig[0].URLArguments[0];
|
187 | city = city.split(';city=');
|
188 |
|
189 | city.shift();
|
190 | city.forEach(t => {
|
191 | t = t.substr(0, t.indexOf(';'))
|
192 | ids.push(t)
|
193 | });
|
194 |
|
195 |
|
196 | let job = {
|
197 | "id": result.Request.CityConfig[0].CityID[0],
|
198 | "cityid": ids,
|
199 | "name": result.Request.CityConfig[0].CityName[0],
|
200 | "dates": result.Request.Dates[0].Date,
|
201 | "backup": result.Request.Dates[0].Date,
|
202 | "job": result.Request.JobID[0],
|
203 | "los": result.Request.$.los
|
204 | };
|
205 |
|
206 |
|
207 | hp_bot.job.saveJob(job);
|
208 |
|
209 |
|
210 | if(!result.Request.Dates[0].Date){
|
211 | hp_bot.general.errorHandler(job,1,_CONTROLLER.time().format('YYYY-MM-DD'),job.name,job.cityid,'{"error":"no date"}')
|
212 | hp_bot.job.saveJob([]);
|
213 | }
|
214 | if(!result.Request.CityConfig[0].CityName[0]){
|
215 | hp_bot.general.errorHandler(job,1,moment().format('YYYY-MM-DD'),'null',0,'{"error":"city"}')
|
216 | hp_bot.job.saveJob([]);
|
217 | }
|
218 |
|
219 | resolve(job)
|
220 | }
|
221 | if(err)
|
222 | {
|
223 | console.log(err)
|
224 | setTimeout(()=>{
|
225 | _CONTROLLER.reboot();
|
226 | },680000)
|
227 | }
|
228 | }
|
229 | catch (TypeError)
|
230 | {
|
231 |
|
232 | setTimeout( makeRequest(clientversion),8000);
|
233 |
|
234 |
|
235 | console.log("JOB parsing error")
|
236 | console.log(result.Request)
|
237 | console.log(" ")
|
238 | console.log("getting new jeb with new clientVersion:" +clientVersion)
|
239 |
|
240 |
|
241 | }
|
242 |
|
243 | });
|
244 | });
|
245 | }
|
246 | }).on('error',
|
247 | async function(err) {
|
248 |
|
249 |
|
250 | let version = await _CONTROLLER.version(false);
|
251 |
|
252 |
|
253 | console.log("Error while fetching new Job");
|
254 | console.log(err);
|
255 |
|
256 |
|
257 | let hosturl = 'http://'+hostip+':'+hostport;
|
258 | _CONTROLLER.fetch(hosturl+'/newip?gateway='+slave+'&client='+client+'&job=-1&version='+version);
|
259 |
|
260 |
|
261 | setTimeout(()=>
|
262 | {
|
263 | if(errjobcounter >=3 && rebootOnError == true)
|
264 | _CONTROLLER.fetch(hosturl+'/reboot?gateway='+slave+'&client='+client+'&job=error&version='+version);
|
265 |
|
266 | else
|
267 | _CONTROLLER.fetch(hosturl+'/newip?gateway='+slave+'&client='+client+'&version='+version).then(newIP=>{
|
268 | hp_bot.job.getNewJob();
|
269 | })
|
270 |
|
271 | errjobcounter++;
|
272 | },30000)
|
273 | }
|
274 | );
|
275 | }
|
276 |
|
277 |
|
278 | _CONTROLLER.fs.readFile('./clientVersion.txt','utf8', function read(err, data)
|
279 | {
|
280 | if (err)
|
281 | {
|
282 | console.log('no file: clientVersion.txt')
|
283 | makeRequest(clientVersion);
|
284 | return;
|
285 | }
|
286 | else
|
287 | {
|
288 | clientVersion = data;
|
289 | makeRequest(data)
|
290 | }
|
291 |
|
292 | });
|
293 | })
|
294 |
|
295 | },
|
296 | 'getOldJob' : function getOldJob() {
|
297 | console.log("searching for old job");
|
298 | try{
|
299 |
|
300 | const backup = JSON.parse(_CONTROLLER.fs.readFileSync('./backup.json', 'utf8'));
|
301 |
|
302 |
|
303 | const checkforid = backup.cityid[0];
|
304 | const checkfordate = backup.dates[0];
|
305 | return backup;
|
306 | }
|
307 | catch (TypeError)
|
308 | {
|
309 | console.log("no Job found..")
|
310 | return null
|
311 | }
|
312 | },
|
313 | 'searchJob' : async function () {
|
314 | var job = hp_bot.job.getOldJob();
|
315 |
|
316 | if(!job)
|
317 | job = await hp_bot.job.getNewJob();
|
318 | else
|
319 | console.log("BACKUP JOB FOUND");
|
320 |
|
321 | return job;
|
322 | },
|
323 | 'updateOldJob' : function (date,cityid,resetdate=false) {
|
324 | return new Promise(resolve=>{
|
325 |
|
326 | try{
|
327 |
|
328 | let backup = JSON.parse(_CONTROLLER.fs.readFileSync('./backup.json', 'utf8'));
|
329 | const indx = backup.dates.indexOf(date);
|
330 |
|
331 |
|
332 | if (indx > -1 && backup.dates.length>=1)
|
333 | {
|
334 | console.log("removing date")
|
335 | backup.dates.splice(indx, 1);
|
336 | console.log( " ")
|
337 | console.log("****dates left: "+ backup.dates.length)
|
338 | console.log( " ")
|
339 | }
|
340 |
|
341 |
|
342 | if( backup.dates.length==0)
|
343 | {
|
344 | console.log("removing city id")
|
345 | const indx2= backup.cityid.indexOf(cityid)
|
346 | if (indx2 > -1){
|
347 | backup.cityid.splice(indx2, 1);
|
348 | backup.dates = backup.backup;
|
349 | }
|
350 |
|
351 | if(backup.cityid.length==0){
|
352 | console.log("Clearing JOB")
|
353 | hp_bot.job.saveJob([]).then(r=>{
|
354 | resolve(JOB.DONE)
|
355 | });
|
356 |
|
357 | }
|
358 |
|
359 |
|
360 | }
|
361 |
|
362 |
|
363 | hp_bot.job.saveJob(backup).then(r=>{
|
364 | resolve(JOB.CITY_ID_LEFT)
|
365 | });
|
366 |
|
367 | }
|
368 | catch (TypeError)
|
369 | {
|
370 | console.log('!!! JOB NOT SAVED !!!')
|
371 | console.log(TypeError)
|
372 | resolve(false)
|
373 | }
|
374 | })
|
375 | },
|
376 | 'nextJob' : async function nextJob(callback) {
|
377 | console.log("get new Job")
|
378 | const newjob = await hp_bot.job.getNewJob();
|
379 | callback(newjob);
|
380 | },
|
381 | 'saveJob' : function (json) {
|
382 | if(!json)return;
|
383 | return new Promise(resolve=>{
|
384 |
|
385 |
|
386 | console.log(" ")
|
387 | console.log("Saving Job | backup.json");
|
388 | _CONTROLLER.fs.writeFile('./backup.json', JSON.stringify(json), 'utf8', function readFileCallback(err, data) {
|
389 | if (err)
|
390 | console.log(err);
|
391 | else
|
392 | console.log("JOB is SAVED")
|
393 |
|
394 | console.log(" ")
|
395 | resolve(true)
|
396 | })
|
397 | });
|
398 | },
|
399 | 'sendJobToHost': function (json_job,httpOrSocket='socket') {
|
400 | return new Promise(resolve => {
|
401 | if (httpOrSocket == 'socket') {
|
402 | socket.emit('jobdone', JSON.stringify(json_job), function (response) {
|
403 | console.log(response);
|
404 | resolve(response)
|
405 | });
|
406 | }
|
407 | })
|
408 | },
|
409 | },
|
410 | bot: {
|
411 | "mobile" : async function startMobileJob (arg,startdate,cityname,cityid,API=null) {
|
412 |
|
413 | console.log("->Fetching Mobile Version");
|
414 | const end = _CONTROLLER.time(startdate,'YYYY-MM-DD').add(1, 'day').format('YYYY-MM-DD');
|
415 | let counterror = 0;
|
416 | return new Promise(resolve=>{
|
417 | let adult =1;
|
418 |
|
419 | async function startFetch(adult) {
|
420 | console.log(startdate,cityname,cityid,adult);
|
421 |
|
422 | const xmlresult = await hp_bot.general.getXMLData(adult,startdate,end,cityname,cityid);
|
423 |
|
424 | const isvalid = hp_bot.general.validateXmlResult(xmlresult,arg,adult,startdate,cityname,cityid);
|
425 | if(!isvalid)return;
|
426 |
|
427 |
|
428 | const parsed = await _HP.methods.Booking.parsemobile(xmlresult.result,adult,startdate,end,cityname,cityid);
|
429 |
|
430 | if(parsed==ADULT.ONE){
|
431 | startFetch(2)
|
432 | }
|
433 | if(parsed==ADULT.TWO)
|
434 | {
|
435 | counterror = 0;
|
436 | const json = await _HP.methods.general.generateJson(_HP.hotels.Booking, arg.job, arg.id, startdate, slave);
|
437 |
|
438 | if(API)
|
439 | {
|
440 | API(json)
|
441 | resolve(json)
|
442 | }
|
443 | else
|
444 | {
|
445 | const answer = await hp_bot.job.sendJobToHost(json, 'socket');
|
446 | if (answer == 'OK')
|
447 | {
|
448 | console.log("SENDED: OK")
|
449 | let _status = await hp_bot.job.updateOldJob(startdate, cityid);
|
450 | resolve(_status)
|
451 | }
|
452 | else {
|
453 | startFetch(adult);
|
454 | }
|
455 | }
|
456 |
|
457 | }
|
458 | if(parsed==ADULT.ERROR){
|
459 |
|
460 | console.log("ip got blocked")
|
461 |
|
462 |
|
463 | if(4<counterror)
|
464 | {
|
465 | let message;
|
466 | try{
|
467 | message = allresult.errors[0].message;
|
468 | hp_bot.general.errorHandler(arg,adult,startdate,cityname,cityid,message,'Mobile Parser',true)
|
469 | }catch (TypeError)
|
470 | {
|
471 |
|
472 | if(JSON.stringify(allresult).indexOf('in_city_translation')>=0)
|
473 | {
|
474 | message = {'error':'in_city_translation no results found'}
|
475 | hp_bot.general.errorHandler(arg,adult,startdate,cityname,cityid,message,'Mobile Parser',true)
|
476 | }
|
477 | else
|
478 | {
|
479 | message = {'info':'no results found'}
|
480 | hp_bot.general.errorHandler(arg,adult,startdate,cityname,cityid,message,'Mobile Parser',true)
|
481 | }
|
482 | }
|
483 |
|
484 | counterror = 0;
|
485 | }
|
486 |
|
487 |
|
488 | setTimeout(()=>{
|
489 | hp_bot.general.getNewIP(ipischanging).then(gotNewIP=>
|
490 | {
|
491 | counterror++
|
492 | console.log('IP changes counter : '+counterror)
|
493 | ipischanging=false;
|
494 | startFetch(adult);
|
495 |
|
496 | })
|
497 | },1000)
|
498 | ipischanging =true;
|
499 |
|
500 | }
|
501 |
|
502 | console.log("PARSED RESULT "+ parsed)
|
503 |
|
504 |
|
505 | }
|
506 | startFetch(adult);
|
507 |
|
508 | })
|
509 | },
|
510 | "standart" : async function startSeleniumJOB(arg) {
|
511 | let isfetching = true;
|
512 | console.log("->Fetching Selenium Version");
|
513 | console.log("Selenium is still in testing mode.. ");
|
514 |
|
515 |
|
516 | if(arg.cityid[0]=='' || !arg.cityid[0])
|
517 | {
|
518 | hp_bot.job.nextJob(startSeleniumJOB);
|
519 | return
|
520 | }
|
521 |
|
522 | console.log("JOB FOUND:");
|
523 | console.log(arg);
|
524 | console.log("=====================");
|
525 | currentip = await _CONTROLLER.showExternalIP(true)
|
526 |
|
527 | let city = arg.name.replace(" ", '+');
|
528 | let icity = 0;
|
529 | let countcity = arg.cityid.length;
|
530 |
|
531 | let idate = 0;
|
532 | let countdate = arg.dates.length;
|
533 |
|
534 |
|
535 | nextCityId();
|
536 | function nextCityId() {
|
537 |
|
538 | if(icity==countcity && isfetching){
|
539 | console.log("Job Done");
|
540 | console.log(JSON.stringify(_HP.hotels.Booking));
|
541 | hp_bot.job.nextJob(startSeleniumJOB);
|
542 | }
|
543 |
|
544 | if(icity<countcity)
|
545 | {
|
546 | idate=0;
|
547 | nextDate(arg.cityid[icity])
|
548 | icity++;
|
549 | }
|
550 |
|
551 | }
|
552 | function nextDate(cityid) {
|
553 |
|
554 | _HP.hotels.Booking = [];
|
555 | const start = arg.dates[idate];
|
556 | fetchData(1,start,city,cityid);
|
557 | idate++;
|
558 | }
|
559 | function fetchData(adult,start,city,cityid) {
|
560 |
|
561 | const end = _CONTROLLER.time(start,'YYYY-MM-DD').add(1, 'day').format('YYYY-MM-DD');
|
562 | let room = 1;
|
563 | let child = 1;
|
564 |
|
565 | _HP.methods.Booking.get(cityid,city,start,end,room,adult,child,false,arg.job,arg.id).then(result=>{
|
566 |
|
567 | let isok = -1;
|
568 |
|
569 |
|
570 | if(isok==1||isok=='1'){
|
571 | fetchData(2,start,city,cityid);
|
572 | }
|
573 |
|
574 |
|
575 |
|
576 | if(isok==2||isok=='2')
|
577 | {
|
578 |
|
579 | _HP.methods.general.generateJson(_HP.hotels.Booking,arg.job,arg.id,start,slave).then(answer=>{
|
580 |
|
581 |
|
582 | if(idate==countdate){
|
583 | hp_bot.job.updateOldJob(start,cityid,arg.dates);
|
584 | nextCityId()
|
585 | }
|
586 |
|
587 |
|
588 | if(idate<countdate){
|
589 |
|
590 | console.log("=> going to next date: "+idate);
|
591 | hp_bot.job.updateOldJob(start,null,null);
|
592 | nextDate(cityid)
|
593 | }
|
594 |
|
595 | })
|
596 | }
|
597 |
|
598 |
|
599 | if(isok==0||isok=='0'){
|
600 |
|
601 | hp_bot.general.getNewIP().then(gotNewIP=>{
|
602 | fetchData(adult,start,city,cityid);
|
603 | })
|
604 | }
|
605 |
|
606 | })
|
607 |
|
608 | }
|
609 |
|
610 | },
|
611 | "api" : async function startApiJob() {}
|
612 | },
|
613 | general:{
|
614 | "generateDeviceID": function generateDeviceID(show = false) {
|
615 |
|
616 |
|
617 | let nr1 = Math.floor((Math.random() * 9999) + 1000);
|
618 | let nr2 = Math.floor((Math.random() * 9999) + 1000);
|
619 | let nr3 = Math.floor((Math.random() * 1) + 10);
|
620 | if(show)
|
621 | console.log('generateDeviceID: '+ `72331403-${nr1}-${nr2}-${nr3}`)
|
622 |
|
623 | return `72331403-${nr1}-${nr2}-${nr3}`
|
624 | },
|
625 | "getNewIP": function getNewIP(ischanging=false) {
|
626 |
|
627 | return new Promise(resolve=>{
|
628 |
|
629 | console.log('old ip: ' + currentip);
|
630 |
|
631 | hp_bot.general.generateDeviceID(true);
|
632 |
|
633 | _CONTROLLER.tor.newTorSession(async function(err){
|
634 | if(err)console.log(err)
|
635 | currentip = await _CONTROLLER.showExternalIP(false);
|
636 | console.log("new ip:"+currentip);
|
637 | setTimeout(()=>{
|
638 | resolve(currentip)
|
639 | },5000)
|
640 |
|
641 | })
|
642 |
|
643 | |
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 | })
|
665 | },
|
666 | "getXMLData": function fetchIphoneXMLData(adult,start,end,city,cityid) {
|
667 | return new Promise(resolve=>{
|
668 | const devid = hp_bot.general.generateDeviceID();
|
669 | const _url = `https://iphone-xml.booking.com/json/bookings.getHotelAvailabilityMobile?detail_level=1&genius_freebies=2&show_distance_cc=1&request_less_fields=2&show_facilities_review_score=1&show_last_minute_saving=1&include_translations=2&add_bh_info=1&languagecode=de&urgency=1&include_taxes=1&include_count=1&location_source=autocomplete&show_price_trend=1&show_deals=flash%2Clastm%2Csmart%2Cgenius&children_qty=0&low_av_alternatives=0&&&order_by=popularity&show_if_class_is_estimated=1&show_categories=v3&show_location_score=1&show_last_reservation_text=1&show_reinforcement_text=v2&show_filtered_facilities=1&show_if_no_cc_allowed=2&show_soldout=1&show_is_personalized_result=0&show_flash_saving=1&max_persons=-2&use_direct_payment=1&add_ctrip_info=1&include_rack_rate_savings=1&&include_url=1&bh_alt_urgency_msg=1&show_refundable=1&check_price_is_final=1&show_extra_charges=1&room_qty=1&show_if_city_center=1&available_rooms=0&price_buckets=100&flash_deals_amount_if_unsigned=2&show_low_availability=2&show_business_badge=1&autoextend=1&user_os=6.0.1&user_version=11.3.1-android&network_type=wifi&bt=1&arrival_date=${start}&departure_date=${end}&city_ids=${cityid.replace('city=', '').replace('|si=ai%2Cco%2Cci%2Cre%2Cdi', '')}&rows=5000&device_id=${devid}da-ef8edab1ad7f&guest_qty=${adult}`;
|
670 | const options = {
|
671 | headers: {
|
672 | 'Content-Type' : 'application/x-www-form-urlencoded',
|
673 | 'Authorization': 'Basic dGhlc2FpbnRzYnY6ZGdDVnlhcXZCeGdN'
|
674 | },
|
675 | url: _url,
|
676 | timeout: 900000
|
677 | };
|
678 |
|
679 |
|
680 | _CONTROLLER.tor.request(options, function (err, resp, body) {
|
681 | resolve(JSON.parse(body));
|
682 | })
|
683 | })
|
684 | },
|
685 | "validateXmlResult": function (xml,arg,adult,start,_city,cityid) {
|
686 |
|
687 | console.log("check validate");
|
688 |
|
689 | let xmlcity = null;
|
690 |
|
691 |
|
692 | const cityname = arg.name.trim().replace('/+/g','');
|
693 | const listcity = [];
|
694 |
|
695 | try
|
696 | {
|
697 |
|
698 | let found = false;
|
699 | xmlcity = xml.filter;
|
700 |
|
701 | if(xmlcity)
|
702 | xmlcity.forEach(fitler=>
|
703 | {
|
704 | if(fitler.id == 'city')
|
705 | {
|
706 | if(fitler.categories)
|
707 | fitler.categories.forEach(categorycity=>{
|
708 | listcity.push(categorycity.name);
|
709 | if(categorycity.name.toUpperCase().indexOf(cityname.toUpperCase())>=0)
|
710 | found = categorycity;
|
711 | })
|
712 | }
|
713 | });
|
714 |
|
715 | if(found==false && listcity.length>1)
|
716 | {
|
717 | let message = {'warrning':'city_ids did not match cityname '+cityname,
|
718 | 'list':listcity}
|
719 |
|
720 | hp_bot.general.errorHandler(arg,adult,start,cityname,cityid,message,'Mobile Parser',true);
|
721 | return null;
|
722 | }
|
723 | else
|
724 | {
|
725 | console.log("Data is valid")
|
726 | return true;
|
727 | }
|
728 |
|
729 | }
|
730 | catch (TypeError)
|
731 | {
|
732 | console.log(" error validate date")
|
733 | console.log(xmlcity)
|
734 | console.log(TypeError)
|
735 | return true;
|
736 | }
|
737 |
|
738 | },
|
739 | "errorHandler": function (arg,adult,start,city,cityid,message,type='mobile',rebootanddelete=false) {
|
740 |
|
741 | console.log( "errorHandler " + type)
|
742 | city =city.replace('/+/g','');
|
743 |
|
744 | const hosturl='http://'+hostip+':'+hostport+'/errorjob';
|
745 | let log = {
|
746 | "job" : JSON.stringify(arg),
|
747 | "jobid" : arg.job,
|
748 | "message": JSON.stringify(message) + ',{ "cityid":'+cityid+',"city":"'+city+'" }',
|
749 | "cityid" : cityid,
|
750 | "city" : city,
|
751 | "slave" : slave,
|
752 | "client" : client,
|
753 | };
|
754 |
|
755 | _CONTROLLER.request.post({
|
756 | headers: {'content-type' : 'application/x-www-form-urlencoded'},
|
757 | url: hosturl,
|
758 | json: true,
|
759 | form: {
|
760 | data: JSON.stringify(log)
|
761 | }
|
762 | },
|
763 | function(error, response, body){
|
764 |
|
765 |
|
766 |
|
767 | if(rebootanddelete){
|
768 |
|
769 | }
|
770 | });
|
771 | setTimeout(()=>{
|
772 | if(rebootanddelete){}
|
773 |
|
774 | else
|
775 | _CONTROLLER.version();
|
776 | },10000)
|
777 |
|
778 | }
|
779 | },
|
780 | };
|
781 |
|
782 |
|
783 | hp_bot.constructor.prototype.start = hp_bot.init;
|
784 | hp_bot.constructor.prototype.getNewJob = hp_bot.job.getNewJob;
|
785 | module.exports = hp_bot.constructor;
|
786 |
|
787 |
|
788 |
|
789 | process.on('uncaughtException', function (error) {
|
790 | console.log(error.stack);
|
791 | });
|
792 |
|
793 |
|
794 | socket.on('connect', function (socket) {
|
795 | console.log('Connected!');
|
796 | });
|
797 | socket.on('disconnect', function(){
|
798 | console.log("lost connection to server")
|
799 | socket.connect()
|
800 | socket.emit('slaves',slave)
|
801 | hp_bot.init();
|
802 |
|
803 | });
|