Skip to content

Commit

Permalink
Working on oculus scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNovak committed May 23, 2020
1 parent 88b92b3 commit 8ac259d
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 239 deletions.
12 changes: 12 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "auto"
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"name": "Start",
"program": "${workspaceFolder}\\app.js"
}
]
Expand Down
63 changes: 43 additions & 20 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
const _express = require("express");
const _express = require('express');
const _app = _express();
const _bodyParser = require("body-parser");
const _httpClient = require("./services/http-client");
const _steamScraper = require("./services/steam-scraper");
const _logger = require("./services/logger");
const _bodyParser = require('body-parser');
const _httpClient = require('./services/http-client');
const _steamScraper = require('./services/steam-scraper');
const _oculusScraper = require('./services/oculus-scraper');
const _logger = require('./services/logger');

const PORT = process.env.PORT || 8080;

function main() {
_app.use(_express.static("public"));
_app.use(_express.static('public'));
_app.use(_bodyParser.urlencoded({ extended: false }));
_app.use(_bodyParser.json());

_app.post("/api/app-scrape", async (req, res) => {
_app.post('/api/steam/app-scrape', async (req, res) => {
let appUrl = req.body.url;

let appPageHtml;
try {
appPageHtml = await _httpClient.get(appUrl);
} catch (error) {
_logger.error(error);
res.status(500).json({ message: "Error retrieving page HTML." });
res.status(500).json({ message: 'Error retrieving page HTML.' });
return;
}

Expand All @@ -30,49 +31,47 @@ function main() {
res.status(200).json(appPageData);
return;
} catch (error) {
if (error.type == "NO_GAME_ELEMENTS") {
if (error.type == 'NO_GAME_ELEMENTS') {
res.status(400).json({ message: error.message });
return;
}

_logger.error(error);
res.status(500).json({ message: "Error scraping page data." });
res.status(500).json({ message: 'Error scraping page data.' });
return;
}
});

_app.post("/api/search-scrape", async (req, res) => {
_app.post('/api/steam/search-scrape', async (req, res) => {
let searchUrl = req.body.url;
let searchPageHtml;
try {
searchPageHtml = await _httpClient.get(searchUrl);
} catch (error) {
_logger.error(error);
res.status(500).json({ message: "Error retrieving page HTML." });
res.status(500).json({ message: 'Error retrieving page HTML.' });
return;
}

try {
let searchPageData = _steamScraper.getSearchPageData(
searchPageHtml
);
let searchPageData = _steamScraper.getSearchPageData(searchPageHtml);
res.status(200).json(searchPageData);
return;
} catch (error) {
_logger.error(error);
res.status(500).json({ message: "Error scraping page data." });
res.status(500).json({ message: 'Error scraping page data.' });
return;
}
});

_app.post("/api/search-app-scrape", async (req, res) => {
_app.post('/api/steam/search-app-scrape', async (req, res) => {
let appUrl = req.body.url;
let appPageHtml;
try {
appPageHtml = await _httpClient.get(appUrl);
} catch (error) {
_logger.error(error);
res.status(500).json({ message: "Error retrieving page HTML." });
res.status(500).json({ message: 'Error retrieving page HTML.' });
return;
}

Expand All @@ -81,13 +80,37 @@ function main() {
res.status(200).json(appPageData);
return;
} catch (error) {
if (error.type == "NO_GAME_ELEMENTS") {
if (error.type == 'NO_GAME_ELEMENTS') {
res.status(400).json({ message: error.message });
return;
}

_logger.error(error);
res.status(500).json({ message: "Error scraping page data." });
res.status(500).json({ message: 'Error scraping page data.' });
return;
}
});

_app.post('/api/oculus/experience-scrape', async (req, res) => {
let experienceUrl = req.body.url;

let experiencePageHtml;
try {
experiencePageHtml = await _httpClient.get(experienceUrl);
} catch (error) {
_logger.error(error);
res.status(500).json({ message: 'Error retrieving page HTML.' });
return;
}

try {
let experiencePageData = _oculusScraper.getExperiencePageData(experiencePageHtml);
experiencePageData.link = experienceUrl;
res.status(200).json(experiencePageData);
return;
} catch (error) {
_logger.error(error);
res.status(500).json({ message: 'Error scraping page data.' });
return;
}
});
Expand Down
Loading

0 comments on commit 8ac259d

Please sign in to comment.