-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexes.js
More file actions
119 lines (117 loc) · 3.25 KB
/
indexes.js
File metadata and controls
119 lines (117 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var page=require('webpage').create();
var system=require('system');
if(system.args[1]){var q=system.args[1]}
else{var q="Ignis"}
if(system.args[2]){var postcode=system.args[2]}
else{var postcode="TS4 2ET"}
function timecheck(){
if((new Date().getMinutes())%5==0 && new Date().getMinutes() != new Date(start).getMinutes()){
search(true);
}
else{
console.log(new Date().getMinutes());
setTimeout(function(){timecheck()},30000)
}
}
page.onError = function(msg, trace) {}
function search(first){
if(first){
start=Date.now();
console.log("");
console.log(Date());
console.log("");
console.log("Searching site for "+q);
console.log("");
searchmachines=[];
}
page.open("https://cars.suzuki.co.uk/search/?searchSuzuki="+q,function(status){
var machine = page.evaluate(function(){
comments=document.head.childNodes;
for(x=0;x<comments.length;x++){
if(comments[x].nodeType==Node.COMMENT_NODE && comments[x].data.indexOf("Machine")>-1){
return comments[x].data+"returns "+document.querySelector(".search-counter").innerText.split(" for")[0];
}
}
});
if(searchmachines.indexOf(machine)==-1){
searchmachines.push(machine);
console.log(machine);
}
if(searchmachines.length==4){
findadealer(true);
}
else{
search(false);
}
});
}
function findadealer(first){
if(first){
console.log("");
console.log("Searching Find a Dealer for "+postcode);
console.log("");
fadmachines=[];
fadresults=[];
}
page.open("https://cars.suzuki.co.uk/find-a-dealer?PostcodeForDealers="+postcode,function(status){
var machine = page.evaluate(function(){
return Array.prototype.slice.call(document.head.childNodes).filter(function(x){return (x.nodeName=='#comment' && x.data.match('Machine'))})[0].data;
});
if(fadmachines.indexOf(machine)==-1){
fadmachines.push(machine);
setTimeout(function(){
var result = page.evaluate(function(){
if(document.querySelector(".address__header")){
return document.querySelector(".address__header").innerText;
}
else{
return "nothing";
}
});
fadresults.push(machine+"returns "+result);
console.log(machine+"returns "+result);
if(fadmachines.length==4){
end();
}
else{
findadealer(false);
}
},10000);
}
else{
findadealer(false);
}
});
}
function end(){
searchresults=[];
fadresults2=[];
for(x=0;x<4;x++){
searchresults.push(searchmachines[x].split(" returns")[1]);
fadresults2.push(fadmachines[x].split(" returns")[1]);
}
var uniquesearches = [];
for(i = 0;i < 4;i++){
if(uniquesearches.indexOf(searchresults[i])==-1){
uniquesearches.push(searchresults[i]);
}
}
var uniquedealers = [];
for(i = 0;i < 4;i++){
if(uniquedealers.indexOf(fadresults2[i])==-1){
uniquedealers.push(fadresults2[i]);
}
}
console.log("");
console.log("Finished in "+Math.round((Date.now()-start)/1000)+" seconds");
if(uniquesearches.length!=1){
console.log("");
console.log("!----------MACHINES' SEARCH INDEXES ARE OUT OF SYNC----------!");
}
if(uniquedealers.length!=1){
console.log("");
console.log("!----------MACHINES' DEALER INDEXES ARE OUT OF SYNC----------!");
}
timecheck();
}
search(true);