-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
95 lines (89 loc) · 2.08 KB
/
app.js
File metadata and controls
95 lines (89 loc) · 2.08 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
const app = require('express')()
const axios = require('axios')
const {
cleanString,
getTableTag,
getBiodata,
removeTag,
} = require('./helper')
const {
getShow,
getMember,
} = require('./parser')
app.get('/', (req, res) => {
axios.get('https://jkt48.com/theater/schedule?lang=id')
.then(({ data }) => {
const table = getTableTag(data)
const perform = getShow(cleanString(table[0]))
const members = getMember(cleanString(table[1]))
console.log(members)
const show = []
let result = {}
perform.forEach((p, i) => {
for (let key in p) {
result[key] = p[key]
}
for (let key in members[i]) {
result[key] = members[i][key];
}
show.push(result)
result = {}
})
res.send(show)
return;
})
.catch(err => {
console.log(err)
})
})
app.get('/member', (req, res) => {
const url = req.query.u
axios.get(url)
.then(({ data }) => {
const biodata = getBiodata(data)
let result = {}
let key = ''
biodata.forEach(bio => {
const isContent = /bioright/.test(bio)
const content = removeTag(bio)
if (!isContent) {
switch (content) {
case 'Nama':
result.name = ''
key = 'name'
break;
case 'Tanggal Lahir':
result.birthdate = ''
key = 'birthdate'
break;
case 'Golongan Darah':
result.bloodType = ''
key = 'bloodType'
break;
case 'Horoskop':
result.horoscope = ''
key = 'horoscope'
break;
case 'Tinggi Badan':
result.height = ''
key = 'height'
break;
case 'Nama Panggilan':
result.nickname = ''
key = 'nickname'
break;
default:
result[content]
key = content
break;
}
} else {
result[key] = content
}
})
res.send(result)
return;
})
.catch(err => console.log(err))
})
app.listen(3000, () => console.log('on port 3000'))