Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rows.forEach((row, index) => {
row = row.split(']').join('').trim().split(',');
// First column contains the hour of the recordings
var date = moment.tz(row[0], 'HH:mm', 'Europe/Stockholm').date(moment().date());
// Adapt date to yesterday for the relevant measurements
if (date > moment(rows[rows.length - 1], 'HH:mm').date(moment().date())) {
date.subtract(1, 'day');
}
date = {utc: date.toDate(), local: date.format()};
// Now loop over all the measurements, for now just try and insert them
// all and let them fail at insert time. This could probably be more
// efficient.
legend.forEach((e, i) => {
// Filter out time or background columns
if (e === 'Tid' || e.includes('bakgrund')) {
return;
}
var city = 'Stockholm';
if (e.includes('Uppsala')) city = 'Uppsala';
exports.fetchData = function (source, cb) {
// A workaround to getting rate limited for 6 logins in 1 hr for AirNow
// system. Only try to grab data in last 20 minutes of an hour.
if (moment().minute() < 40) {
return cb(null, {name: 'unused', measurements: []});
}
// First fetch the stations list and then get the latest measurements
const file = 'Locations/monitoring_site_locations.dat';
const lineToObj = function (line) {
const convertCity = function (city) {
if (!city) {
return;
}
return city.split(',')[0].trim();
};
return {
aqsid: line[0],
var makePostForm = function (station) {
// Get current date in Sao Paulo
var date = moment().tz('America/Sao_Paulo').format('DD-MM-YYYY');
return {
texData: date,
selEst: station
};
};
.filter(o => moment(o.value_datetime_inserted).utc().isAfter(timeLastInsert))
// eslint-disable-next-line eqeqeq
exports.fetchData = function (source, cb) {
// get the time 1 day ago in AEST
var timeAgo = moment().tz('Australia/Sydney').subtract(1, 'days').format('YYYY-MM-DDTHH:mm:ss');
// Fetch the data, for the last 24 hours
request({
uri: source.url,
qs: {
'$query': `select *, :id where (\`datetime\` > '${timeAgo}') order by \`datetime\` desc limit 1000`
}
}, function (err, res, body) {
if (err || res.statusCode !== 200) {
return cb({message: 'Failure to load data url.'});
}
// Wrap everything in a try/catch in case something goes wrong
try {
// Format the data
var data = formatData(JSON.parse(body), source);
if (data === undefined) {
$('tr.evenarg, tr.oddarg').each(function (i, e) {
let columns = $(this).children('td');
let dateText = $(columns).first().text();
let dateTime = getFullDate(dateText);
if (dateTime.isValid()) {
lastFullDate = dateTime;
} else {
if (lastFullDate) {
let dayTime = moment(dateText, 'HH:mm');
dateTime = moment.tz(
{
year: lastFullDate.year(),
month: lastFullDate.month(),
day: lastFullDate.date(),
hour: dayTime.hour(),
minute: dayTime.minute()
},
'Europe/Moscow');
} else {
// no known full date?
// you've got a problem
}
}
for (let i in parameters) {
const generateRequests = (source) => {
return [moment().format('YYYYMMDD'), moment().add(1, 'days').format('YYYYMMDD')].map((date) => {
const url = source.url.replace('', date);
return (done) => {
request.get({
url
}, (err, res, body) => {
if (err || res.statusCode !== 200) {
return done(null, []);
}
try {
const data = formatData(body, source);
return done(null, data);
} catch (e) {
return done(null, []);
}
});
};
pollutants.map(pollutant => {
const url = source.url + source.country + '_' + pollutant + '.csv';
const timeLastInsert = moment().utc().subtract(2, 'hours');
let header;
return new StringStream()
.use(stream => {
const resp = request.get({url})
.on('response', ({statusCode}) => {
+statusCode !== 200
? stream.end()
: resp.pipe(stream);
});
return stream;
})
.CSVParse({header: false, delimiter: ',', skipEmptyLines: true})
.shift(1, columns => (header = columns[0]))
.filter(o => o.length === header.length)
.map(o => header.reduce((a, c, i) => { a[c] = o[i]; return a; }, {}))
measurements = measurements.filter((m) => {
return moment().utc().diff(m.date.utc, 'hours') < 24;
});