Update example
parent
c9ce6faed4
commit
c153eca68c
|
@ -28,16 +28,12 @@ import {
|
||||||
LatestSearchQuery,
|
LatestSearchQuery,
|
||||||
Game,
|
Game,
|
||||||
searchHandiwork,
|
searchHandiwork,
|
||||||
HandiworkSearchQuery,
|
HandiworkSearchQuery
|
||||||
Asset,
|
|
||||||
getHandiworkFromURL
|
|
||||||
} from "./index";
|
} from "./index";
|
||||||
|
|
||||||
// Configure the .env reader
|
// Configure the .env reader
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
main();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the user to enter the OTP code
|
* Ask the user to enter the OTP code
|
||||||
* necessary to authenticate on the server.
|
* necessary to authenticate on the server.
|
||||||
|
@ -56,39 +52,52 @@ async function insert2faCode(): Promise<number> {
|
||||||
return answers.code as number;
|
return answers.code as number;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
/**
|
||||||
// Local variables
|
* Authenticate on the platform.
|
||||||
const gameList = ["City of broken dreamers", "Seeds of chaos", "MIST"];
|
*/
|
||||||
|
async function authenticate(): Promise<boolean> {
|
||||||
// Log in the platform
|
// Log in the platform
|
||||||
console.log("Authenticating...");
|
console.log("Authenticating...");
|
||||||
const result = await login(process.env.F95_USERNAME, process.env.F95_PASSWORD, insert2faCode);
|
const result = await login(process.env.F95_USERNAME, process.env.F95_PASSWORD, insert2faCode);
|
||||||
console.log(`Authentication result: ${result.message}\n`);
|
console.log(`Authentication result: ${result.message}\n`);
|
||||||
|
|
||||||
// Manage failed login
|
return result.success;
|
||||||
if (!result.success) {
|
}
|
||||||
console.log("Failed authentication, impossible to continue");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get user data
|
/**
|
||||||
|
* Fetch and show data of the current logger user.
|
||||||
|
*/
|
||||||
|
async function fetchUserData(): Promise<void> {
|
||||||
console.log("Fetching user data...");
|
console.log("Fetching user data...");
|
||||||
const userdata = await getUserData();
|
|
||||||
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
|
const userdata = await getUserData();
|
||||||
|
|
||||||
|
const gameThreads = userdata.watched.filter((e) => e.forum === "Games");
|
||||||
|
const unread = gameThreads.filter((e) => e.unread).length;
|
||||||
|
|
||||||
|
console.log(`User: ${userdata.name}`);
|
||||||
|
console.log(`Threads followed: ${userdata.watched.length}`);
|
||||||
|
console.log(`Games followed: ${gameThreads.length}`);
|
||||||
|
console.log(`Unread game threads: ${unread}\n`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the data of the latest `3D game` updated.
|
||||||
|
*/
|
||||||
|
async function fetchLatestGameInfo(): Promise<void> {
|
||||||
const latestQuery: LatestSearchQuery = new LatestSearchQuery();
|
const latestQuery: LatestSearchQuery = new LatestSearchQuery();
|
||||||
latestQuery.category = "games";
|
latestQuery.category = "games";
|
||||||
latestQuery.includedTags = ["3d game"];
|
latestQuery.includedTags = ["3d game"];
|
||||||
|
|
||||||
const latestUpdates = await getLatestUpdates<Game>(latestQuery, 1);
|
const latestUpdates = await getLatestUpdates<Game>(latestQuery, 1);
|
||||||
console.log(`"${latestUpdates.shift().name}" was the last "3d game" tagged game to be updated\n`);
|
console.log(`"${latestUpdates.shift().name}" was the last "3d game" tagged game to be updated\n`);
|
||||||
|
}
|
||||||
|
|
||||||
// Get game data
|
/**
|
||||||
for (const gamename of gameList) {
|
* Fetch data of the games given theirs names.
|
||||||
|
*/
|
||||||
|
async function fetchGameData(games: string[]): Promise<void> {
|
||||||
|
for (const gamename of games) {
|
||||||
console.log(`Searching '${gamename}'...`);
|
console.log(`Searching '${gamename}'...`);
|
||||||
|
|
||||||
// Prepare the query
|
// Prepare the query
|
||||||
|
@ -109,3 +118,19 @@ async function main() {
|
||||||
} else console.log(`No data found for '${gamename}'\n`);
|
} else console.log(`No data found for '${gamename}'\n`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
if (await authenticate()) {
|
||||||
|
// Fetch and log user data
|
||||||
|
await fetchUserData();
|
||||||
|
|
||||||
|
// Get latest `3D GAME` game updated
|
||||||
|
await fetchLatestGameInfo();
|
||||||
|
|
||||||
|
// Get game data
|
||||||
|
const gameList = ["City of broken dreamers", "Seeds of chaos", "MIST"];
|
||||||
|
await fetchGameData(gameList);
|
||||||
|
} else console.log("Failed authentication, impossible to continue");
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
Loading…
Reference in New Issue