summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/EFA/Services.pm.PL
blob: be3bffb4eb7dd5cc73ee7d3418f8028662586344 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env perl

use strict;
use warnings;
use 5.014;
use utf8;
use Data::Dumper;
use Encode      qw(encode);
use File::Slurp qw(read_file write_file);
use JSON;

my $json = JSON->new->utf8;

sub load_instance {
	my ( $path, %opt ) = @_;

	my $data = $json->decode(
		scalar read_file("ext/transport-apis/data/${path}-efa.json") );
	my %ret = (
		name      => $opt{name} // $data->{name} =~ s{ *[(][^)]+[)]}{}r,
		homepage  => $data->{attribution}{homepage},
		url       => $opt{url} // $data->{options}{endpoint} =~ s{ / $ }{}rx,
		time_zone => $data->{timezone},
		languages => $data->{supportedLanguages},
		coverage  => {
			area    => $data->{coverage}{realtimeCoverage}{area},
			regions => $data->{coverage}{realtimeCoverage}{region} // []
		},
	);

	return %ret;
}

my %efa_instance = (
	BSVG => {
		url  => 'https://bsvg.efa.de/bsvagstd',
		name => 'Braunschweiger Verkehrs-GmbH',
	},
	DING => {
		url  => 'https://www.ding.eu/ding3',
		name => 'Donau-Iller Nahverkehrsverbund',
	},
	KVV    => { load_instance('de/kvv') },
	LinzAG => {
		url      => 'https://www.linzag.at/static',
		name     => 'Linz AG',
		encoding => 'iso-8859-15',
	},
	MVV => {
		url  => 'https://efa.mvv-muenchen.de/mobile',
		name => 'Münchner Verkehrs- und Tarifverbund',
	},
	NVBW => {
		url  => 'https://www.efa-bw.de/nvbw',
		name => 'Nahverkehrsgesellschaft Baden-Württemberg',
	},
	VAG => {
		url  => 'https://efa.vagfr.de/vagfr3',
		name => 'Freiburger Verkehrs AG',
	},
	VGN => {
		url  => 'https://efa.vgn.de/vgnExt_oeffi',
		name => 'Verkehrsverbund Grossraum Nuernberg',
	},

	# HTTPS: certificate verification fails
	VMV => {
		url  => 'http://efa.vmv-mbh.de/vmv',
		name => 'Verkehrsgesellschaft Mecklenburg-Vorpommern',
	},
	VRN => {
		url  => 'https://www.vrn.de/mngvrn/',
		name => 'Verkehrsverbund Rhein-Neckar',
	},
	VRR => {
		url  => 'https://efa.vrr.de/vrr',
		name => 'Verkehrsverbund Rhein-Ruhr',
	},
	VRR2 => {
		url  => 'https://app.vrr.de/standard',
		name => 'Verkehrsverbund Rhein-Ruhr (alternative)',
	},
	VRR3 => {
		url  => 'https://efa.vrr.de/rbgstd3',
		name => 'Verkehrsverbund Rhein-Ruhr (alternative alternative)',
	},
	VVO => {
		url  => 'https://efa.vvo-online.de/VMSSL3',
		name => 'Verkehrsverbund Oberelbe',
	},
	VVS => {
		url  => 'https://www2.vvs.de/vvs',
		name => 'Verkehrsverbund Stuttgart',
	},

);

my $buf = <<'__EOF__';
package Travel::Status::DE::EFA::Services;

# vim:readonly
# This package has been automatically generated
# by lib/Travel/Status/DE/EFA/Services.pm.PL.
# Do not edit, changes will be lost.

use strict;
use warnings;
use 5.014;
use utf8;

our $VERSION = '3.00';

# Most of these have been adapted from
# <https://github.com/public-transport/transport-apis> and
# <https://github.com/public-transport/hafas-client/tree/main/p>.
# Many thanks to Jannis R / @derhuerst and all contributors for maintaining
# these resources.

__EOF__

my $perlobj = Data::Dumper->new( [ \%efa_instance ], ['efa_instance'] );

$buf .= 'my ' . $perlobj->Sortkeys(1)->Indent(0)->Dump;

$buf .= <<'__EOF__';

sub get_service_ids {
	return sort keys %{$efa_instance};
}

sub get_service {
	my ($service) = @_;
	return $efa_instance->{$service};
}

sub get_service_ref {
	return $efa_instance;
}

sub get_service_map {
	return %{$efa_instance};
}

1;
__EOF__

write_file( $ARGV[0], { binmode => ':utf8' }, $buf );