Adapt example to new API

pull/73/head
MillenniumEarl 2021-03-03 20:18:14 +01:00
parent ededed1cc8
commit 63b3e30def
1 changed files with 28 additions and 11 deletions

View File

@ -12,7 +12,14 @@ F95_PASSWORD = YOUR_PASSWORD
import dotenv from "dotenv"; import dotenv from "dotenv";
// Modules from file // Modules from file
import { login, getUserData, getLatestUpdates, getGameData} from "./index"; import { login,
getUserData,
getLatestUpdates,
LatestSearchQuery,
Game,
searchHandiwork,
HandiworkSearchQuery
} from "./index.js";
// Configure the .env reader // Configure the .env reader
dotenv.config(); dotenv.config();
@ -35,27 +42,37 @@ async function main() {
// Get user data // Get user data
console.log("Fetching user data..."); console.log("Fetching user data...");
const userdata = await getUserData(); const userdata = await getUserData();
console.log(`${userdata.username} follows ${userdata.watched.length} threads\n`); const gameThreads = userdata.watched.filter(e => e.forum === "Games").length;
console.log(`${userdata.name} follows ${userdata.watched.length} threads of which ${gameThreads} are games\n`);
// Get latest game update // Get latest game update
// const latestUpdates = await getLatestUpdates({ const latestQuery: LatestSearchQuery = new LatestSearchQuery();
// tags: ["3d game"] latestQuery.category = "games";
// }, 1); latestQuery.includedTags = ["3d game"];
// console.log(`"${latestUpdates[0].name}" was the last "3d game" tagged game to be updated\n`);
const latestUpdates = await getLatestUpdates<Game>(latestQuery, 1);
console.log(`"${latestUpdates.shift().name}" was the last "3d game" tagged game to be updated\n`);
// Get game data // Get game data
for(const gamename of gameList) { for(const gamename of gameList) {
console.log(`Searching '${gamename}'...`); console.log(`Searching '${gamename}'...`);
const found = await getGameData(gamename, false);
// If no game is found // Prepare the query
if (found.length === 0) { const query: HandiworkSearchQuery = new HandiworkSearchQuery();
query.keywords = gamename;
// Fetch the first result
const result = await searchHandiwork<Game>(query, 1);
// No game found
if (result.length === 0) {
console.log(`No data found for '${gamename}'`); console.log(`No data found for '${gamename}'`);
continue; continue;
} }
// Extract first game // Extract first game
const gamedata = found[0]; const gamedata = result.shift();
//console.log(`Found: ${gamedata.name} (${gamedata.version}) by ${gamedata.author}\n`); const authors = gamedata.authors.map((a, idx) => a.name).join(", ");
console.log(`Found: ${gamedata.name} (${gamedata.version}) by ${authors}\n`);
} }
} }