Skip to content

Commit

Permalink
improve maps-scraper error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AV committed Jul 8, 2023
1 parent 5b5b40f commit 3f2b7b4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions superscraper/scrapers/maps/maps-scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,22 @@ async function handleRootEndpoint(req, res) {

async function handleMapsEndpoint(req, res) {
console.log(JSON.stringify(req.body, null, 2));
res.json({ result: 'ok' });

const locations = req.body.location;

/*
column_name | data_type
---------------------+--------------------------
time | timestamp with time zone
coordinates | USER-DEFINED
altitude | double precision
horizontal_accuracy | integer
altitude_accuracy | double precision
speed | double precision
is_moving | boolean
activity_type | text
activity_confidence | integer
*/

const data = [];
locations.forEach((location) => {
const coordinates = `POINT(${location.coords.longitude} ${location.coords.latitude})`;
Expand All @@ -70,7 +82,7 @@ async function handleMapsEndpoint(req, res) {
{
name: 'horizontal_accuracy',
value: location.coords.accuracy,
type: 'INTEGER',
type: 'DOUBLE PRECISION',
},
{
name: 'altitude_accuracy',
Expand All @@ -95,15 +107,18 @@ async function handleMapsEndpoint(req, res) {
{
name: 'activity_confidence',
value: location.activity.confidence,
type: 'INTEGER',
type: 'REAL',
},
]);
});

try {
await db.saveData(schema, tableName, data, uniqueColumns);
res.json({ result: 'ok' });
} catch (error) {
console.error('Error inserting location data', error);
res.status(500).json({ error: error.message });
//TODO: repeat this on other scrapers
}
}

Expand Down

0 comments on commit 3f2b7b4

Please sign in to comment.