-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.ts
44 lines (40 loc) · 1.6 KB
/
cron.ts
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
import { baseName, pathSep } from "./helpers";
import * as cons from "./constants";
var fs = require('fs');
var schedule = require('node-schedule');
var overpass = require('query-overpass');
export class OverpassJob {
private job: any;
constructor (schedule_string: string,
rel_query_dir: string,
rel_target_dir: string) {
var base_dir = process.cwd();
var complete_query_dir = base_dir + pathSep() + rel_query_dir;
var complete_target_dir = base_dir + pathSep() + rel_target_dir;
/* removed the scheduling for testing, now on start OP will queried */
//this.job = schedule.scheduleJob(schedule_string, function () {
startJob(complete_query_dir, complete_target_dir)
//});
}
}
function startJob (query_dir: string, target_dir: string) {
fs.readdir(query_dir, function(err, query_files) {
if (err) throw err;
for (var i in query_files) {
var query_file = query_dir + pathSep() + query_files[i];
var target_file = target_dir + pathSep() + baseName(query_files[i]) + cons.ENDING_OP;
writeTargetFile(query_file, target_file);
}
});
}
function writeTargetFile (query_file: string, target_file: string) {
fs.readFile(query_file, 'utf8', function(err, query) {
if (err) throw err;
overpass(query, function(err, data) {
fs.writeFile(target_file, JSON.stringify(data), function(err) {
if (err) throw err;
console.log('successfully wrote file ' + target_file);
});
});
});
}