-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.js
24 lines (21 loc) · 853 Bytes
/
misc.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
const request = require('request');
// this is some sample code that will scrape the printers from the CUPS web interface
function getPrinterUrls(callback) {
const CUPSurl = 'http://localhost:631/printers';// todo - change of you have CUPS running on other host
request(CUPSurl, (error, response, body) => {
if (!error && response.statusCode == 200) {
const printersMatches = body.match(/<TR><TD><A HREF="\/printers\/([a-zA-Z0-9-^"]+)">/gm);// i know, this is terrible, sorry(
var printersUrls = [];
let i;
if (printersMatches) {
for (i = 0; i < printersMatches.length; i++) {
const a = (/"\/printers\/([a-zA-Z0-9-^"]+)"/).exec(printersMatches[i]);
if (a) {
printersUrls.push(`${CUPSurl}/${a[1]}`);
}
}
}
}
callback(error, printersUrls);
});
}