-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmolejo-tesseract.js
58 lines (47 loc) · 1.24 KB
/
molejo-tesseract.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
'use strict';
let tesseract = require("node-tesseract"),
fs = require("fs"),
http = require("http");
const filename = "molejo-schedule.jpg";
var options = {
hostname: 'www.molejo.com.br',
port: 80,
path: '/mobile/index.jpg',
method: 'GET',
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36'
}
};
let download = (filename, cb) => {
console.log( "Downloading schedule ... " )
let fileStream = fs.createWriteStream(filename);
let req = http.get(options, (resp) => {
resp.pipe(fileStream);
fileStream.on("finish", () => {
console.log("-- Download finished")
fileStream.close(cb);
}).on("error", ( err ) => {
fs.unlink(filename);
console.log(`Err: ${err}`);
});
})
}
let processText = ( text ) => {
text.split("\n").forEach( (e) => {
let matches = e.match( /^[0-9]{2}\/[0-9]{2}/ );
if ( matches ) {
console.log(matches.input)
}
})
}
download(filename, () => {
let path = `${__dirname}/${filename}`;
console.log(`PATH: ${path}`)
tesseract.process(path, (err, text) => {
if(err) {
console.error(err);
} else {
processText(text)
}
})
})