-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpeacock_start.erl
76 lines (62 loc) · 2.37 KB
/
peacock_start.erl
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
%% Author: Krisztian Litavszky
%% Mail: [email protected]
%% Personal number: 19860926-6153
%% Initializing module & exporting functions.
-module(peacock_start).
-compile(export_all).
%% It starts the module, runs inets libraries for http requests and takes source
%% code from a page for extracting event links, creates a
%% template for an Event, calls a function to find links.
get_info() ->
Name = [],
Description = [],
Time = "22:00 - 05:00",
Date = [],
Picture = [],
Event = [Name, Description, Time, Date, Picture],
inets:start(),
{ok, {{_Version, 200, _ReasonPhrase}, _Headers, Body}} =
httpc:request("http://www.peacockdinnerclub.com/club"),
find_links(Body, Event),
loop().
makeref() ->
make_ref().
%% This function goes through all source code and is looking for
%% specified tag in order to find a place in source code where the link is
%% situated. Once it's found, it passes the source code to another function
find_links([$K, $o, $m, $m, $a, $n, $d, $e|T], Event) -> find_link(T, Event);
find_links([_H|T], Event) ->
find_links(T, Event).
find_link([$T, $i, $d, $i, $g, $a, $r, $e|_T], _Event) ->
srv ! {done, self()};
find_link([$h, $r, $e, $f, $=, $\"|T], Event) -> get_link(T,[],Event);
find_link([_H|T], Event) ->
find_link(T, Event).
%% Takes sources code which always starts from some link (thanks to "get_links"
%% function and extracts the link into variable "List" until required tag.
%% When it is extracted it gets a source code for the event that matches this
%% link(Body) and passes it to another module for parsing the information.
%% After it calls "get_links" again in order to find next link for an event.
get_link([$\", $>, $<|T], _List, Event) ->
find_link(T, Event);
get_link([$\", $>|T], List, Event) ->
{ok, {{_Version, 200, _ReasonPhrase}, _Headers, Body}} =
httpc:request("http://www.peacockdinnerclub.com" ++ lists:reverse(List)),
peacock:check_text(Body, Event),
find_link(T, Event);
get_link([H|T], List, Event) ->
get_link(T, [H|List], Event).
%% @author Tomasz Rakalski
%% The function for the process part, waits for messages from the server and
%% runs the process again after 6 hours (after timeout).
loop() ->
receive
{ok, _Pid} ->
io:format("confirmation received~n"),
loop();
stop ->
ok
after 2160000 ->
get_info(),
loop()
end.