diff options
author | John Ankarström <john@ankarstrom.se> | 2022-04-03 01:09:09 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-04-03 01:09:09 +0200 |
commit | 388e5bf6f5c189c1f5657fded5246bb3b77a9dd9 (patch) | |
tree | 50cdc17516748ebe900cc52bdfa790e2cf2cd60f /pl/episode_data.pl | |
parent | 279b0c7764c3e49db72606c25dd7151137d66b70 (diff) | |
download | EpisodeBrowser-388e5bf6f5c189c1f5657fded5246bb3b77a9dd9.tar.gz |
Correctly fetch remote data for WPS episodes.
Diffstat (limited to 'pl/episode_data.pl')
-rw-r--r-- | pl/episode_data.pl | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/pl/episode_data.pl b/pl/episode_data.pl index 1bdde79..f71e2cb 100644 --- a/pl/episode_data.pl +++ b/pl/episode_data.pl @@ -4,6 +4,7 @@ lookup_episode_local/3, lookup_episode_remote/3]). +:- use_module(library(clpfd)). :- use_module(library(dcg/basics)). :- use_module(library(http/http_open)). :- use_module(library(sgml)). @@ -44,11 +45,12 @@ retract_episode(Ep) :- % Parsing. -padding(Ep) --> { Ep < 10 }, "00". -padding(Ep) --> { Ep >= 10, Ep < 100 }, "0". -padding(Ep) --> { Ep >= 100 }. +padding(Ep) --> { Ep #< 10 }, "00". +padding(Ep) --> { Ep #>= 10, Ep #< 100 }, "0". +padding(Ep) --> { Ep #>= 100 }. episode_number(Ep) --> padding(Ep), integer(Ep). +episode_number(Ep) --> padding(Ep), integer(Ep), "WPS", integer(_). % Database updating. @@ -56,10 +58,9 @@ ensure :- episode_name_data(_, _, _), !. ensure :- update. update :- - remote(R0), !, - findall(Ep-Name-Data, (xpath(R0, //tr, R), - remote_episode(R, Ep), - remote_episode_name_data(R, Ep, Name, Data)), + findall(Ep-Name-Data, (remote_row(R), + row_episode(R, Ep), + row_episode_name_data(R, Ep, Name, Data)), ENDs), !, maplist(update, ENDs). @@ -68,18 +69,19 @@ update(Ep-Name-Data) :- assert_episode_name_data(Ep, Name, Data). % Remote retrieval. -remote(R) :- +remote_row(R) :- catch(http_load_html( 'https://www.detectiveconanworld.com/wiki/Next_Conan%27s_Hint', - R), + R0), _, - fail). + fail), !, + xpath(R0, //tr, R). -remote_episode(R, Ep) :- +row_episode(R, Ep) :- xpath(R, td(index(1),text), T), - atom_number(T, Ep). + atom_phrase(episode_number(Ep), T). -remote_episode_name_data(R, Ep, Name, Data) :- +row_episode_name_data(R, Ep, Name, Data) :- xpath(R, td(index(1),text), T), atom_phrase(episode_number(Ep), T), xpath(R, td(index(2),text), Name), |