Last active
December 2, 2022 22:51
-
-
Save TysonJouglet/fefffe3ee4e874aeab2e42b2b1649f28 to your computer and use it in GitHub Desktop.
Helper package for getting advent of code input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace package aoc | |
as | |
-- A new Advent of Code session value is needed. Please do the following: | |
-- 1) Log into your account at https://adventofcode.com | |
-- 2) Open dev tools and view page cookies | |
-- 3) Look at the session cookie and copy the value | |
-- 4) Replace "<your session>" with the newly copied value | |
c_session constant varchar2(32767) := '<your session>'; | |
------------------------------------------------------------------------ | |
-- Returns the input for a given puzzle. | |
-- | |
-- | |
-- @param p_year 4 digit year e.g. 2022 | |
-- @param p_day a day of the month e.g. 2 | |
-- | |
-- @example | |
-- declare | |
-- l_input clob; | |
-- begin | |
-- | |
-- -- defaults to whatever is returned by sysdate | |
-- l_input := aoc.get_input; | |
-- | |
-- dbms_output.put_line(l_input); | |
-- end; | |
-- | |
-- @example | |
-- declare | |
-- l_input clob; | |
-- begin | |
-- l_input := aoc.get_input(p_year => 2022, p_day => 2); | |
-- dbms_output.put_line(l_input); | |
-- end; | |
------------------------------------------------------------------------ | |
function get_input( | |
p_year in pls_integer default extract(year from sysdate), | |
p_day in pls_integer default extract( day from sysdate) | |
) return clob; | |
end aoc; | |
create or replace package body aoc | |
as | |
function get_input( | |
p_year in pls_integer default extract(year from sysdate), | |
p_day in pls_integer default extract( day from sysdate) | |
) return clob | |
is | |
l_input clob; | |
begin | |
apex_web_service.g_request_headers.delete; | |
apex_web_service.g_request_headers(1).name := 'Cookie'; | |
apex_web_service.g_request_headers(1).value := 'session=' || c_session; | |
l_input := apex_web_service.make_rest_request( | |
p_url => 'https://adventofcode.com/'|| p_year ||'/day/'|| p_day ||'/input', | |
p_http_method => 'GET' | |
); | |
return l_input; | |
end get_input; | |
end aoc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment