aboutsummaryrefslogtreecommitdiff
path: root/pl
diff options
context:
space:
mode:
Diffstat (limited to 'pl')
-rw-r--r--pl/episode_data.pl29
1 files changed, 23 insertions, 6 deletions
diff --git a/pl/episode_data.pl b/pl/episode_data.pl
index 6fa5b8d..e944243 100644
--- a/pl/episode_data.pl
+++ b/pl/episode_data.pl
@@ -1,6 +1,8 @@
:- module(episode_data, [ensure_episode_data/0,
retract_episode/1,
- episode_count/1]).
+ episode_count/1,
+ rate_episode/2,
+ episode_rating/2]).
:- use_module(library(clpfd)).
:- use_module(library(dcg/basics)).
@@ -12,6 +14,7 @@
:- persistent episode_title(episode:integer, title:atom).
:- persistent episode_datum(episode:integer, key:atom, value:atom).
+:- persistent episode_rating(episode:integer, rating:integer).
attach :-
absolute_file_name('episode_data.db', F, [access(write)]),
@@ -37,6 +40,20 @@ episode_count(N) :-
setof(E, T^episode_title(E,T), Es),
last(Es, N).
+rate_episode(Ep, 0) :-
+ ( episode_rating(Ep, _)
+ -> retractall_episode_rating(Ep, _)
+ ; true
+ ),
+ !.
+
+rate_episode(Ep, R) :-
+ dif(R, 0),
+ ( episode_rating(Ep, R)
+ -> true
+ ; assert_episode_rating(Ep, R)
+ ).
+
% Remote data retrieval.
episode_number(Ep) --> integer(Ep).
@@ -80,14 +97,14 @@ remote_html(H) :-
remote_episode_title_data(Ep, Title, ['Date'-Date, 'Source'-Source, 'Hint'-Hint]) :-
remote_html(H),
xpath(H, //tr(td(index(3),@style='background:#f2fde9;')), R),
- xpath(R, td(index(1),text), Ep0),
+ xpath(R, td(index(1),normalize_space), Ep0),
atom_phrase(episode_number(Ep), Ep0),
- xpath(R, td(index(3),text), Title),
- xpath(R, td(index(4),text), Date),
- xpath(R, td(index(7),text), Source0),
+ xpath(R, td(index(3),normalize_space), Title),
+ xpath(R, td(index(4),normalize_space), Date),
+ xpath(R, td(index(7),normalize_space), Source0),
re_replace('\\(([0-9])', ' (\\1', Source0, Source1),
atom_string(Source, Source1),
- xpath(R, td(index(8),text), Hint).
+ xpath(R, td(index(8),normalize_space), Hint).
http_load_html(URL, DOM) :-
setup_call_cleanup(http_open(URL, In,