Copy const axios = require('axios');
const fs = require('fs');
const path = require('path');
// Replace with your actual API key
const API_KEY = 'YOUR_API_KEY_HERE';
// Example parameters
const stationId = 'ABEP';
const year = 2025;
const dayOfYear = 1;
const listFilesUrl = `https://api.os.uk/positioning/osnet/v1/rinex/${year}/${dayOfYear}`;
const downloadDir = './downloads';
async function downloadRinexFiles() {
try {
const response = await axios.get(listFilesUrl, {
headers: { 'key': API_KEY }
});
const files = response.data;
if (!fs.existsSync(downloadDir)) {
fs.mkdirSync(downloadDir);
}
for (const file of files) {
const fileUrl = file.url;
const fileName = file.fileName;
if(fileName.startsWith(stationId)) {
console.log(`Downloading ${fileName}...`);
const filePath = path.join(downloadDir, fileName);
const fileResponse = await axios.get(fileUrl, {
headers: { 'key': API_KEY },
responseType: 'stream'
});
const writer = fs.createWriteStream(filePath);
fileResponse.data.pipe(writer);
}
}
console.log('All files downloaded.');
} catch (error) {
console.error('Error downloading RINEX files:', error.message);
}
}
downloadRinexFiles();