From e09f487e0c7aabe265cd97fd593097dedc5bdd25 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 28 Mar 2013 08:36:59 +0100 Subject: [PATCH] added rm_follow_links.sh and linz_ag.pl --- linz_ag.pl | 101 +++++++++++++++++++++++++++++++++++++++++++++ rm_follow_links.sh | 14 +++++++ 2 files changed, 115 insertions(+) create mode 100755 linz_ag.pl create mode 100644 rm_follow_links.sh diff --git a/linz_ag.pl b/linz_ag.pl new file mode 100755 index 0000000..0bad64f --- /dev/null +++ b/linz_ag.pl @@ -0,0 +1,101 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Data::Dumper; + +use LWP::Simple; +use XML::Simple; + +use constant LINZ_AG_URL => "http://www.linzag.at/static/XML_DM_REQUEST"; + +sub get_trips { + my ( $name_dm, $no_of_trips ) = @_; + my ( $result, $result_trips, $requestID, $sessionID, $direction, + $max_length_dest, $max_length_countdown, $max_length_line ); + $requestID = $sessionID = $max_length_dest = $max_length_countdown = $max_length_line = 0; + + # cheat sheet: + # http://www.linzag.at/static/XML_DM_REQUEST?sessionID=0&locationServerActive=1&type_dm=any&name_dm=60502280 + # http://www.linzag.at/static/XML_DM_REQUEST?sessionID=2880156875&requestID=1&dmLineSelectionAll=1 + + # open session and get ID + my $get_s_id_url = LINZ_AG_URL + . "?sessionID=${sessionID}" + . "&locationServerActive=1" # TODO: What does this do? + . "&type_dm=any" + . "&name_dm=${name_dm}" + . "&limit=${no_of_trips}"; + + my $xml = XMLin(get( $get_s_id_url )); + # retrieve XML for trips + $sessionID = $xml->{sessionID}; + my $get_time_url = LINZ_AG_URL + . "?sessionID=${sessionID}" + . "&requestID=${requestID}" + . "&dmLineSelectionAll=1"; + $xml = XMLin(get( $get_time_url )); + + # map direction shortcode_letters to names (e.g $direction->{27}->{R} = "Linz Auwiesen" ); + foreach my $line (@{$xml->{itdDepartureMonitorRequest}->{itdServingLines}->{itdServingLine}} ) { + $direction->{$line->{number}}->{$line->{motDivaParams}->{direction}} = $line->{direction}; + } + + # parse trips + foreach my $trip (@{$xml->{itdDepartureMonitorRequest}->{itdDepartureList}->{itdDeparture}}) { + my $line = $trip->{itdServingLine}->{symbol}; + my $dest_code = $trip->{itdServingLine}->{motDivaParams}->{direction}; + my $destination = $direction->{$line}->{$dest_code}; + my $countdown = $trip->{countdown}; + my $hour = $trip->{itdDateTime}->{itdTime}->{hour}; + my $minute = $trip->{itdDateTime}->{itdTime}->{minute}; + $max_length_dest = length($destination) if ( length($destination) > $max_length_dest); + $max_length_countdown = length($countdown) if ( length($countdown) > $max_length_countdown); + $max_length_line = length($line) if ( length($line) > $max_length_line); + + push (@$result_trips, { + line => $line, + destination => $destination, + countdown => $trip->{countdown}, + hour => $hour, + minute => $minute, + }); + } + + $result->{trips} = $result_trips; + $result->{max_length_dest} = $max_length_dest; + $result->{max_length_countdown} = $max_length_countdown; + $result->{max_length_line} = $max_length_line; + return $result; +} + +sub print_trips { + # quick hack + + my $t = shift; + my $ml_dest = $t->{max_length_dest}; + my $ml_cd = $t->{max_length_countdown}; + my $ml_ln = $t->{max_length_line}; + $ml_ln = length("line") if ( length("line") > $ml_ln ); + $ml_cd = length("countdown") if ( length("countdown") > $ml_cd ); + $ml_dest = length("destination") if ( length("destination") > $ml_dest ); + my $total_line_length = $ml_ln + $ml_cd + $ml_dest + 21; + print ( " ". "=" x $total_line_length . "\n" ); + # line destination countdown time + printf(" | %-${ml_ln}s %-${ml_dest}s %-${ml_cd}s %s |\n", "line", "destination", "countdown", "time" ); + print ( " ". "=" x $total_line_length . "\n" ); + $ml_cd -= length("(min) "); + $ml_cd += length(" "); + for my $entry ( @{$t->{trips}} ) { + printf(" | %-${ml_ln}s | %-${ml_dest}s | %-${ml_cd}d(min) | %02d:%02d h |\n", + $entry->{'line'}, $entry->{'destination'}, + $entry->{'countdown'}, + $entry->{'hour'}, $entry->{'minute'}); + } + print ( " ". "-" x $total_line_length . "\n" ); +} + +my $name_dm = 60502280; +my $no_of_trips = 10; +my $trips = get_trips($name_dm, $no_of_trips); +#print Dumper($trips); +print_trips($trips); diff --git a/rm_follow_links.sh b/rm_follow_links.sh new file mode 100644 index 0000000..a690569 --- /dev/null +++ b/rm_follow_links.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +list=$(ls -lR /srv/storage/prix_2012 | grep -e ^l | awk '{print $10}') +count=0 + +for line in $list; do + echo $line + #rm -r $line + count=$((count+1)) +done + +echo "count: $count" + +