Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded task generation and misc tidy up #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
Node v22.4.0 required

To generate League tasks and Combat Tasks, with the above Node version installed run;

npm run cli tasks combat -- --legacy --json

npm run cli tasks leagues4 -- --legacy --json

Ensuring you have an "out" directory alongside /src/ this will generate 2 corresponding .JSONs for use.

Examples below;


{
"id": "1622",
"name": "Equip a Corrupted Bow of Faerdhinen",
"description": "Obtain and Equip a Corrupted Bow of Faerdhinen.",
"category": "Combat",
"tier": "Master",
"clientSortId": "1471"
},



{
"structId": 3453,
"sortId": 393,
"id": "3594",
"monster": "12",
"name": "Undying Raider",
"description": "Complete a Chambers of Xeric solo raid without dying.",
"category": "Combat",
"tier": "Master",
"clientSortId": "393"
},
110 changes: 110 additions & 0 deletions out2/UltimoCombiner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const axios = require('axios');
const fs = require('fs');
const path = require('path');

async function extractCategories() {
const categoriesUrl = 'https://raw.githubusercontent.com/osrs-reldo/os-league-tools/refs/heads/master/src/data/categories.js';
const outputFile = path.join(__dirname, 'categories.json');

try {
// Fetch the categories.js file
let categoriesScript = (await axios.get(categoriesUrl)).data;

// Use regex to find only the CATEGORY constant definition
const match = categoriesScript.match(/const CATEGORY\s*=\s*({[\s\S]*?});/);
if (!match) {
throw new Error('CATEGORY constant not found in categories.js');
}

// Extract the CATEGORY script portion
const categoryScript = match[1];

// Stub out `images` and other undefined variables
const sandbox = {
images: {}, // Stub `images` as an empty object
};

// Safely evaluate the CATEGORY object
const CATEGORY = eval(`
with (sandbox) {
(${categoryScript})
}
`);

// Write the CATEGORY object to a JSON file
fs.writeFileSync(outputFile, JSON.stringify(CATEGORY, null, 2));
console.log(`CATEGORY object extracted and saved to ${outputFile}`);
} catch (error) {
console.error('Error extracting CATEGORY object:', error.message);
}
}

async function fetchAndFormatData() {
const tasksUrl = 'https://raw.githubusercontent.com/osrs-reldo/task-json-store/refs/heads/main/tasks/LEAGUE_4.min.json';
const localFile = path.join(__dirname, 'leagues_4.json');
const categoriesFile = path.join(__dirname, 'categories.json');
const wikiScrapeUrl = 'https://raw.githubusercontent.com/osrs-reldo/task-json-store/refs/heads/main/tasks/LEAGUE_4.min.json';

try {
// Fetch tasks JSON data
const tasksResponse = await axios.get(tasksUrl);
const remoteData = tasksResponse.data;

// Fetch wiki scrape data
const wikiScrapeResponse = await axios.get(wikiScrapeUrl);
const wikiScrapeData = wikiScrapeResponse.data;

// Read leagues_4.json
const localData = JSON.parse(fs.readFileSync(localFile, 'utf-8'));

// Read preprocessed categories.json
const CATEGORY = JSON.parse(fs.readFileSync(categoriesFile, 'utf-8'));

// Combine and format data
const combinedData = {};

localData.forEach(localItem => {
const remoteItem = remoteData.find(remote => remote.structId === localItem.lookupstruct);
const wikiItem = wikiScrapeData.find(wiki => wiki.structId === localItem.lookupstruct);

if (remoteItem) {
// Format the object based on the previous years file.
const categoryKey = localItem.category.toUpperCase();
const category = CATEGORY[categoryKey];
const subcategory = category?.subcategories?.GENERAL || 'Unknown';

combinedData[localItem.id] = {
id: localItem.id,
label: localItem.name,
description: localItem.description,
skillReqs: wikiItem?.skills?.map(skill => ({
skill: skill.skill.toLowerCase(),
level: parseInt(skill.level, 10)
})) || [], // Map skills to lowercase skill names and integer levels
regions: [localItem.area],
difficulty: localItem.tier,
category: categoryKey,
subcategory: subcategory,
prerequisite: '', // Seemingly "dead" field ish.
};
}
});

// Write the formatted data to a new file
const outputFilePath = path.join(__dirname, 'formatted_leagues_4.json');
fs.writeFileSync(outputFilePath, JSON.stringify(combinedData, null, 2));

console.log('Formatted data written to:', outputFilePath);
} catch (error) {
console.error('Error during processing:', error.message);
}
}

(async function main() {
try {
await extractCategories();
await fetchAndFormatData();
} catch (error) {
console.error('Script failed:', error.message);
}
})();
Loading