summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-12-13 21:50:22 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-12-13 21:50:22 +0100
commit0f079921da9e70d4572d0677171478d91470e7d4 (patch)
treecd550a9a75b71915821db0f59eaa14dc18bf4c25 /scripts
parent3176e452dbe31e7d35019abe251643bd929653b4 (diff)
automatically update autocomplete station list
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/update-autocomplete42
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/update-autocomplete b/scripts/update-autocomplete
new file mode 100755
index 0000000..4dc64ae
--- /dev/null
+++ b/scripts/update-autocomplete
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use 5.020;
+
+use JSON;
+use File::Slurp qw(write_file);
+use Travel::Status::DE::IRIS::Stations;
+
+my @station_names
+ = map { $_->[1] } Travel::Status::DE::IRIS::Stations::get_stations();
+my $station_list = q{};
+
+for my $station (@station_names) {
+ $station_list .= sprintf( "\t\t\t\"%s\": null,\n", $station );
+}
+
+my $autocomplete = <<"EOF";
+/*
+ * Copyright (C) 2020 DB Station&Service AG, Europaplatz 1, 10557 Berlin
+ * Copyright (C) 2020 Daniel Friesel
+ *
+ * SPDX-License-Identifier: CC-BY-4.0
+ */
+document.addEventListener('DOMContentLoaded', function() {
+ var elems = document.querySelectorAll('.autocomplete');
+ M.Autocomplete.init(elems, {
+ minLength: 3,
+ limit: 50,
+ data: {
+$station_list
+ }
+ });
+});
+EOF
+
+write_file(
+ "public/static/js/autocomplete.js",
+ { binmode => ':encoding(utf-8)' },
+ $autocomplete
+);