-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl2json.pl
More file actions
executable file
·97 lines (93 loc) · 2.24 KB
/
l2json.pl
File metadata and controls
executable file
·97 lines (93 loc) · 2.24 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env perl
use warnings;
my %day_key = ('mandag' => 'mon'
,'tisdag' => 'tue'
,'onsdag' => 'wed'
,'torsdag' => 'thu'
,'fredag' => 'fri'
);
my $first_site = 1;
print "{\n";
while (<>)
{
chomp;
if (/Meny vecka (\d+) \(([\d-]+) — ([\d-]+)/)
{
my $week_num = $1;
my $start_date = $2;
my $end_date = $3;
$end_date = substr($start_date, 0, 5) . $end_date;
print " \"week\" : \"$week_num\",\n";
print " \"start\" : \"$start_date\",\n";
print " \"end\" : \"$end_date\"";
}
elsif (/<h2><a id="(\w+)"/) # new day
{
$first_site = 1;
my $day = $day_key{$1};
print ",\n";
print " \"$day\" : [\n";
}
elsif (/<\/table>/)
{
print "\n ]";
}
elsif (/<tr class="\w+"><th>(.*?)<\/th>.*?<li>(.*)<\/li><\/ul>/)
{
my $site = $1;
my $lunch = $2;
$site =~ s/ / /g;
if (not $first_site)
{
print ",\n";
}
else
{
$first_site = 0;
}
$site =~ /<a href="(.*?)">(.*?)<\/a>/;
print " {\n";
print " \"name\" : \"$2\",\n";
print " \"link\" : \"$1\",\n";
my @lunch_list = split(/<\/li><li>/, $lunch);
foreach (@lunch_list) # using default $_ works since this is last in while loop
{
s/\t/ /g; # change tabs to spaces
s/[\s]{2,}/ /g; # remove multi spaces
s/&/&/g;
s/´/´/g;
s/ö/ö/g;
s/ö/ö/g;
s/Ö/Ö/g;
s/Ö/Ö/g;
s/ä/ä/g;
s/ä/ä/g;
s/Ä/Ä/g;
s/Ä/Ä/g;
s/å/å/g;
s/å/å/g;
s/Å/Å/g;
s/Å/Å/g;
s/à/a/g;
s/à/a/g;
s/\xef\xbf\xbd/a/g;
s/è/è/g;
s/é/é/g;
s/é/é/g;
# quotes in all forms should be converted to single quote to not mess up json
s/"/'/g;
s/"/'/g;
s/“/'/g;
s/”/'/g;
s/‘/'/g;
s/’/'/g;
s/<em>/_/g;
s/<\/em>/_/g;
}
@lunch_list = grep { $_ !~ /(no workie|^—|Ingen meny)/ } @lunch_list;
print " \"menu\" : [ " . join(', ', map { '"' . $_ . '"'} @lunch_list) . " ]\n";
print " }";
}
}
print "\n";
print "}\n";