-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscan.pl
More file actions
executable file
·78 lines (61 loc) · 1.9 KB
/
scan.pl
File metadata and controls
executable file
·78 lines (61 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl -s
#
## Hoersuppe.de scanner
use strict;
use warnings;
use utf8;
use Log::Log4perl qw(:easy);
use Config::Simple;
use File::Basename;
use DBI;
use LWP::Simple;
use JSON;
# make a new config reader object
my $currentpath = dirname(__FILE__);
my $cfg = new Config::Simple("$currentpath/sms.config");
my $programmpath = $cfg->param('directory');
# Log config
Log::Log4perl->init("$currentpath/logging.config");
# connect to database
my $dbh = DBI->connect(
"dbi:SQLite:dbname=$programmpath/data.db",
"",
"",
{ RaiseError => 1 }, #Exceptions instead of error
) or die $DBI::errstr;
# create table if not exists
$dbh->do(
"CREATE TABLE IF NOT EXISTS podcasts(
slug TEXT PRIMARY KEY,
title TEXT
)"
);
# make a JSON parser object
my $json = JSON->new->allow_nonref;
# get JSON via LWP and decode it to hash
INFO("Get slugs from hoersuppe");
my $rawdata = get("http://hoersuppe.de/api/?action=getPodcasts");
my $podcast_data = $json->decode($rawdata);
my $podcasts = $podcast_data->{"data"};
# insert Podcasts in DB
foreach my $podcast (@$podcasts) {
my $podtitle = $podcast->{"title"};
my $podslug = $podcast->{"slug"};
if ( defined $podslug ) {
my $sth = $dbh->prepare("SELECT slug FROM podcasts WHERE slug LIKE \'$podslug\'");
$sth->execute();
if ( defined $sth->fetchrow_array() ) {
DEBUG( "- Podcast $podslug is in database\n" );
}
else {
my $rawdata_info = get("http://hoersuppe.de/api/?action=getPodcastData&podcast=$podslug");
my $podcast_info = $json->decode($rawdata_info);
if ( $podcast_info->{"data"}->{"obsolete"} ne "1" ) {
$dbh->do("INSERT INTO podcasts VALUES('$podslug','$podtitle')");
INFO( "+ Podcast $podslug created\n" );
}
}
$sth->finish();
}
}
$dbh->disconnect();