first commit
This commit is contained in:
commit
54c7f25948
|
@ -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.
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^1.8.4",
|
||||||
|
"cheerio": "^1.0.0",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^5.1.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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}`);
|
||||||
|
});
|
Loading…
Reference in New Issue