diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-04-14 16:18:26 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-04-14 16:18:26 (GMT) |
commit | 94e4a04528f0c9204fb0affc7d91ed568b4b90a7 (patch) | |
tree | 3a208b38a7c237532e68c8e8710d0d92c252552b /lib | |
parent | 2a3c2cc85f0770abda73ba572917c0511cc370be (diff) |
inital commit for schedule generation
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/RHRD/utils.pm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/RHRD/utils.pm b/lib/RHRD/utils.pm index 2c7b7a9..d87ed70 100755 --- a/lib/RHRD/utils.pm +++ b/lib/RHRD/utils.pm @@ -26,6 +26,9 @@ use strict; use POSIX; use DateTime; use DateTime::TimeZone; +use LWP::Simple; +use URI::Fetch; +use JSON; sub get_rd_week { @@ -112,4 +115,33 @@ sub dropbox_param_len_ok return (1, 'OK', DB_PARAM_LEN_HINT); } +sub fetch_parse_json +{ + my ($url, $ua_str) = @_; + + my $uri = URI->new($url); + $ua_str = "Radio Helsinki Rivendell Utilities" unless $ua_str; + + my $ua = LWP::UserAgent->new; + $ua->agent($ua_str); + $ua->env_proxy; + my $res = URI::Fetch->fetch($uri, UserAgent => $ua) + or return (0, URI::Fetch->errstr); + if($res->status == URI::Fetch::URI_GONE()) { + return (0, "This feed has been permanently removed"); + } + + my $json = $res->content; + my $data; + eval { + $data = from_json($json); + 1; + } or do { + return (0, "error parsing import result"); + }; + + return (1, \$data); +} + + return 1; |