-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcronjob.pl
executable file
·116 lines (102 loc) · 2.87 KB
/
cronjob.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
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl -w -I.
use strict;
use Data::Dumper;
use URI::Escape;
use JSON;
use RSSTootalizer::Feed;
use RSSTootalizer::Filter;
use RSSTootalizer::User;
use RSSTootalizer::Entry;
use RSSTootalizer::DB;
our $config = "";
open CONFIG, "rsstootalizer.conf.json" or die "Cannot open rsstootalizer.conf.json";
{
local $/ = undef;
$config = <CONFIG>;
}
close CONFIG;
$config = decode_json($config);
sub Error {{{
my $errormessage = "\nStack Trace:\n";
my $i=0;
while ((my @call_details = (caller($i++))) ){
$errormessage .= $call_details[1].":".$call_details[2]." in function ".$call_details[3]."\n";
}
print STDERR $errormessage;
exit(1);
}}}
# Force Unicode output
binmode STDERR, ":utf8";
binmode STDOUT, ":utf8";
my @feeds = RSSTootalizer::Feed->all();
FEED: foreach my $feed (@feeds){
next FEED unless $feed;
next FEED unless $feed->{data}->{enabled};
my $entries = $feed->fetch_entries();
next FEED unless $entries;
ENTRY: foreach my $entry ($entries->items){
my @seen_entries = $feed->entry_by("entry_link", $entry->link());
next ENTRY if ((scalar @seen_entries) > 0);
my %entry;
$entry{title} = $entry->title();
$entry{link} = $entry->link();
$entry{content} = $entry->content()->body;
$entry{author} = $entry->author();
$entry{issued} = $entry->issued();
$entry{modified} = $entry->modified();
$entry{id} = $entry->id();
$entry{tags} = join(", ", $entry->tags());
my $do_post = 0;
my @filters = $feed->filters();
foreach my $filter (@filters){
if ($filter->apply($entry)){
if ($filter->{data}->{type} eq "white"){
$do_post = 1;
} else {
$do_post = 0;
}
}
}
if ($do_post){
my $user = $feed->user();
my $status = $feed->{data}->{format};
$status =~ s/{ID}/$entry{id}/g;
if (defined($entry{title})){
$status =~ s/{Title}/$entry{title}/g;
} else {
$status =~ s/{Title}/No Title/g;
}
$status =~ s/{Link}/$entry{link}/g;
$status =~ s/{Content}/$entry{content}/g;
if (defined($entry{author})){
$status =~ s/{Author}/$entry{author}/g;
} else {
$status =~ s/{Author}//g;
}
if (defined($entry{issued})){
$status =~ s/{Issued}/$entry{issued}/g;
} else {
$status =~ s/{Issued}//g;
}
$status =~ s/{Modified}/$entry{modified}/g;
$status =~ s/{Tags}/$entry{tags}/g;
my %data;
if (length($status) > 500){
$status =~ s/^(.{497}).*$/$1.../g;
}
$data{status} = $status;
$ENV{status} = encode_json({%data});
open(DATA, "./post_status.bash '$user->{data}->{access_token}' '$user->{data}->{instance}' |");
my $reply = "";
{
local $/ = undef;
$reply = <DATA>;
}
}
my %ne;
$ne{feed_id} = $feed->{data}->{ID};
$ne{entry_link} = $entry{link};
RSSTootalizer::Entry->create(%ne);
}
}
RSSTootalizer::DB->doUPDATE("UPDATE `users` SET session_id = 'invalid' WHERE TIME_TO_SEC(NOW()) - TIME_TO_SEC(`valid_from`) > 60*60*4;"); # invalidate old sessions