-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathhelper.js
75 lines (66 loc) · 1.91 KB
/
helper.js
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
var http = require("http");
var https = require("https");
var requrl = require("url");
module.exports = function()
{
this.execHttps = function (url, func, retry)
{
console.log("Parsing", url, retry);
var httpobj = http;
if (url.startsWith("https://"))
{
httpobj = https;
}
const parsedURL = requrl.parse(url);
const options = {
protocol: parsedURL.protocol,
hostname: parsedURL.hostname,
path: parsedURL.path,
headers: { 'User-Agent': 'Mozilla/5.0' },
};
httpobj.get(options, function(res)
{
res.setEncoding("utf8");
var source = "";
res.on("data", function(data)
{
source += data;
});
res.on("end", function()
{
if (source.indexOf("Server cannot process your request") != -1)
{
if (retry == 0)
{
func("");
}
else
{
//bad server
execHttps(url, func, retry-1);
}
}
else
{
func(source);
}
});
}).on("error", function(err)
{
console.log(err);
setTimeout(function()
{
func(source)
}, 1000);
});
}
this.MongoClient = require('mongodb').MongoClient;
this.mongourl = "mongodb://localhost:27017/codechefratingpredictor";
//openshift configuration
if (process.env.MONGODB_PASSWORD)
{
this.mongourl = "mongodb://" + process.env.MONGODB_USER + ":" + process.env.MONGODB_PASSWORD
+ "@" + process.env.MONGODB_SERVICE_HOST + ':' + process.env.MONGODB_SERVICE_PORT
+ '/' + process.env.MONGODB_DATABASE;
}
};