-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_check_script.pl
executable file
·71 lines (64 loc) · 2.1 KB
/
simple_check_script.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
#!/usr/bin/env perl
# this is a script which simply checks the LQFB Host and mails the updated initiatives.
# it uses a status file defined in config.pm to check the date for the last run
# and the minimum initiative id
#
# if run for the first time, nothing will done only the min id and the last time is set
# to the current timestamp
#
# add the parameter 'summary' if you want only a summary mail
use config;
use strict;
use MyMailer;
use encoding 'utf8';
use LWP::UserAgent;
use XML::EasyOBJ;
use CUpdateCollection;
use CInitiative;
use MyUtils::CArray;
my $lastRunTimestamp=undef;
my $minid = 0;
if (open(STATUSFILE, "<$config::SIMPLE_CHECK_FILE")) {
my @lines = <STATUSFILE>;
$lastRunTimestamp = $lines[0];
$minid = $lines[1];
close(STATUSFILE);
}
my $after_action = $ARGV[0];
if ($after_action ne '' && $after_action ne 'summary') {
die("Usage: simple_check_script.pl [summary]");
}
my $browser = LWP::UserAgent->new;
my $xml_file = $browser->get("$config::LQFB_ROOT/api/initiative.html?key=$config::LQFB_API_KEY&min_id=$minid");
my $xml_doc = new XML::EasyOBJ(-type => 'string', -param=>$xml_file->content);
my @all_initiatives = $xml_doc->getElement('initiative');
my $parsed_initiatives = new CArray;
$minid = 0;
my $min_fixed = 0;
my $maxTimestamp = 0;
my $updates = new CUpdateCollection();
foreach (@all_initiatives) {
my $initiative = new CInitiative($_);
$initiative->check_lr_updates($lastRunTimestamp, $updates, \$maxTimestamp) if $lastRunTimestamp;
unless ($min_fixed) {
if ($initiative->getIssueState() eq 'finished' || $initiative->getIssueState() eq 'cancelled') {
$minid = int($initiative->getId());
} else {
$min_fixed = 1;
}
}
$parsed_initiatives->addElement($initiative);
}
if ($lastRunTimestamp) {
if ($after_action eq 'summary') {
MyMailer::mail_all_updates($updates);
} else {
MyMailer::mail_single_updates($updates);
}
}
for (my $i=0;$i<$parsed_initiatives->getSize();$i++) {
$parsed_initiatives->getAt($i)->save();
}
open(STATUSFILE, ">$config::SIMPLE_CHECK_FILE") or die("Could not open Status File for writing!");
print STATUSFILE "$maxTimestamp\n$minid\n";
close(STATUSFILE);