first commit

This commit is contained in:
Vichingo455 2025-06-01 12:13:22 +02:00
commit 54c7f25948
4 changed files with 1178 additions and 0 deletions

10
README.md Normal file
View File

@ -0,0 +1,10 @@
# Start Romagna Live Bus API
API for the Live Bus website.
## 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
## 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"
}
}

37
server.js Normal file
View File

@ -0,0 +1,37 @@
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 = 3001;
// Permette richieste da qualsiasi origine
app.use(cors());
// Route API che estrae i dati da GridView1
app.get('/', async (req, res) => {
try {
const response = await axios.get('https://infobus.startromagna.it/CapienzaAutobusTempoReale/');
const $ = cheerio.load(response.data);
const rows = [];
$('#GridView1 tr').each((i, row) => {
const columns = $(row).find('td').map((j, col) => $(col).text().trim()).get();
if (columns.length > 0) {
rows.push(columns);
}
});
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}`);
});