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 = [];
for (const url of urls) {
// Start looking for information
const info = scraper.getGameInfo(url);
const info = await scraper.getGameInfo(url);
results.push(info);
}
return results;

View File

@ -305,10 +305,11 @@ function extractStructuredData(body) {
* 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 {Boolean} mod Specify if it is a game or a mod
* @returns {Promise<String>} Game description
* @returns {String} Game description
*/
function getOverview(text, mod) {
shared.logger.trace("Extracting game overview...");
// Get overview (different parsing for game and mod)
const overviewEndIndex = mod ? text.indexOf("Updated") : text.indexOf("Thread Updated");
return text.substring(0, overviewEndIndex).replace("Overview:\n", "").trim();

View File

@ -4,58 +4,46 @@
const dotenv = require("dotenv");
// Modules from file
const searcher = require("../app/scripts/searcher.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");
const F95API = require("../app/index.js");
// Configure the .env reader
dotenv.config();
// Login
auth().then(async function searchGames(result) {
if(!result) return;
console.log("Fetching user data...");
const userdata = await uScraper.getUserData();
console.log(`${userdata.username} follows ${userdata.watchedThreads.length} threads`);
main();
// Search for Kingdom Of Deception data
await search("kingdom of deception");
// Search for Perverted Education data
await search("perverted education");
// Search for Corrupted Kingdoms data
await search("corrupted kingdoms");
// 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}`);
async function main() {
// Local variables
const gameList = [
"kingdom of deception",
"perverted education",
"corrupted kingdoms",
"summertime saga",
"brothel king"
];
// Log in the platform
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}`);
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`);
async function search(gamename) {
console.log(`Searching '${gamename}'...`);
const urls = await searcher.searchGame(gamename);
console.log(`Found: ${urls}`);
for(const gamename of gameList) {
console.log(`Searching '${gamename}'...`);
const found = await F95API.getGameData(gamename, false);
console.log("Scraping data...");
for (const url of urls) {
const gamedata = await scraper.getGameInfo(url);
// If no game is found
if (found.length === 0) {
console.log(`No data found for '${gamename}'`);
continue;
}
// Extract first game
const gamedata = found[0];
console.log(`Found ${gamedata.name} (${gamedata.version}) by ${gamedata.author}`);
}
console.log("Scraping completed!");
}