Weather API Integrations
I am using Oracle PLSQL to get the current Temperature For my APEX application..
This is my code for Fetching the Data from API
/* Formatted on 2020/06/12 09:04 (Formatter Plus v4.8.8) */
DECLARE
req UTL_HTTP.req;
resp UTL_HTTP.resp;
VALUE LONG;
l_obj json_object_t;
request_context UTL_HTTP.request_context_key;
l_dept_arr json_array_t;
l_dept_obj json_object_t;
l_emp_arr json_array_t;
l_emp_obj json_object_t;
BEGIN
---UTL_HTTP.set_wallet ('file:E:\wallets', '********');
request_context :=
UTL_HTTP.create_request_context (wallet_path => 'E:\******',
wallet_password => '*******'
);
req :=
UTL_HTTP.begin_request
(utl_url.ESCAPE
('http://dataservice.accuweather.com/currentconditions/v1/*****?&apikey=***********&details=false'
),
request_context => request_context
);
UTL_HTTP.set_header (req, 'User-Agent', 'Mozilla/4.0');
UTL_HTTP.set_header (req, 'content-type', 'application/json');
resp := UTL_HTTP.get_response (req);
LOOP
UTL_HTTP.read_line (resp, VALUE, TRUE);
l_obj :=
json_object_t.parse
('{"LocalObservationDateTime":"2020-06-11T11:50:00+05:00","EpochTime":1591858200,"WeatherText":"Partly sunny","WeatherIcon":3,"HasPrecipitation":false,"PrecipitationType":null,"IsDayTime":true,"Temperature":{"Metric":{"Value":33.9,"Unit":"C","UnitType":17},"Imperial":{"Value":93.0,"Unit":"F","UnitType":18}},"MobileLink":"http://m.accuweather.com/en/pk/goth-natkhe-khan/260826/current-weather/260826?lang=en-us","Link":"http://www.accuweather.com/en/pk/goth-natkhe-khan/260826/current-weather/260826?lang=en-us"}'
);
INSERT INTO weatherconditions
VALUES (SYSDATE,
l_obj.json_array_t ('Temperature').get_array ('Metric').get_string
('Value'),
l_obj.get_string ('WeatherIcon'),
l_obj.get_string ('WeatherIcon'));
END LOOP;
COMMIT;
--DBMS_OUTPUT.put_line (l_obj.get_string ('WeatherIcon'));
UTL_HTTP.end_response (resp);
UTL_HTTP.end_request (req);
UTL_HTTP.destroy_request_context (request_context);
EXCEPTION
WHEN UTL_HTTP.end_of_body
THEN
UTL_HTTP.end_response (resp);
WHEN UTL_HTTP.too_many_requests
THEN
UTL_HTTP.end_response (resp);
END;
/
Comments
Post a Comment