-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.pl
44 lines (32 loc) · 1.11 KB
/
server.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
:- module(server, [server/0]).
:- use_module(library('http/thread_httpd')).
:- use_module(log).
:- use_module(lastfm_scrobbles).
:- use_module(lastfm_friends).
:- use_module(lastfm_events).
:- use_module(library('semweb/rdf_db')).
server(Port, Options) :-
http_server(reply,[ port(Port),timeout(20)| Options]).
reply(Request) :-
member(path(Path),Request),
atom_concat('/',UserRdf,Path),
atom_concat(User,'.rdf',UserRdf),!,
format('Content-type: application/rdf+xml; charset=UTF-8~n~n', []),
current_output(S),
set_stream(S,encoding(utf8)),
log:log('Generating RDF scrobble for ~w',[User]),
catch(scrobble_rdf(User,Triples1),_,Triples1=[]),
catch(friends_rdf(User,Triples2),_,Triples2=[]),
catch(events_rdf(User,Triples3),_,Triples3=[]),
flatten([Triples1,Triples2,Triples3],Triples4),
rdf_global_term(Triples4,Triples),
rdf_write_xml(S,Triples).
reply(Request) :-
member(path(Path),Request),
atom_concat('/',User,Path),!,
host(H),
format(atom(Redirect),'~w/~w.rdf',[H,User]),
throw(http_reply(see_other(Redirect),[])).
server :-
server(3060,[]),nl,
writeln(' - Server launched'),nl.