Skip to content

Commit 7c3e6cd

Browse files
authored
feat(scraper): add ArcaneScraper and transformer for arcanes (#714)
1 parent 4523a65 commit 7c3e6cd

File tree

7 files changed

+113
-15
lines changed

7 files changed

+113
-15
lines changed

build/parser.mjs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class Parser {
161161
const result = [];
162162

163163
const bar = new Progress(`Parsing ${category}`, items.length);
164+
164165
if (!items.length) {
165166
bar?.interrupt?.(`No ${category}`);
166167
return [];
@@ -192,7 +193,7 @@ class Parser {
192193
const result = cloneDeep(original);
193194

194195
if (result.rewardName) result.uniqueName = result.rewardName;
195-
this.addType(result);
196+
this.addType(result, data);
196197
this.addDamage(result);
197198
this.sanitize(result);
198199
this.addImageName(result, data.manifest);
@@ -229,7 +230,7 @@ class Parser {
229230
const result = cloneDeep(original);
230231

231232
if (result.rewardName) result.uniqueName = result.rewardName;
232-
this.addType(result);
233+
this.addType(result, data);
233234
this.sanitize(result);
234235
this.addImageName(result, data.manifest, previous);
235236
this.addCategory(result, category);
@@ -445,17 +446,25 @@ class Parser {
445446
* saved as /Lotus/Powersuits/*, meaning that Archwing has to be looked for
446447
* first, otherwise it would be considered a Warframe.
447448
* @param {Partial<Item>} item to have type adjusted on
449+
* @param {RawItemData} data raw context data
448450
*/
449-
addType(item) {
451+
addType(item, data) {
450452
if (item.parent) return;
451-
// eslint-disable-next-line no-restricted-syntax
452-
for (const type of types) {
453-
const contains = type.regex ? new RegExp(type.id, 'ig').test(item.uniqueName) : item.uniqueName.includes(type.id);
454-
if (contains) {
455-
if (type.append) item.type = `${item.type}${type.name}`;
456-
else item.type = type.name;
457-
// if (item.type !== type.name) console.error(`${item.name} didn't update types`)
458-
break;
453+
const arcane = data.wikia.arcanes.find((entry) => entry.name === item.name);
454+
if (arcane) {
455+
item.type = `${arcane.type} Arcane`;
456+
} else {
457+
// eslint-disable-next-line no-restricted-syntax
458+
for (const type of types) {
459+
const contains = type.regex
460+
? new RegExp(type.id, 'ig').test(item.uniqueName)
461+
: item.uniqueName.includes(type.id);
462+
if (contains) {
463+
if (type.append) item.type = `${item.type}${type.name}`;
464+
else item.type = type.name;
465+
// if (item.type !== type.name) console.error(`${item.name} didn't update types`)
466+
break;
467+
}
459468
}
460469
}
461470

@@ -917,6 +926,9 @@ class Parser {
917926
case 'upgrades':
918927
this.addModWikiaData(item, wikiaItem);
919928
break;
929+
case 'arcanes':
930+
this.addArcaneWikiaData(item, wikiaItem);
931+
break;
920932
default:
921933
break;
922934
}
@@ -987,6 +999,19 @@ class Parser {
987999
if (!wikiaItem.thumbnail) warnings.missingWikiThumb.push(item.name);
9881000
}
9891001

1002+
/**
1003+
* Add additional data for mods from the wiki
1004+
* @param {Item} item mod to append wikia data to
1005+
* @param {WikiaArcane} wikiaItem to pull data from
1006+
*/
1007+
addArcaneWikiaData(item, wikiaItem) {
1008+
item.wikiaThumbnail = wikiaItem.thumbnail;
1009+
item.wikiaUrl = wikiaItem.url;
1010+
item.transmutable = wikiaItem.transmutable;
1011+
item.type = wikiaItem.type;
1012+
if (!wikiaItem.thumbnail) warnings.missingWikiThumb.push(item.name);
1013+
}
1014+
9901015
/**
9911016
* Normalize Ogg vault dates to be technically ISO-8601 dates
9921017
* @param {OggDateStamp} vaultDate vault date to normalize

build/scraper.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Generator as RelicGenerator } from '@wfcd/relics';
44
import patchlogs from 'warframe-patchlogs';
55

66
import Progress from './progress.mjs';
7+
import ArcaneScraper from './wikia/scrapers/ArcaneScraper.mjs';
78
import ArchwingScraper from './wikia/scrapers/ArchwingScraper.mjs';
89
import CompanionScraper from './wikia/scrapers/CompanionScraper.mjs';
910
import ModScraper from './wikia/scrapers/ModScraper.mjs';
@@ -207,13 +208,14 @@ class Scraper {
207208
* @property {Array<WikiaMods>} mods
208209
* @property {Array<WikiaVersions>} versions
209210
* @property {Array<WikiaDucats>} ducats
211+
* @property {Array<WikiaArcanes>} arcanes
210212
*/
211213
/**
212214
* Get additional data from wikia if it's not provided in the API
213215
* @returns {WikiaData}
214216
*/
215217
async fetchWikiaData() {
216-
const bar = new Progress('Fetching Wikia Data', 7);
218+
const bar = new Progress('Fetching Wikia Data', 8);
217219
const ducats = [];
218220
const ducatsWikia = await get('https://wiki.warframe.com/w/Ducats/Prices/All', true);
219221
const $ = load(ducatsWikia);
@@ -231,6 +233,8 @@ class Scraper {
231233
bar.tick();
232234
const mods = await new ModScraper().scrape();
233235
bar.tick();
236+
const arcanes = await new ArcaneScraper().scrape();
237+
bar.tick();
234238
const versions = await new VersionScraper().scrape();
235239
bar.tick();
236240
const archwings = await new ArchwingScraper().scrape();
@@ -246,6 +250,7 @@ class Scraper {
246250
ducats,
247251
archwings,
248252
companions,
253+
arcanes,
249254
};
250255
}
251256

build/tradable.mjs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
const builtUntradable = ['Warframe', 'Throwing', 'Shotgun', 'Rifle', 'Pistol', 'Melee', 'Sword And Shield'];
22
const tradableConditions = (item) => !(builtUntradable.includes(item.type) && item.name.match(/Prime/gi));
33

4+
const tradableArcanes = [
5+
'Arcane',
6+
'Primary Arcane',
7+
'Secondary Arcane',
8+
'Melee Arcane',
9+
'Amp Arcane',
10+
'Zaw Arcane',
11+
'Kitgun Arcane',
12+
'Shotgun Arcane',
13+
'Sniper Arcane',
14+
'Operator Arcane',
15+
'Bow Arcane',
16+
'Warframe Arcane',
17+
];
18+
419
const tradableMods = [
520
'Arch-Melee Mod',
621
'Archwing Mod',
@@ -17,7 +32,16 @@ const tradableMods = [
1732
'Stance Mod',
1833
'Warframe Mod',
1934
];
20-
const tradableTypes = ['Arcane', 'Captura', 'Cut Gem', 'Fish', 'Focus Lens', 'Relic', 'Upgrades', ...tradableMods];
35+
const tradableTypes = [
36+
'Captura',
37+
'Cut Gem',
38+
'Fish',
39+
'Focus Lens',
40+
'Relic',
41+
'Upgrades',
42+
...tradableArcanes,
43+
...tradableMods,
44+
];
2145
const untradableTypes = [
2246
'Color Palette',
2347
'Exalted Weapon',

build/wikia/WikiaDataScraper.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ export default class WikiaDataScraper {
180180
things.push(transformedThing);
181181
})
182182
);
183-
184183
things.sort(nameCompare);
185184
} catch (e) {
186185
console.error(e.stack);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import WikiaDataScraper from '../WikiaDataScraper.mjs';
2+
import transformArcanes from '../transformers/transformArcanes.mjs';
3+
4+
export default class ArcaneScraper extends WikiaDataScraper {
5+
constructor() {
6+
super('https://wiki.warframe.com/w/Module:Arcane/data?action=edit', 'Arcane', transformArcanes);
7+
}
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default async (oldArcane, imageUrls) => {
2+
let newArcane;
3+
if (!oldArcane || !oldArcane.Name) {
4+
return undefined;
5+
}
6+
7+
try {
8+
const { Image, Name, Transmutable, Introduced, Type } = oldArcane;
9+
10+
newArcane = {
11+
name: Name,
12+
url: `https://wiki.warframe.com/w/${encodeURIComponent(Name.replace(/\s/g, '_'))}`,
13+
transmutable: Transmutable,
14+
introduced: Introduced,
15+
type: Type,
16+
thumbnail: imageUrls?.[Image],
17+
};
18+
} catch (error) {
19+
console.error(`Error parsing ${oldArcane.Name}`);
20+
console.error(error);
21+
}
22+
return newArcane;
23+
};

index.d.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ declare module 'warframe-items' {
249249
patchlogs?: PatchLog[];
250250
rarity?: Rarity;
251251
tradable: true;
252-
type: 'Arcane';
252+
type: 'Arcane' | `${ArcaneType} Arcane`;
253253
}
254254
interface StanceMod extends Omit<Mod, 'levelStats'> {
255255
type: 'Stance Mod';
@@ -299,6 +299,20 @@ declare module 'warframe-items' {
299299
| 'Peculiar'
300300
| 'Plexus'
301301
| 'Posture';
302+
303+
type ArcaneType =
304+
| 'Primary'
305+
| 'Secondary'
306+
| 'Melee'
307+
| 'Warframe'
308+
| 'Amp'
309+
| 'Operator'
310+
| 'Zaw'
311+
| 'Kitgun'
312+
| 'Bow'
313+
| 'Shotgun'
314+
| 'Sniper';
315+
302316
interface Mod extends MinimalItem, WikiaItem, Droppable {
303317
baseDrain: number;
304318
category: 'Mods';

0 commit comments

Comments
 (0)