pull/44/head
MillenniumEarl 2020-11-02 10:21:36 +01:00
parent d335f192cd
commit c88c9720a2
3 changed files with 33 additions and 44 deletions

View File

@ -122,7 +122,7 @@ module.exports.getGameData = async function (name, mod) {
const results = []; const results = [];
for (const url of urls) { for (const url of urls) {
// Start looking for information // Start looking for information
const info = scraper.getGameInfo(url); const info = await scraper.getGameInfo(url);
results.push(info); results.push(info);
} }
return results; return results;

View File

@ -305,10 +305,11 @@ function extractStructuredData(body) {
* Different processing depending on whether the game is a mod or not. * Different processing depending on whether the game is a mod or not.
* @param {String} text Structured text extracted from the game's web page * @param {String} text Structured text extracted from the game's web page
* @param {Boolean} mod Specify if it is a game or a mod * @param {Boolean} mod Specify if it is a game or a mod
* @returns {Promise<String>} Game description * @returns {String} Game description
*/ */
function getOverview(text, mod) { function getOverview(text, mod) {
shared.logger.trace("Extracting game overview..."); shared.logger.trace("Extracting game overview...");
// Get overview (different parsing for game and mod) // Get overview (different parsing for game and mod)
const overviewEndIndex = mod ? text.indexOf("Updated") : text.indexOf("Thread Updated"); const overviewEndIndex = mod ? text.indexOf("Updated") : text.indexOf("Thread Updated");
return text.substring(0, overviewEndIndex).replace("Overview:\n", "").trim(); return text.substring(0, overviewEndIndex).replace("Overview:\n", "").trim();

View File

@ -4,58 +4,46 @@
const dotenv = require("dotenv"); const dotenv = require("dotenv");
// Modules from file // Modules from file
const searcher = require("../app/scripts/searcher.js"); const F95API = require("../app/index.js");
const scraper = require("../app/scripts/scraper.js");
const Credentials = require("../app/scripts/classes/credentials.js");
const networkHelper = require("../app/scripts/network-helper.js");
const uScraper = require("../app/scripts/user-scraper.js");
// Configure the .env reader // Configure the .env reader
dotenv.config(); dotenv.config();
// Login
auth().then(async function searchGames(result) {
if(!result) return;
console.log("Fetching user data..."); main();
const userdata = await uScraper.getUserData();
console.log(`${userdata.username} follows ${userdata.watchedThreads.length} threads`);
// Search for Kingdom Of Deception data async function main() {
await search("kingdom of deception"); // Local variables
const gameList = [
// Search for Perverted Education data "kingdom of deception",
await search("perverted education"); "perverted education",
"corrupted kingdoms",
// Search for Corrupted Kingdoms data "summertime saga",
await search("corrupted kingdoms"); "brothel king"
];
// Search for Summertime Saga data
await search("summertime saga");
});
async function auth() {
console.log("Token fetch...");
const creds = new Credentials(process.env.F95_USERNAME, process.env.F95_PASSWORD);
await creds.fetchToken();
console.log(`Token obtained: ${creds.token}`);
// Log in the platform
console.log("Authenticating..."); console.log("Authenticating...");
const result = await networkHelper.autenticate(creds); const result = await F95API.login(process.env.F95_USERNAME, process.env.F95_PASSWORD);
console.log(`Authentication result: ${result.message}`); console.log(`Authentication result: ${result.message}`);
return result.success; // Get user data
console.log("Fetching user data...");
const userdata = await F95API.getUserData();
console.log(`${userdata.username} follows ${userdata.watchedThreads.length} threads`);
for(const gamename of gameList) {
console.log(`Searching '${gamename}'...`);
const found = await F95API.getGameData(gamename, false);
// If no game is found
if (found.length === 0) {
console.log(`No data found for '${gamename}'`);
continue;
} }
async function search(gamename) { // Extract first game
console.log(`Searching '${gamename}'...`); const gamedata = found[0];
const urls = await searcher.searchGame(gamename);
console.log(`Found: ${urls}`);
console.log("Scraping data...");
for (const url of urls) {
const gamedata = await scraper.getGameInfo(url);
console.log(`Found ${gamedata.name} (${gamedata.version}) by ${gamedata.author}`); console.log(`Found ${gamedata.name} (${gamedata.version}) by ${gamedata.author}`);
} }
console.log("Scraping completed!");
} }