forked from bsiever/canvas-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateDates.pl
More file actions
75 lines (65 loc) · 1.44 KB
/
Copy pathUpdateDates.pl
File metadata and controls
75 lines (65 loc) · 1.44 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
# Find and replace the dates in a Canvas JSON file
# JSON input is via standard input
#
# Parameters:
# $1 - File containing a 3 column tab-delimited spreadsheet
# column 1 = description of assignment/group (not used for anything)
# column 2 = previous due date, e.g. "2021-01-15 23:59:00"
# column 3 = new due date, e.g. "2021-09-07 23:59:00"
# first line in file is assumed to be a header
#
# Example usage: perl UpdateDates.pl dates.txt < schedule.json > new.json
use strict;
if (@ARGV < 1)
{
print "$0 <date file>\n";
exit;
}
open(IN, $ARGV[0]);
# Skip the header line
my $line;
$line = <IN>;
my @oldDate;
my @newDate;
while ($line = <IN>)
{
$line =~ s/[\n\r]//g;
my @cols = split(/\t/, $line);
if (@cols == 3)
{
my $desc;
my $old;
my $new;
($desc, $old, $new) = @cols;
push @oldDate, $old;
push @newDate, $new;
# print $desc . " ". $old . " " . $new . "\n";
}
}
close(IN);
while ($line = <STDIN>)
{
if ($line =~ /due_at/)
{
my $i = 0;
while ($i < @oldDate)
{
my $old = $oldDate[$i];
if (index($line, $old) != -1)
{
my $new = $newDate[$i];
$line =~ s/$old/$new/;
last;
}
else
{
$i++;
}
}
print $line;
}
else
{
print $line;
}
}