-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeeds.pl
104 lines (91 loc) · 2.26 KB
/
feeds.pl
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/perl
use strict;
use warnings;
use vars qw($VERSION %IRSSI);
use Irssi;
use LWP::UserAgent qw(UserAgent);
use XML::RSSLite qw(RSSLite);
use JSON::XS qw(decode_json);
use HTML::Entities qw(decode_entities);
#use Config;
#use threads;
#my $thr = threads->create(\&sub1);
#sub sub1
#{
# Irssi::print("PROOT");
# sleep(10);
#}
$VERSION = '0.0.1';
%IRSSI = (
authors => 'frenchi',
license => 'exsinistropl',
name => 'sticazzi-arse',
);
my $shorten_browser = LWP::UserAgent->new;
$shorten_browser->agent('toolbar');
$shorten_browser->cookie_jar({});
sub shorten_url
{
my ($url) = @_;
my $res = $shorten_browser->post('http://goo.gl/api/url',
[ url => $url ]);
if ($res->is_success()) {
my $jsdata = decode_json($res->decoded_content);
return $jsdata->{short_url};
} else {
return undef;
}
}
my $feed_browser = LWP::UserAgent->new;
$feed_browser->agent('Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)');
$feed_browser->cookie_jar({});
sub get_feed
{
my ($url) = @_;
my ($browser, $res);
$res = $feed_browser->get($url);
if ($res->is_success() && $res->decoded_content) {
my %rsshash;
parseRSS(\%rsshash, \$res->decoded_content);
return %rsshash;
} else {
return undef;
}
}
my %lastread;
my @feeds = (
['ARS','http://feeds.arstechnica.com/arstechnica/index?format=xml'],
['PTS','http://feeds.feedburner.com/Phoronix'],
['LtU','http://lambda-the-ultimate.org/rss.xml'],
);
sub rss_announce
{
my $server = Irssi::servers();
foreach my $feed (@feeds) {
my ($prefix, $link) = @{$feed};
my %rss = get_feed($link);
if (!%rss || !defined($rss{'items'})) {
Irssi::print("cannot get feed for $prefix " . $link);
next;
}
my $last = $lastread{$prefix};
if (!defined $last) {
$last = @{$rss{'items'}}[0]->{title};
}
my $state = 0;
foreach my $item (reverse(@{$rss{'items'}})) {
if ($state == 0 && $last eq $item->{title}) {
$state = 1;
} elsif ($state == 1) {
my $short = shorten_url($item->{link});
my $title = decode_entities($item->{title});
$server->command("MSG ##fdt [$prefix] $title $short");
$last = $item->{title};
} else {
}
}
$lastread{$prefix} = $last;
}
}
rss_announce();
Irssi::timeout_add(5 * 60 * 1000, "rss_announce", "");