diff options
author | John Ankarström <john@ankarstrom.se> | 2022-03-06 22:37:19 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-03-06 22:37:19 +0100 |
commit | 06de1a12afaa2d3f4940290f87604eea9031c86d (patch) | |
tree | 685d64eb0036cdc5535dfcc374ed12b1a4b78d13 | |
parent | 23df5644c2ce8209a8387257f8d6942736008663 (diff) | |
download | EpisodeBrowser-06de1a12afaa2d3f4940290f87604eea9031c86d.tar.gz |
Update data for all episodes at once.
Previously, a remote request would be made once per episode.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | c/common.c | 3 | ||||
-rw-r--r-- | c/listview.c | 1 | ||||
-rw-r--r-- | pl/episode_data.pl | 53 |
4 files changed, 43 insertions, 16 deletions
@@ -11,7 +11,7 @@ LDFLAGS += -lcomctl32 -luxtheme ifeq ($(BUILD_MODE),debug) CFLAGS += -g else - CFLAGS += -O2 -ld-options,-mwindows + CFLAGS += -O -ld-options,-mwindows endif all: EpisodeBrowser.exe @@ -4,8 +4,7 @@ #include "resource.h" #include "defs.h" -/* Convert zero-terminated non-wide (multi-byte) string to - * zero-terminated wide/non-wide string depending on UNICODE. */ +/* Convert normal string to TSTR using given codepage. */ TCHAR * TszFromSz(const char *sz, int iCp) { diff --git a/c/listview.c b/c/listview.c index 40c3108..971c4e9 100644 --- a/c/listview.c +++ b/c/listview.c @@ -70,6 +70,7 @@ LvProc(HWND hLv, UINT uMsg, WPARAM wParam, LPARAM lParam) return CallWindowProc(LvPrevProc, hLv, uMsg, wParam, lParam); } +/* Enable/disable non-classic list view theme. */ void LvSetTheme(HWND hLv, int bUseTheme) { diff --git a/pl/episode_data.pl b/pl/episode_data.pl index a1b3a25..c6a5f3a 100644 --- a/pl/episode_data.pl +++ b/pl/episode_data.pl @@ -19,37 +19,64 @@ attach :- detach :- db_detach. +% Interface. + +lookup_episode(Ep, Name, Data) :- lookup_episode_local(Ep, Name, Data), !. +lookup_episode(Ep, Name, Data) :- lookup_episode_remote(Ep, Name, Data). + +lookup_episode_local(Ep, Name, Data) :- + episode_name_data(Ep, Name, Data). +lookup_episode_remote(Ep, Name, Data) :- + update, !, + episode_name_data(Ep, Name, Data). + + retract_episode(Ep) :- ( episode_name_data(Ep, _, _) -> retractall_episode_name_data(Ep, _, _) ; true ). +% Parsing. + padding(Ep) --> { Ep < 10 }, "00". padding(Ep) --> { Ep >= 10, Ep < 100 }, "0". padding(Ep) --> { Ep >= 100 }. episode_number(Ep) --> padding(Ep), integer(Ep). -lookup_episode(Ep, Name, Data) :- lookup_episode_local(Ep, Name, Data), !. -lookup_episode(Ep, Name, Data) :- lookup_episode_remote(Ep, Name, Data). +% Database updating. -lookup_episode_local(Ep, Name, Data) :- - episode_name_data(Ep, Name, Data). +update :- + remote(R0), !, + findall(Ep-Name-Data, (xpath(R0, //tr, R), + remote_episode(R, Ep), + remote_episode_name_data(R, Ep, Name, Data)), + ENDs), !, + maplist(update, ENDs). -lookup_episode_remote(Ep, Name, Data) :- +update(Ep-Name-Data) :- episode_name_data(Ep, Name, Data), !. +update(Ep-Name-Data) :- assert_episode_name_data(Ep, Name, Data). + +% Remote retrieval. + +remote(R) :- catch(http_load_html( 'https://www.detectiveconanworld.com/wiki/Next_Conan%27s_Hint', - D), + R), _, - fail), - xpath(D, //tr, D1), - xpath(D1, td(index(1),text), T), + fail). + +remote_episode(R, Ep) :- + xpath(R, td(index(1),text), T), + atom_number(T, Ep). + +remote_episode_name_data(R, Ep, Name, Data) :- + xpath(R, td(index(1),text), T), atom_phrase(episode_number(Ep), T), - xpath(D1, td(index(2),text), Name), - xpath(D1, td(index(3),text), Hint), - Data = ['Hint'(Hint)], - assert_episode_name_data(Ep, Name, Data). + xpath(R, td(index(2),text), Name), + xpath(R, td(index(3),text), Hint), + Data = ['Hint'(Hint)]. http_load_html(URL, DOM) :- setup_call_cleanup(http_open(URL, In, |