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, scrape_from_url/1, scrape_from_fbid/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, event_data_format_error/0, event_data_error/0, fetch_error/0, scrape_error/0]).
-opaque event_photo() :: {event_photo,
binary(),
binary(),
gleam@option:option(binary())}.
-opaque event_video() :: {event_video,
binary(),
binary(),
gleam@option:option(binary())}.
-opaque event_parent() :: {event_parent, binary()}.
-opaque event_sibling() :: {event_sibling,
binary(),
integer(),
gleam@option:option(integer()),
event_parent()}.
-opaque 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.
-opaque offline_location() :: {offline_location,
float(),
float(),
gleam@option:option(binary())}.
-type offline_type() :: text | place | city.
-opaque offline_city() :: {offline_city, binary(), binary()}.
-opaque 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.
-opaque event_host() :: {event_host,
binary(),
binary(),
binary(),
host_type(),
binary()}.
-opaque event_time_details() :: {event_time_details,
integer(),
integer(),
binary()}.
-opaque 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())}.
-type event_data_format_error() :: {decode_error, gleam@json:decode_error()} |
validate_error.
-type event_data_error() :: {find_key_value_error,
scrapbook@internal@html:find_key_value_error()} |
{data_format_errors, list(event_data_format_error())}.
-type fetch_error() :: {request_construction_error, binary()} |
{request_send_error, gleam@dynamic:dynamic_()} |
follow_redirection_error.
-type scrape_error() :: url_error |
{fetch_error, fetch_error()} |
{event_data_error, event_data_error()}.
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 157).
-spec do_get_property(
binary(),
binary(),
fun((gleam@dynamic:dynamic_()) -> {ok, IWE} |
{error, list(gleam@dynamic:decode_error())}),
fun((IWE) -> boolean()),
list(event_data_format_error())
) -> {ok, IWE} | {error, event_data_error()}.
do_get_property(Html, Key, Decoder, Validator, Errors) ->
gleam@result:'try'(case scrapbook@internal@html:find_key_value(Html, Key) of
{ok, Value} ->
{ok, Value};
{error, Err} ->
case Errors of
[] ->
{error, {find_key_value_error, Err}};
_ ->
{error, {data_format_errors, Errors}}
end
end, fun(_use0) ->
{find_key_value_result, Html@1, Json_string} = _use0,
case gleam@json:decode(Json_string, Decoder) of
{ok, Value@1} ->
case Validator(Value@1) of
true ->
{ok, Value@1};
false ->
do_get_property(
Html@1,
Key,
Decoder,
Validator,
[validate_error | Errors]
)
end;
{error, Err@1} ->
do_get_property(
Html@1,
Key,
Decoder,
Validator,
[{decode_error, Err@1} | Errors]
)
end
end).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 192).
-spec get_property(
binary(),
binary(),
fun((gleam@dynamic:dynamic_()) -> {ok, IWJ} |
{error, list(gleam@dynamic:decode_error())}),
fun((IWJ) -> boolean())
) -> {ok, IWJ} | {error, event_data_error()}.
get_property(Html, Key, Decoder, Validator) ->
do_get_property(Html, Key, Decoder, Validator, []).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 201).
-spec or_none(decode@zero:decoder(IWN)) -> decode@zero:decoder(gleam@option:option(IWN)).
or_none(Decoder) ->
decode@zero:one_of(
decode@zero:map(Decoder, fun(Field@0) -> {some, Field@0} end),
[decode@zero:success(none)]
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 205).
-spec photo_image_uri_decoder() -> decode@zero:decoder(binary()).
photo_image_uri_decoder() ->
decode@zero:one_of(
decode@zero:at(
[<<"image"/utf8>>, <<"uri"/utf8>>],
{decoder, fun decode@zero:decode_string/1}
),
[decode@zero:at(
[<<"full_image"/utf8>>, <<"uri"/utf8>>],
{decoder, fun decode@zero:decode_string/1}
)]
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 211).
-spec photo_decoder() -> decode@zero:decoder(event_photo()).
photo_decoder() ->
decode@zero:field(
<<"url"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Url) ->
decode@zero:field(
<<"id"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Id) ->
decode@zero:then(
begin
_pipe = photo_image_uri_decoder(),
or_none(_pipe)
end,
fun(Image_uri) ->
decode@zero:success(
{event_photo, Url, Id, Image_uri}
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 219).
-spec video_image_uri_decoder() -> decode@zero:decoder(binary()).
video_image_uri_decoder() ->
decode@zero:at(
[<<"image"/utf8>>, <<"uri"/utf8>>],
{decoder, fun decode@zero:decode_string/1}
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 223).
-spec video_decoder() -> decode@zero:decoder(event_video()).
video_decoder() ->
decode@zero:field(
<<"url"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Url) ->
decode@zero:field(
<<"id"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Id) ->
decode@zero:then(
begin
_pipe = video_image_uri_decoder(),
or_none(_pipe)
end,
fun(Image_uri) ->
decode@zero:success(
{event_video, Url, Id, Image_uri}
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 231).
-spec parent_decoder() -> decode@zero:decoder(event_parent()).
parent_decoder() ->
decode@zero:field(
<<"id"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Id) -> decode@zero:success({event_parent, Id}) end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 237).
-spec sibling_decoder() -> decode@zero:decoder(event_sibling()).
sibling_decoder() ->
decode@zero:field(
<<"id"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Id) ->
decode@zero:field(
<<"start_timestamp"/utf8>>,
{decoder, fun decode@zero:decode_int/1},
fun(Start_timestamp) ->
decode@zero:field(
<<"end_timestamp"/utf8>>,
decode@zero:optional(
{decoder, fun decode@zero:decode_int/1}
),
fun(End_timestamp) ->
decode@zero:field(
<<"parent_event"/utf8>>,
parent_decoder(),
fun(Parent) ->
decode@zero:success(
{event_sibling,
Id,
Start_timestamp,
End_timestamp,
Parent}
)
end
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 246).
-spec siblings_decoder() -> decode@zero:decoder(list(event_sibling())).
siblings_decoder() ->
decode@zero:list(sibling_decoder()).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 250).
-spec get_basic_data(binary()) -> {ok, event_basic_data()} |
{error, event_data_error()}.
get_basic_data(Html) ->
Decoder = (decode@zero:field(
<<"id"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Id) ->
decode@zero:field(
<<"name"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Name) ->
decode@zero:field(
<<"start_timestamp"/utf8>>,
{decoder, fun decode@zero:decode_int/1},
fun(Start_timestamp) ->
decode@zero:then(
begin
_pipe = decode@zero:at(
[<<"cover_media_renderer"/utf8>>,
<<"cover_photo"/utf8>>,
<<"photo"/utf8>>],
photo_decoder()
),
or_none(_pipe)
end,
fun(Photo) ->
decode@zero:field(
<<"day_time_sentence"/utf8>>,
{decoder,
fun decode@zero:decode_string/1},
fun(Formatted_date) ->
decode@zero:then(
begin
_pipe@1 = decode@zero:at(
[<<"cover_media_renderer"/utf8>>,
<<"cover_video"/utf8>>],
video_decoder()
),
or_none(_pipe@1)
end,
fun(Video) ->
decode@zero:field(
<<"url"/utf8>>,
{decoder,
fun decode@zero:decode_string/1},
fun(Url) ->
decode@zero:field(
<<"is_online"/utf8>>,
{decoder,
fun decode@zero:decode_bool/1},
fun(Is_online) ->
decode@zero:field(
<<"parent_if_exists_or_self"/utf8>>,
begin
_pipe@2 = parent_decoder(
),
or_none(
_pipe@2
)
end,
fun(
Parent
) ->
decode@zero:field(
<<"comet_neighboring_siblings"/utf8>>,
siblings_decoder(
),
fun(
Siblings
) ->
decode@zero: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
)),
get_property(
Html,
<<"event"/utf8>>,
fun(_capture) -> decode@zero:run(_capture, Decoder) end,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 289).
-spec get_description(binary()) -> {ok, binary()} | {error, event_data_error()}.
get_description(Html) ->
Decoder = (decode@zero:field(
<<"text"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Text) -> decode@zero:success(Text) end
)),
get_property(
Html,
<<"event_description"/utf8>>,
fun(_capture) -> decode@zero:run(_capture, Decoder) end,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 298).
-spec online_type_decoder() -> decode@zero:decoder(online_type()).
online_type_decoder() ->
decode@zero:then(
{decoder, fun decode@zero:decode_string/1},
fun(Type_) -> case Type_ of
<<"MESSENGER_ROOM"/utf8>> ->
decode@zero:success(messenger_room);
<<"THIRD_PARTY"/utf8>> ->
decode@zero:success(third_party);
<<"FB_LIVE"/utf8>> ->
decode@zero:success(facebook_live);
<<"OTHER"/utf8>> ->
decode@zero:success(other);
_ ->
decode@zero:failure(other, <<"OnlineType"/utf8>>)
end end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 310).
-spec get_place_online(binary()) -> {ok, event_place()} |
{error, event_data_error()}.
get_place_online(Html) ->
Decoder = (decode@zero:field(
<<"third_party_url"/utf8>>,
decode@zero:optional({decoder, fun decode@zero:decode_string/1}),
fun(Url) ->
decode@zero:field(
<<"type"/utf8>>,
online_type_decoder(),
fun(Type_) -> decode@zero:success({online, Url, Type_}) end
)
end
)),
get_property(
Html,
<<"online_event_setup"/utf8>>,
fun(_capture) -> decode@zero:run(_capture, Decoder) end,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 321).
-spec offline_location_decoder() -> decode@zero:decoder(offline_location()).
offline_location_decoder() ->
decode@zero:field(
<<"latitude"/utf8>>,
{decoder, fun decode@zero:decode_float/1},
fun(Latitude) ->
decode@zero:field(
<<"longitude"/utf8>>,
{decoder, fun decode@zero:decode_float/1},
fun(Longitude) ->
decode@zero:then(
begin
_pipe = decode@zero:at(
[<<"reverse_geocode"/utf8>>,
<<"country_alpha_two"/utf8>>],
{decoder, fun decode@zero:decode_string/1}
),
or_none(_pipe)
end,
fun(Country_code) ->
decode@zero:success(
{offline_location,
Latitude,
Longitude,
Country_code}
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 332).
-spec offline_type_decoder() -> decode@zero:decoder(offline_type()).
offline_type_decoder() ->
decode@zero:then(
{decoder, fun decode@zero:decode_string/1},
fun(Type_) -> case Type_ of
<<"TEXT"/utf8>> ->
decode@zero:success(text);
<<"PLACE"/utf8>> ->
decode@zero:success(place);
<<"CITY"/utf8>> ->
decode@zero:success(city);
_ ->
decode@zero:failure(text, <<"OfflineType"/utf8>>)
end end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 343).
-spec offline_city_decoder() -> decode@zero:decoder(offline_city()).
offline_city_decoder() ->
decode@zero:field(
<<"contextual_name"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Name) ->
decode@zero:field(
<<"id"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Id) -> decode@zero:success({offline_city, Name, Id}) end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 352).
-spec get_place_offline(binary()) -> {ok, event_place()} |
{error, event_data_error()}.
get_place_offline(Html) ->
Decoder = (decode@zero:field(
<<"id"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Id) ->
decode@zero:field(
<<"name"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Name) ->
decode@zero:then(
begin
_pipe = decode@zero:at(
[<<"best_description"/utf8>>, <<"text"/utf8>>],
{decoder, fun decode@zero:decode_string/1}
),
or_none(_pipe)
end,
fun(Description) ->
decode@zero:field(
<<"url"/utf8>>,
begin
_pipe@1 = {decoder,
fun decode@zero:decode_string/1},
or_none(_pipe@1)
end,
fun(Url) ->
decode@zero:field(
<<"location"/utf8>>,
decode@zero:optional(
offline_location_decoder()
),
fun(Location) ->
decode@zero:field(
<<"place_type"/utf8>>,
offline_type_decoder(),
fun(Type_) ->
decode@zero:then(
begin
_pipe@2 = decode@zero:at(
[<<"address"/utf8>>,
<<"street"/utf8>>],
{decoder,
fun decode@zero:decode_string/1}
),
or_none(_pipe@2)
end,
fun(Address) ->
decode@zero:field(
<<"city"/utf8>>,
begin
_pipe@3 = offline_city_decoder(
),
or_none(
_pipe@3
)
end,
fun(City) ->
decode@zero:success(
{offline,
Id,
Name,
Description,
Url,
Location,
Type_,
Address,
City}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)),
get_property(
Html,
<<"event_place"/utf8>>,
fun(_capture) -> decode@zero:run(_capture, Decoder) end,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 386).
-spec host_type_decoder() -> decode@zero:decoder(host_type()).
host_type_decoder() ->
decode@zero:then(
{decoder, fun decode@zero:decode_string/1},
fun(Type_) -> case Type_ of
<<"User"/utf8>> ->
decode@zero:success(user);
<<"Page"/utf8>> ->
decode@zero:success(page);
_ ->
decode@zero:failure(page, <<"OfflineType"/utf8>>)
end end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 396).
-spec host_photo_decoder() -> decode@zero:decoder(binary()).
host_photo_decoder() ->
decode@zero:field(
<<"uri"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Image_uri) -> decode@zero:success(Image_uri) end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 402).
-spec host_decoder() -> decode@zero:decoder(event_host()).
host_decoder() ->
decode@zero:field(
<<"id"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Id) ->
decode@zero:field(
<<"name"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Name) ->
decode@zero:field(
<<"url"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Url) ->
decode@zero:field(
<<"__typename"/utf8>>,
host_type_decoder(),
fun(Type_) ->
decode@zero:field(
<<"profile_picture"/utf8>>,
host_photo_decoder(),
fun(Image_uri) ->
decode@zero:success(
{event_host,
Id,
Name,
Url,
Type_,
Image_uri}
)
end
)
end
)
end
)
end
)
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 412).
-spec hosts_decoder() -> decode@zero:decoder(list(event_host())).
hosts_decoder() ->
decode@zero:list(host_decoder()).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 416).
-spec get_hosts(binary()) -> {ok, list(event_host())} |
{error, event_data_error()}.
get_hosts(Html) ->
Decoder = (decode@zero:then(
hosts_decoder(),
fun(Hosts) -> decode@zero:success(Hosts) end
)),
get_property(
Html,
<<"event_hosts_that_can_view_guestlist"/utf8>>,
fun(_capture) -> decode@zero:run(_capture, Decoder) end,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 431).
-spec get_time_details(binary(), integer()) -> {ok, event_time_details()} |
{error, event_data_error()}.
get_time_details(Html, Expected_start_timestamp) ->
Decoder = (decode@zero:field(
<<"start_timestamp"/utf8>>,
{decoder, fun decode@zero:decode_int/1},
fun(Start_timestamp) ->
decode@zero:field(
<<"end_timestamp"/utf8>>,
{decoder, fun decode@zero:decode_int/1},
fun(End_timestamp) ->
decode@zero:field(
<<"tz_display_name"/utf8>>,
{decoder, fun decode@zero:decode_string/1},
fun(Timezone) ->
decode@zero:success(
{event_time_details,
Start_timestamp,
End_timestamp,
Timezone}
)
end
)
end
)
end
)),
get_property(
Html,
<<"data"/utf8>>,
fun(_capture) -> decode@zero:run(_capture, Decoder) end,
fun(Event_time_details) ->
erlang:element(2, Event_time_details) =:= Expected_start_timestamp
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 448).
-spec get_ticket_url(binary()) -> {ok, binary()} | {error, event_data_error()}.
get_ticket_url(Html) ->
Decoder = (decode@zero:then(
decode@zero:at(
[<<"event"/utf8>>, <<"event_buy_ticket_url"/utf8>>],
{decoder, fun decode@zero:decode_string/1}
),
fun(Url) -> decode@zero:success(Url) end
)),
get_property(
Html,
<<"ticket_card_content_renderer"/utf8>>,
fun(_capture) -> decode@zero:run(_capture, Decoder) end,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 462).
-spec get_users_responded(binary()) -> {ok, integer()} |
{error, event_data_error()}.
get_users_responded(Html) ->
Decoder = (decode@zero:field(
<<"count"/utf8>>,
{decoder, fun decode@zero:decode_int/1},
fun(Users_responded) -> decode@zero:success(Users_responded) end
)),
get_property(
Html,
<<"event_connected_users_public_responded"/utf8>>,
fun(_capture) -> decode@zero:run(_capture, Decoder) end,
fun(_) -> true end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 479).
-spec no_value_to_option({ok, IXZ} | {error, event_data_error()}) -> {ok,
gleam@option:option(IXZ)} |
{error, event_data_error()}.
no_value_to_option(Result) ->
case Result of
{ok, Value} ->
{ok, {some, Value}};
{error, {find_key_value_error, {find_value_error, no_value}}} ->
{ok, none};
{error, Err} ->
{error, Err}
end.
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 491).
-spec no_prefix_to_option({ok, IYF} | {error, event_data_error()}) -> {ok,
gleam@option:option(IYF)} |
{error, event_data_error()}.
no_prefix_to_option(Result) ->
case Result of
{ok, Value} ->
{ok, {some, Value}};
{error, {find_key_value_error, {no_prefix, _}}} ->
{ok, none};
{error, Err} ->
{error, Err}
end.
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 502).
-spec get_event(binary()) -> {ok, event_data()} | {error, event_data_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),
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
),
no_value_to_option(_pipe@2)
end,
fun(Ticket_url) ->
gleam@result:'try'(
begin
_pipe@3 = get_users_responded(
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", 532).
-spec fetch(binary()) -> {ok, binary()} | {error, fetch_error()}.
fetch(Url) ->
gleam@result:'try'(
gleam@result:replace_error(
gleam@http@request:to(Url),
{request_construction_error, Url}
),
fun(Req) ->
Req@1 = begin
_pipe = Req,
_pipe@1 = gleam@http@request:set_header(
_pipe,
<<"accept"/utf8>>,
<<"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"/utf8>>
),
_pipe@2 = gleam@http@request:set_header(
_pipe@1,
<<"accept-language"/utf8>>,
<<"en-US,en;q=0.6"/utf8>>
),
_pipe@3 = gleam@http@request:set_header(
_pipe@2,
<<"cache-control"/utf8>>,
<<"max-age=0"/utf8>>
),
_pipe@4 = gleam@http@request:set_header(
_pipe@3,
<<"sec-fetch-dest"/utf8>>,
<<"document"/utf8>>
),
_pipe@5 = gleam@http@request:set_header(
_pipe@4,
<<"sec-fetch-mode"/utf8>>,
<<"navigate"/utf8>>
),
_pipe@6 = gleam@http@request:set_header(
_pipe@5,
<<"sec-fetch-site"/utf8>>,
<<"same-origin"/utf8>>
),
_pipe@7 = gleam@http@request:set_header(
_pipe@6,
<<"sec-fetch-user"/utf8>>,
<<"?1"/utf8>>
),
_pipe@8 = gleam@http@request:set_header(
_pipe@7,
<<"sec-gpc"/utf8>>,
<<"1"/utf8>>
),
_pipe@9 = gleam@http@request:set_header(
_pipe@8,
<<"upgrade-insecure-requests"/utf8>>,
<<"1"/utf8>>
),
gleam@http@request:set_header(
_pipe@9,
<<"user-agent"/utf8>>,
<<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"/utf8>>
)
end,
case begin
_pipe@10 = Req@1,
gleam@httpc:send(_pipe@10)
end of
{ok, Resp} ->
case (erlang:element(2, Resp) >= 300) andalso (erlang:element(
2,
Resp
)
< 400) of
true ->
Headers = maps:from_list(erlang:element(3, Resp)),
gleam@result:'try'(
gleam@result:replace_error(
begin
_pipe@11 = Headers,
gleam@dict:get(
_pipe@11,
<<"location"/utf8>>
)
end,
follow_redirection_error
),
fun(Location) -> fetch(Location) end
);
false ->
{ok, erlang:element(4, Resp)}
end;
{error, Err} ->
{error, {request_send_error, Err}}
end
end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 576).
-spec scrape_event(binary()) -> {ok, event_data()} | {error, scrape_error()}.
scrape_event(Url) ->
case fetch(Url) of
{ok, Html} ->
case get_event(Html) of
{ok, Event} ->
{ok, Event};
{error, Err} ->
{error, {event_data_error, Err}}
end;
{error, Err@1} ->
{error, {fetch_error, Err@1}}
end.
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 588).
-spec scrape_from_url(binary()) -> {ok, event_data()} | {error, scrape_error()}.
scrape_from_url(Url) ->
gleam@result:'try'(
gleam@result:replace_error(
scrapbook@internal@event@url:format_url(Url),
url_error
),
fun(Url@1) -> scrape_event(Url@1) end
).
-file("/home/norbert/projects/scrapbook/src/scrapbook/event.gleam", 594).
-spec scrape_from_fbid(binary()) -> {ok, event_data()} | {error, scrape_error()}.
scrape_from_fbid(Fbid) ->
gleam@result:'try'(
gleam@result:replace_error(
scrapbook@internal@event@url:fbid_to_url(Fbid),
url_error
),
fun(Url) -> scrape_event(Url) end
).