-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
132 lines (107 loc) · 3.53 KB
/
Copy pathindex.js
File metadata and controls
132 lines (107 loc) · 3.53 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
120
121
122
123
124
125
126
127
128
129
130
131
const http = require('http');
const VoiceResponse = require('twilio').twiml.VoiceResponse;
var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
http
.createServer((req, res) => {
// Create TwiML response
var random = Math.floor(Math.random() * 64);
random += 1
url = `https://ichingfortune.com/hexagrams/${random}.php`;
request(url, function(error, response, html){
if(!error){
var $ = cheerio.load(html);
// parsing / regex functions
var textArray = $('h2').next().map( function() {
return $(this).text() //each element input gets turned into text output
});
var title = $('h1').text().replace(/I Ching/g, "")
var aboveBelow = $('#image').text().replace(/\n\t\t\t\t\t\t/g, " ");
aboveBelow = aboveBelow.toString().replace(/\n\t\t\t\t\t/g, " ");
var aboveBelowSplit = aboveBelow.split('Below')
var above = aboveBelowSplit[0]
var below = `Below${aboveBelowSplit[1]}`
var judgment = textArray[1].replace(/\n\t\t\t\t\t\t/g, " ")
var image = textArray[2].replace(/\n\t\t\t\t\t\t/g, " ")
var jsonObject =
{ reading :
{
title: title,
above: above,
below:below,
judgment:judgment,
image:image
}
}
}
const twiml = new VoiceResponse();
console.log(`${title}/n ${above}/n ${below}/n ${judgment}/n ${image}`)
twiml.say(`${title}`);
twiml.pause({
length: 1
});
twiml.say(`${above}`);
twiml.pause({
length: 1
});
twiml.say(`${below}`);
twiml.pause({
length: 1
});
twiml.say(`The Judgment`)
twiml.pause({
length: 1
});
twiml.say(`${judgment}`)
twiml.pause({
length: 1
});
twiml.say(`The Image`)
twiml.pause({
length: 1
});
twiml.say(`${image}`)
twiml.pause({
length: 1
});
res.writeHead(200, { 'Content-Type': 'text/xml' });
res.end(twiml.toString());
})
})
.listen(1337, '127.0.0.1');
console.log('TwiML server running at http://127.0.0.1:1337/');
function roll() {
var random = Math.floor(Math.random() * 64);
random += 1
url = `https://ichingfortune.com/hexagrams/${random}.php`;
request(url, function(error, response, html){
if(!error){
var $ = cheerio.load(html);
// parsing / regex functions
var textArray = $('h2').next().map( function() {
return $(this).text() //each element input gets turned into text output
});
var title = $('h1').text().replace(/I Ching/g, "")
var aboveBelow = $('#image').text().replace(/\n\t\t\t\t\t\t/g, " ");
aboveBelow = aboveBelow.toString().replace(/\n\t\t\t\t\t/g, " ");
var aboveBelowSplit = aboveBelow.split('Below')
var above = aboveBelowSplit[0]
var below = `Below${aboveBelowSplit[1]}`
var judgment = textArray[1].replace(/\n\t\t\t\t\t\t/g, " ")
var image = textArray[2].replace(/\n\t\t\t\t\t\t/g, " ")
var jsonObject =
{ reading :
{
title: title,
above: above,
below:below,
judgment:judgment,
image:image
}
}
}
res.send(jsonObject)
})
}