Restore code

This commit is contained in:
Vichingo455 2025-06-01 12:26:26 +02:00
commit b308186e22
4 changed files with 1192 additions and 0 deletions

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# START Romagna Non-guaranteed Routes Monitor
API for START Romagna non-guaranteed routes monitor
## How to use
1. Download [Node.JS](https://nodejs.org/en/download) and install it
2. Download the repository and extract it
3. Open a command line on the folder you extracted the repository
4. Run ``npm install`` to install required modules, then ``node server.js`` to start the server instance
## API params
The API is called with 2 params:
- Bacino: Specifies the zone to check
- Data: the date to check routes
# Rights and credits
Start Romagna, Start and the Start Romagna logo are registered trademarks and protected by copyright by Start Romagna SpA. They are used here only for reference.

1123
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

8
package.json Normal file
View File

@ -0,0 +1,8 @@
{
"dependencies": {
"axios": "^1.8.4",
"cheerio": "^1.0.0",
"cors": "^2.8.5",
"express": "^5.1.0"
}
}

46
server.js Normal file
View File

@ -0,0 +1,46 @@
const express = require('express');
const axios = require('axios');
const cheerio = require('cheerio');
const cors = require('cors');
const path = require('path');
const app = express();
const port = 3003;
// Permette richieste da qualsiasi origine
app.use(cors());
// Route API che estrae i dati da monitor
app.get('/', async (req, res) => {
try {
const { Bacino, Data, exclude } = req.query;
const response = await axios.get(`https://servizi.startromagna.it/corsesoppresse/corsesopp?param1=${Bacino}&param2=${Data}`);
const $ = cheerio.load(response.data);
// Parse excluded column indexes from query
const excludeIndexes = exclude
? exclude.split(',').map(i => parseInt(i)).filter(i => !isNaN(i))
: [];
const rows = [];
$('#GridView1 tbody tr').each((i, row) => {
const allColumns = $(row).find('td').map((j, col) => $(col).text().trim()).get();
if (allColumns.length > 0) {
// Filter out excluded columns
const filteredColumns = allColumns.filter((_, idx) => !excludeIndexes.includes(idx));
rows.push(filteredColumns);
}
});
res.json(rows);
} catch (error) {
console.error(error);
res.status(500).send('Errore nel recupero dei dati');
}
});
app.listen(port, () => {
console.log(`Server avviato su http://localhost:${port}`);
});