aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/getUsers.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2016-09-04 22:17:14 +0200
committerNoah Loomans <noahloomans@gmail.com>2016-09-04 22:17:14 +0200
commitfd7262bebcd6aff7e3ad229bd9e737816a2b23bc (patch)
tree6b82b7ee03e6d4c3083aff436cf2a9543af46a2a /public/javascripts/getUsers.js
Init commit
Diffstat (limited to 'public/javascripts/getUsers.js')
-rw-r--r--public/javascripts/getUsers.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/public/javascripts/getUsers.js b/public/javascripts/getUsers.js
new file mode 100644
index 0000000..d179bee
--- /dev/null
+++ b/public/javascripts/getUsers.js
@@ -0,0 +1,36 @@
+const Promise = require('bluebird')
+const cheerio = require('cheerio')
+const request = Promise.promisify(require('request'))
+const ty = require('then-yield').using(Promise.cast)
+
+module.exports = ty.async(function * () {
+ const page = (yield request(`http://${window.location.host}/meetingpointProxy/Roosters-AL%2Fdoc%2Fdagroosters%2Fframes%2Fnavbar.htm`)).body
+ const $ = cheerio.load(page)
+ const $script = $('script').eq(1)
+ const scriptText = $script.text()
+
+ const regexs = [/var classes = \[(.+)\];/, /var teachers = \[(.+)\];/, /var rooms = \[(.+)\];/, /var students = \[(.+)\];/]
+ const items = regexs.map(regex => scriptText.match(regex)[1].split(',').map(item => item.replace(/"/g, '')))
+
+ return []
+ .concat(items[0].map((item, index) => ({
+ type: 'c',
+ value: item,
+ index: index
+ })))
+ .concat(items[1].map((item, index) => ({
+ type: 't',
+ value: item,
+ index: index
+ })))
+ .concat(items[2].map((item, index) => ({
+ type: 'r',
+ value: item,
+ index: index
+ })))
+ .concat(items[3].map((item, index) => ({
+ type: 's',
+ value: item,
+ index: index
+ })))
+})