Current section
Files
Jump to
Current section
Files
src/scrapbook@event.erl
-module(scrapbook@event).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([get_event/1, construct_event_request_from_url/2, construct_event_request_from_id/2, scrape_event_response/1]).
-export_type([event_photo/0, event_video/0, event_parent/0, event_sibling/0, event_basic_data/0, online_type/0, offline_location/0, offline_type/0, offline_city/0, event_place/0, host_type/0, event_host/0, event_time_details/0, event_data/0]).
-type event_photo() :: {event_photo,
binary(),
binary(),
gleam@option:option(binary())}.
-type event_video() :: {event_video,
binary(),
binary(),
gleam@option:option(binary())}.
-type event_parent() :: {event_parent, binary()}.
-type event_sibling() :: {event_sibling,
binary(),
integer(),
gleam@option:option(integer()),
event_parent()}.
-type event_basic_data() :: {event_basic_data,
binary(),
binary(),
integer(),
binary(),
gleam@option:option(event_photo()),
gleam@option:option(event_video()),
binary(),
boolean(),
gleam@option:option(event_parent()),
list(event_sibling())}.
-type online_type() :: messenger_room | third_party | facebook_live | other.
-type offline_location() :: {offline_location,
float(),
float(),
gleam@option:option(binary())}.
-type offline_type() :: text | place | city.
-type offline_city() :: {offline_city, binary(), binary()}.
-type event_place() :: {online, gleam@option:option(binary()), online_type()} |
{offline,
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(offline_location()),
offline_type(),
gleam@option:option(binary()),
gleam@option:option(offline_city())}.
-type host_type() :: user | page.
-type event_host() :: {event_host,
binary(),
binary(),
binary(),
host_type(),
binary()}.
-type event_time_details() :: {event_time_details,
integer(),
integer(),
binary()}.
-type event_data() :: {event_data,
event_basic_data(),
binary(),
gleam@option:option(event_place()),
list(event_host()),
event_time_details(),
gleam@option:option(binary()),
gleam@option:option(integer())}.
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 235).
-spec photo_image_uri_decoder() -> gleam@dynamic@decode:decoder(binary()).
photo_image_uri_decoder() ->
gleam@dynamic@decode:one_of(
gleam@dynamic@decode:at(
[<<"image"/utf8>>, <<"uri"/utf8>>],
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
[gleam@dynamic@decode:at(
[<<"full_image"/utf8>>, <<"uri"/utf8>>],
{decoder, fun gleam@dynamic@decode:decode_string/1}
)]
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 241).
-spec photo_decoder() -> gleam@dynamic@decode:decoder(event_photo()).
photo_decoder() ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Url) ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:then(
begin
_pipe = photo_image_uri_decoder(),
scrapbook@internal@decoder:or_none(_pipe)
end,
fun(Image_uri) ->
gleam@dynamic@decode:success(
{event_photo, Url, Id, Image_uri}
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 249).
-spec video_image_uri_decoder() -> gleam@dynamic@decode:decoder(binary()).
video_image_uri_decoder() ->
gleam@dynamic@decode:at(
[<<"image"/utf8>>, <<"uri"/utf8>>],
{decoder, fun gleam@dynamic@decode:decode_string/1}
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 253).
-spec video_decoder() -> gleam@dynamic@decode:decoder(event_video()).
video_decoder() ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Url) ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:then(
begin
_pipe = video_image_uri_decoder(),
scrapbook@internal@decoder:or_none(_pipe)
end,
fun(Image_uri) ->
gleam@dynamic@decode:success(
{event_video, Url, Id, Image_uri}
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 261).
-spec parent_decoder() -> gleam@dynamic@decode:decoder(event_parent()).
parent_decoder() ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) -> gleam@dynamic@decode:success({event_parent, Id}) end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 267).
-spec sibling_decoder() -> gleam@dynamic@decode:decoder(event_sibling()).
sibling_decoder() ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:field(
<<"start_timestamp"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Start_timestamp) ->
gleam@dynamic@decode:field(
<<"end_timestamp"/utf8>>,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_int/1}
),
fun(End_timestamp) ->
gleam@dynamic@decode:field(
<<"parent_event"/utf8>>,
parent_decoder(),
fun(Parent) ->
gleam@dynamic@decode:success(
{event_sibling,
Id,
Start_timestamp,
End_timestamp,
Parent}
)
end
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 279).
-spec siblings_decoder() -> gleam@dynamic@decode:decoder(list(event_sibling())).
siblings_decoder() ->
gleam@dynamic@decode:list(sibling_decoder()).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 283).
-spec get_basic_data(binary()) -> {ok, event_basic_data()} |
{error, list(scrapbook@error:property_error())}.
get_basic_data(Html) ->
Decoder = (gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:field(
<<"name"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Name) ->
gleam@dynamic@decode:field(
<<"start_timestamp"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Start_timestamp) ->
gleam@dynamic@decode:then(
begin
_pipe = gleam@dynamic@decode:at(
[<<"cover_media_renderer"/utf8>>,
<<"cover_photo"/utf8>>,
<<"photo"/utf8>>],
photo_decoder()
),
scrapbook@internal@decoder:or_none(_pipe)
end,
fun(Photo) ->
gleam@dynamic@decode:field(
<<"day_time_sentence"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Formatted_date) ->
gleam@dynamic@decode:then(
begin
_pipe@1 = gleam@dynamic@decode:at(
[<<"cover_media_renderer"/utf8>>,
<<"cover_video"/utf8>>],
video_decoder()
),
scrapbook@internal@decoder:or_none(
_pipe@1
)
end,
fun(Video) ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Url) ->
gleam@dynamic@decode:field(
<<"is_online"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_bool/1},
fun(Is_online) ->
gleam@dynamic@decode:field(
<<"parent_if_exists_or_self"/utf8>>,
begin
_pipe@2 = parent_decoder(
),
scrapbook@internal@decoder:or_none(
_pipe@2
)
end,
fun(
Parent
) ->
gleam@dynamic@decode:field(
<<"comet_neighboring_siblings"/utf8>>,
siblings_decoder(
),
fun(
Siblings
) ->
gleam@dynamic@decode:success(
{event_basic_data,
Id,
Name,
Start_timestamp,
Formatted_date,
Photo,
Video,
Url,
Is_online,
Parent,
Siblings}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)),
scrapbook@internal@html:get_property(
Html,
<<"event"/utf8>>,
Decoder,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 330).
-spec get_description(binary()) -> {ok, binary()} |
{error, list(scrapbook@error:property_error())}.
get_description(Html) ->
Decoder = (gleam@dynamic@decode:field(
<<"text"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Text) -> gleam@dynamic@decode:success(Text) end
)),
scrapbook@internal@html:get_property(
Html,
<<"event_description"/utf8>>,
Decoder,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 339).
-spec online_type_decoder() -> gleam@dynamic@decode:decoder(online_type()).
online_type_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Type_) -> case Type_ of
<<"MESSENGER_ROOM"/utf8>> ->
gleam@dynamic@decode:success(messenger_room);
<<"THIRD_PARTY"/utf8>> ->
gleam@dynamic@decode:success(third_party);
<<"FB_LIVE"/utf8>> ->
gleam@dynamic@decode:success(facebook_live);
<<"OTHER"/utf8>> ->
gleam@dynamic@decode:success(other);
_ ->
gleam@dynamic@decode:failure(other, <<"OnlineType"/utf8>>)
end end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 351).
-spec get_place_online(binary()) -> {ok, event_place()} |
{error, list(scrapbook@error:property_error())}.
get_place_online(Html) ->
Decoder = (gleam@dynamic@decode:field(
<<"third_party_url"/utf8>>,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Url) ->
gleam@dynamic@decode:field(
<<"type"/utf8>>,
online_type_decoder(),
fun(Type_) ->
gleam@dynamic@decode:success({online, Url, Type_})
end
)
end
)),
scrapbook@internal@html:get_property(
Html,
<<"online_event_setup"/utf8>>,
Decoder,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 364).
-spec offline_location_decoder() -> gleam@dynamic@decode:decoder(offline_location()).
offline_location_decoder() ->
gleam@dynamic@decode:field(
<<"latitude"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_float/1},
fun(Latitude) ->
gleam@dynamic@decode:field(
<<"longitude"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_float/1},
fun(Longitude) ->
gleam@dynamic@decode:then(
begin
_pipe = gleam@dynamic@decode:at(
[<<"reverse_geocode"/utf8>>,
<<"country_alpha_two"/utf8>>],
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
scrapbook@internal@decoder:or_none(_pipe)
end,
fun(Country_code) ->
gleam@dynamic@decode:success(
{offline_location,
Latitude,
Longitude,
Country_code}
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 375).
-spec offline_type_decoder() -> gleam@dynamic@decode:decoder(offline_type()).
offline_type_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Type_) -> case Type_ of
<<"TEXT"/utf8>> ->
gleam@dynamic@decode:success(text);
<<"PLACE"/utf8>> ->
gleam@dynamic@decode:success(place);
<<"CITY"/utf8>> ->
gleam@dynamic@decode:success(city);
_ ->
gleam@dynamic@decode:failure(text, <<"OfflineType"/utf8>>)
end end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 386).
-spec offline_city_decoder() -> gleam@dynamic@decode:decoder(offline_city()).
offline_city_decoder() ->
gleam@dynamic@decode:field(
<<"contextual_name"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Name) ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:success({offline_city, Name, Id})
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 395).
-spec get_place_offline(binary()) -> {ok, event_place()} |
{error, list(scrapbook@error:property_error())}.
get_place_offline(Html) ->
Decoder = (gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:field(
<<"name"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Name) ->
gleam@dynamic@decode:then(
begin
_pipe = gleam@dynamic@decode:at(
[<<"best_description"/utf8>>, <<"text"/utf8>>],
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
scrapbook@internal@decoder:or_none(_pipe)
end,
fun(Description) ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
begin
_pipe@1 = {decoder,
fun gleam@dynamic@decode:decode_string/1},
scrapbook@internal@decoder:or_none(_pipe@1)
end,
fun(Url) ->
gleam@dynamic@decode:field(
<<"location"/utf8>>,
gleam@dynamic@decode:optional(
offline_location_decoder()
),
fun(Location) ->
gleam@dynamic@decode:field(
<<"place_type"/utf8>>,
offline_type_decoder(),
fun(Type_) ->
gleam@dynamic@decode:then(
begin
_pipe@2 = gleam@dynamic@decode:at(
[<<"address"/utf8>>,
<<"street"/utf8>>],
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
scrapbook@internal@decoder:or_none(
_pipe@2
)
end,
fun(Address) ->
gleam@dynamic@decode:field(
<<"city"/utf8>>,
begin
_pipe@3 = offline_city_decoder(
),
scrapbook@internal@decoder:or_none(
_pipe@3
)
end,
fun(City) ->
gleam@dynamic@decode:success(
{offline,
Id,
Name,
Description,
Url,
Location,
Type_,
Address,
City}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)),
scrapbook@internal@html:get_property(
Html,
<<"event_place"/utf8>>,
Decoder,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 431).
-spec host_type_decoder() -> gleam@dynamic@decode:decoder(host_type()).
host_type_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Type_) -> case Type_ of
<<"User"/utf8>> ->
gleam@dynamic@decode:success(user);
<<"Page"/utf8>> ->
gleam@dynamic@decode:success(page);
_ ->
gleam@dynamic@decode:failure(page, <<"OfflineType"/utf8>>)
end end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 441).
-spec host_photo_decoder() -> gleam@dynamic@decode:decoder(binary()).
host_photo_decoder() ->
gleam@dynamic@decode:field(
<<"uri"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Image_uri) -> gleam@dynamic@decode:success(Image_uri) end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 447).
-spec host_decoder() -> gleam@dynamic@decode:decoder(event_host()).
host_decoder() ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Id) ->
gleam@dynamic@decode:field(
<<"name"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Name) ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Url) ->
gleam@dynamic@decode:field(
<<"__typename"/utf8>>,
host_type_decoder(),
fun(Type_) ->
gleam@dynamic@decode:field(
<<"profile_picture"/utf8>>,
host_photo_decoder(),
fun(Image_uri) ->
gleam@dynamic@decode:success(
{event_host,
Id,
Name,
Url,
Type_,
Image_uri}
)
end
)
end
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 457).
-spec hosts_decoder() -> gleam@dynamic@decode:decoder(list(event_host())).
hosts_decoder() ->
gleam@dynamic@decode:list(host_decoder()).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 461).
-spec get_hosts(binary()) -> {ok, list(event_host())} |
{error, list(scrapbook@error:property_error())}.
get_hosts(Html) ->
Decoder = (gleam@dynamic@decode:then(
hosts_decoder(),
fun(Hosts) -> gleam@dynamic@decode:success(Hosts) end
)),
scrapbook@internal@html:get_property(
Html,
<<"event_hosts_that_can_view_guestlist"/utf8>>,
Decoder,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 473).
-spec get_time_details(binary(), integer()) -> {ok, event_time_details()} |
{error, list(scrapbook@error:property_error())}.
get_time_details(Html, Expected_start_timestamp) ->
Decoder = (gleam@dynamic@decode:field(
<<"start_timestamp"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Start_timestamp) ->
gleam@dynamic@decode:field(
<<"end_timestamp"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(End_timestamp) ->
gleam@dynamic@decode:field(
<<"tz_display_name"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Timezone) ->
gleam@dynamic@decode:success(
{event_time_details,
Start_timestamp,
End_timestamp,
Timezone}
)
end
)
end
)
end
)),
scrapbook@internal@html:get_property(
Html,
<<"data"/utf8>>,
Decoder,
fun(Event_time_details) ->
erlang:element(2, Event_time_details) =:= Expected_start_timestamp
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 490).
-spec get_ticket_url(binary()) -> {ok, binary()} |
{error, list(scrapbook@error:property_error())}.
get_ticket_url(Html) ->
Decoder = (gleam@dynamic@decode:then(
gleam@dynamic@decode:at(
[<<"event"/utf8>>, <<"event_buy_ticket_url"/utf8>>],
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Url) -> gleam@dynamic@decode:success(Url) end
)),
scrapbook@internal@html:get_property(
Html,
<<"ticket_card_content_renderer"/utf8>>,
Decoder,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 504).
-spec get_users_responded(binary()) -> {ok, integer()} |
{error, list(scrapbook@error:property_error())}.
get_users_responded(Html) ->
Decoder = (gleam@dynamic@decode:field(
<<"count"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Users_responded) ->
gleam@dynamic@decode:success(Users_responded)
end
)),
scrapbook@internal@html:get_property(
Html,
<<"event_connected_users_public_responded"/utf8>>,
Decoder,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 520).
-spec get_event(binary()) -> {ok, event_data()} |
{error, list(scrapbook@error:property_error())}.
get_event(Html) ->
gleam@result:'try'(
get_basic_data(Html),
fun(Basic_data) ->
gleam@result:'try'(
get_description(Html),
fun(Description) ->
gleam@result:'try'(case erlang:element(9, Basic_data) of
true ->
_pipe = get_place_online(Html),
gleam@result:map(
_pipe,
fun(Field@0) -> {some, Field@0} end
);
false ->
_pipe@1 = get_place_offline(Html),
scrapbook@internal@html:no_value_to_option(
_pipe@1
)
end, fun(Place) ->
gleam@result:'try'(
get_hosts(Html),
fun(Hosts) ->
gleam@result:'try'(
get_time_details(
Html,
erlang:element(4, Basic_data)
),
fun(Time_details) ->
gleam@result:'try'(
begin
_pipe@2 = get_ticket_url(
Html
),
scrapbook@internal@html:no_value_to_option(
_pipe@2
)
end,
fun(Ticket_url) ->
gleam@result:'try'(
begin
_pipe@3 = get_users_responded(
Html
),
scrapbook@internal@html:no_prefix_to_option(
_pipe@3
)
end,
fun(Users_responded) ->
{ok,
{event_data,
Basic_data,
Description,
Place,
Hosts,
Time_details,
Ticket_url,
Users_responded}}
end
)
end
)
end
)
end
)
end)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 549).
-spec construct_event_request_from_url(binary(), binary()) -> {ok,
gleam@http@request:request(binary())} |
{error, scrapbook@error:scrape_error()}.
construct_event_request_from_url(Url, User_agent) ->
gleam@result:'try'(
gleam@result:replace_error(
scrapbook@internal@event@url:format_url(Url),
url_error
),
fun(Url@1) ->
case scrapbook@internal@http:construct_request(Url@1, User_agent) of
{ok, Req} ->
{ok, Req};
{error, Err} ->
{error, {request_error, Err}}
end
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 564).
-spec construct_event_request_from_id(binary(), binary()) -> {ok,
gleam@http@request:request(binary())} |
{error, scrapbook@error:scrape_error()}.
construct_event_request_from_id(Id, User_agent) ->
gleam@result:'try'(
gleam@result:replace_error(
scrapbook@internal@event@url:id_to_url(Id),
url_error
),
fun(Url) ->
case scrapbook@internal@http:construct_request(Url, User_agent) of
{ok, Req} ->
{ok, Req};
{error, Err} ->
{error, {request_error, Err}}
end
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 577).
-spec scrape_event_response(gleam@http@response:response(binary())) -> {ok,
event_data()} |
{error, scrapbook@error:scrape_error()}.
scrape_event_response(Resp) ->
case get_event(erlang:element(4, Resp)) of
{ok, Event} ->
{ok, Event};
{error, Err} ->
{error, {property_error, Err}}
end.