fix ms datasource

This commit is contained in:
nyyu 2021-10-30 11:32:54 +02:00
parent 16947d2734
commit 34d50b419d

View file

@ -7,7 +7,10 @@ use crate::Champion;
pub struct MSDataSource; pub struct MSDataSource;
const CHAMP_PATTERN: &str = " href=\"https://www.metasrc.com/5v5/champion/";
impl DataSource for MSDataSource { impl DataSource for MSDataSource {
fn get_alias(&self) -> &str { fn get_alias(&self) -> &str {
"MS" "MS"
} }
@ -30,9 +33,9 @@ impl DataSource for MSDataSource {
.into_string() .into_string()
.unwrap(); .unwrap();
let mut pos: Option<usize> = page.find(" href=\"/5v5/champion/"); let mut pos: Option<usize> = page.find(CHAMP_PATTERN);
while let Some(mut p) = pos { while let Some(mut p) = pos {
p += 21; p += CHAMP_PATTERN.len();
let role = let role =
&page[p + page[p..].find('/').unwrap() + 1..p + page[p..].find('"').unwrap()]; &page[p + page[p..].find('/').unwrap() + 1..p + page[p..].find('"').unwrap()];
@ -44,7 +47,7 @@ impl DataSource for MSDataSource {
champs.insert(id, vec![role.to_string()]); champs.insert(id, vec![role.to_string()]);
let next = page[p..].find(" href=\"/5v5/champion/"); let next = page[p..].find(CHAMP_PATTERN);
if let Some(n) = next { if let Some(n) = next {
pos = Some(p + n); pos = Some(p + n);
} else { } else {