Skip to content

Commit a280ebc

Browse files
committed
Allow skipping parsing when fetching.
This has been made the default on `codex missing` and and `json fetch_all_matches_from_guide`. There is otherwise a `--noparse` option.
1 parent f219f67 commit a280ebc

File tree

6 files changed

+462
-235
lines changed

6 files changed

+462
-235
lines changed

‎ethi/src/cli.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ pub mod json {
7878
/// Makes `json refresh codex` a valid command.
7979
#[derive(clap::Args, Debug)]
8080
pub struct RefreshCodexCmd {
81+
/// Whether we should stop after just downloading the pages and skip the parsing of the
82+
/// pages.
83+
#[arg(short, long, default_value_t = false)]
84+
pub noparse: bool,
8185
/// Subcommand, if any.
8286
#[command(subcommand)]
8387
pub c: Option<RefreshCodex>,

‎ethi/src/codex/fetch.rs‎

Lines changed: 93 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ pub fn items(guide: &OrnaAdminGuide) -> Result<CodexItems, Error> {
2323
.map(|items| CodexItems { items })
2424
}
2525

26+
/// Retrieve all items from the codex without HTML parsing.
27+
pub fn items_no_parse(guide: &OrnaAdminGuide) -> Result<(), Error> {
28+
fetch_loop(
29+
&guide.codex_fetch_item_list()?,
30+
|slug| guide.codex_fetch_item_page(slug).map(|_| ()),
31+
"CItems",
32+
)
33+
.map(|_| ())
34+
}
35+
2636
/// Retrieve all searchable monsters from the codex.
2737
/// This does not fetch monsters from non-active events.
2838
pub fn monsters(guide: &OrnaAdminGuide) -> Result<CodexMonsters, Error> {
@@ -34,6 +44,17 @@ pub fn monsters(guide: &OrnaAdminGuide) -> Result<CodexMonsters, Error> {
3444
.map(|monsters| CodexMonsters { monsters })
3545
}
3646

47+
/// Retrieve all searchable monsters from the codex without HTML parsing.
48+
/// This does not fetch monsters from non-active events.
49+
pub fn monsters_no_parse(guide: &OrnaAdminGuide) -> Result<(), Error> {
50+
fetch_loop(
51+
&guide.codex_fetch_monster_list()?,
52+
|slug| guide.codex_fetch_monster_page(slug).map(|_| ()),
53+
"CMnstrs",
54+
)
55+
.map(|_| ())
56+
}
57+
3758
/// Retrieve all searchable bosses from the codex.
3859
/// This does not fetch bosses from non-active events.
3960
pub fn bosses(guide: &OrnaAdminGuide) -> Result<CodexBosses, Error> {
@@ -45,6 +66,17 @@ pub fn bosses(guide: &OrnaAdminGuide) -> Result<CodexBosses, Error> {
4566
.map(|bosses| CodexBosses { bosses })
4667
}
4768

69+
/// Retrieve all searchable bosses from the codex without HTML parsing.
70+
/// This does not fetch bosses from non-active events.
71+
pub fn bosses_no_parse(guide: &OrnaAdminGuide) -> Result<(), Error> {
72+
fetch_loop(
73+
&guide.codex_fetch_boss_list()?,
74+
|slug| guide.codex_fetch_boss_page(slug).map(|_| ()),
75+
"CBosses",
76+
)
77+
.map(|_| ())
78+
}
79+
4880
/// Retrieve all searchable raids from the codex.
4981
/// This does not fetch raids from non-active events.
5082
pub fn raids(guide: &OrnaAdminGuide) -> Result<CodexRaids, Error> {
@@ -56,6 +88,17 @@ pub fn raids(guide: &OrnaAdminGuide) -> Result<CodexRaids, Error> {
5688
.map(|raids| CodexRaids { raids })
5789
}
5890

91+
/// Retrieve all searchable raids from the codex without HTML parsing.
92+
/// This does not fetch raids from non-active events.
93+
pub fn raids_no_parse(guide: &OrnaAdminGuide) -> Result<(), Error> {
94+
fetch_loop(
95+
&guide.codex_fetch_raid_list()?,
96+
|slug| guide.codex_fetch_raid_page(slug).map(|_| ()),
97+
"CRaids",
98+
)
99+
.map(|_| ())
100+
}
101+
59102
/// Retrieve all skills from the codex.
60103
pub fn skills(guide: &OrnaAdminGuide) -> Result<CodexSkills, Error> {
61104
fetch_loop(
@@ -66,6 +109,16 @@ pub fn skills(guide: &OrnaAdminGuide) -> Result<CodexSkills, Error> {
66109
.map(|skills| CodexSkills { skills })
67110
}
68111

112+
/// Retrieve all skills from the codex without HTML parsing.
113+
pub fn skills_no_parse(guide: &OrnaAdminGuide) -> Result<(), Error> {
114+
fetch_loop(
115+
&guide.codex_fetch_skill_list()?,
116+
|slug| guide.codex_fetch_skill_page(slug).map(|_| ()),
117+
"CSkills",
118+
)
119+
.map(|_| ())
120+
}
121+
69122
/// Retrieve all searchable followers from the codex.
70123
/// This does not fetch followers from non-active events.
71124
pub fn followers(guide: &OrnaAdminGuide) -> Result<CodexFollowers, Error> {
@@ -77,8 +130,19 @@ pub fn followers(guide: &OrnaAdminGuide) -> Result<CodexFollowers, Error> {
77130
.map(|followers| CodexFollowers { followers })
78131
}
79132

133+
/// Retrieve all searchable followers from the codex without HTML parsing.
134+
/// This does not fetch followers from non-active events.
135+
pub fn followers_no_parse(guide: &OrnaAdminGuide) -> Result<(), Error> {
136+
fetch_loop(
137+
&guide.codex_fetch_follower_list()?,
138+
|slug| guide.codex_fetch_follower_page(slug).map(|_| ()),
139+
"CFollwrs",
140+
)
141+
.map(|_| ())
142+
}
143+
80144
/// Retrieve all missing items from the codex.
81-
pub fn missing_items(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexItems, Error> {
145+
pub fn missing_items(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<(), Error> {
82146
fetch_loop(
83147
&guide
84148
.codex_fetch_item_list()?
@@ -92,15 +156,15 @@ pub fn missing_items(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexIte
92156
.any(|item| item.slug == entry.slug())
93157
})
94158
.collect_vec(),
95-
|slug| guide.codex_fetch_item(slug),
159+
|slug| guide.codex_fetch_item_page(slug).map(|_| ()),
96160
"CItems",
97161
)
98-
.map(|items| CodexItems { items })
162+
.map(|_| ())
99163
}
100164

101165
/// Retrieve all missing searchable monsters from the codex.
102166
/// This does not fetch monsters from non-active events.
103-
pub fn missing_monsters(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexMonsters, Error> {
167+
pub fn missing_monsters(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<(), Error> {
104168
fetch_loop(
105169
&guide
106170
.codex_fetch_monster_list()?
@@ -114,15 +178,15 @@ pub fn missing_monsters(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<Codex
114178
.any(|monster| monster.slug == entry.slug())
115179
})
116180
.collect_vec(),
117-
|slug| guide.codex_fetch_monster(slug),
181+
|slug| guide.codex_fetch_monster_page(slug).map(|_| ()),
118182
"CMnstrs",
119183
)
120-
.map(|monsters| CodexMonsters { monsters })
184+
.map(|_| ())
121185
}
122186

123187
/// Retrieve all missing searchable bosses from the codex.
124188
/// This does not fetch bosses from non-active events.
125-
pub fn missing_bosses(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexBosses, Error> {
189+
pub fn missing_bosses(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<(), Error> {
126190
fetch_loop(
127191
&guide
128192
.codex_fetch_boss_list()?
@@ -136,15 +200,15 @@ pub fn missing_bosses(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexBo
136200
.any(|boss| boss.slug == entry.slug())
137201
})
138202
.collect_vec(),
139-
|slug| guide.codex_fetch_boss(slug),
203+
|slug| guide.codex_fetch_boss_page(slug).map(|_| ()),
140204
"CBosses",
141205
)
142-
.map(|bosses| CodexBosses { bosses })
206+
.map(|_| ())
143207
}
144208

145209
/// Retrieve all missing searchable raids from the codex.
146210
/// This does not fetch raids from non-active events.
147-
pub fn missing_raids(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexRaids, Error> {
211+
pub fn missing_raids(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<(), Error> {
148212
fetch_loop(
149213
&guide
150214
.codex_fetch_raid_list()?
@@ -158,14 +222,14 @@ pub fn missing_raids(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexRai
158222
.any(|raid| raid.slug == entry.slug())
159223
})
160224
.collect_vec(),
161-
|slug| guide.codex_fetch_raid(slug),
225+
|slug| guide.codex_fetch_raid_page(slug).map(|_| ()),
162226
"CRaids",
163227
)
164-
.map(|raids| CodexRaids { raids })
228+
.map(|_| ())
165229
}
166230

167231
/// Retrieve all missing skills from the codex.
168-
pub fn missing_skills(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexSkills, Error> {
232+
pub fn missing_skills(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<(), Error> {
169233
fetch_loop(
170234
&guide
171235
.codex_fetch_skill_list()?
@@ -179,15 +243,15 @@ pub fn missing_skills(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexSk
179243
.any(|skill| skill.slug == entry.slug())
180244
})
181245
.collect_vec(),
182-
|slug| guide.codex_fetch_skill(slug),
246+
|slug| guide.codex_fetch_skill_page(slug).map(|_| ()),
183247
"CSkills",
184248
)
185-
.map(|skills| CodexSkills { skills })
249+
.map(|_| ())
186250
}
187251

188252
/// Retrieve all missing searchable followers from the codex.
189253
/// This does not fetch followers from non-active events.
190-
pub fn missing_followers(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexFollowers, Error> {
254+
pub fn missing_followers(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<(), Error> {
191255
fetch_loop(
192256
&guide
193257
.codex_fetch_follower_list()?
@@ -201,22 +265,21 @@ pub fn missing_followers(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<Code
201265
.any(|follower| follower.slug == entry.slug())
202266
})
203267
.collect_vec(),
204-
|slug| guide.codex_fetch_follower(slug),
268+
|slug| guide.codex_fetch_follower_page(slug).map(|_| ()),
205269
"CFollwrs",
206270
)
207-
.map(|followers| CodexFollowers { followers })
271+
.map(|_| ())
208272
}
209273

210274
/// Retrieve all missing accessible data from the codex.
211-
pub fn missing(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<CodexData, Error> {
212-
Ok(CodexData {
213-
items: missing_items(guide, data)?,
214-
raids: missing_raids(guide, data)?,
215-
monsters: missing_monsters(guide, data)?,
216-
bosses: missing_bosses(guide, data)?,
217-
skills: missing_skills(guide, data)?,
218-
followers: missing_followers(guide, data)?,
219-
})
275+
pub fn missing(guide: &OrnaAdminGuide, data: &OrnaData) -> Result<(), Error> {
276+
missing_items(guide, data)?;
277+
missing_raids(guide, data)?;
278+
missing_monsters(guide, data)?;
279+
missing_bosses(guide, data)?;
280+
missing_skills(guide, data)?;
281+
missing_followers(guide, data)?;
282+
Ok(())
220283
}
221284

222285
/// Retrieve all items from the codex.
@@ -486,7 +549,7 @@ pub fn raid_slugs(guide: &OrnaAdminGuide, slugs: &[&str]) -> Result<CodexRaids,
486549
/// Retrieve skills with the given slugs from the codex.
487550
/// This function ignores errors.
488551
pub fn skill_slugs(guide: &OrnaAdminGuide, slugs: &[&str]) -> Result<CodexSkills, Error> {
489-
try_fetch_loop_slugs(slugs, |slug| guide.codex_fetch_skill(slug), "CRaids")
552+
try_fetch_loop_slugs(slugs, |slug| guide.codex_fetch_skill(slug), "CSkills")
490553
.map(|skills| CodexSkills { skills })
491554
}
492555

@@ -499,7 +562,7 @@ pub fn follower_slugs(guide: &OrnaAdminGuide, slugs: &[&str]) -> Result<CodexFol
499562

500563
/// Loop fetching entities and displaying a progress bar.
501564
/// Errors out after the first failed fetch.
502-
fn fetch_loop<Entry, F, Entity>(
565+
pub fn fetch_loop<Entry, F, Entity>(
503566
entries: &[Entry],
504567
fetch: F,
505568
kind: &str,
@@ -529,7 +592,7 @@ where
529592

530593
/// Loop fetching entities and displaying a progress bar.
531594
/// Ignore errors.
532-
fn try_fetch_loop_slugs<F, Entity>(
595+
pub fn try_fetch_loop_slugs<F, Entity>(
533596
slugs: &[&str],
534597
fetch: F,
535598
kind: &str,

0 commit comments

Comments
 (0)