first commit
This commit is contained in:
117
scripts/perl/traffic/conf2xml.pl
Executable file
117
scripts/perl/traffic/conf2xml.pl
Executable file
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
sub parseTime {
|
||||
# print "Parsing time @_\n";
|
||||
#die;
|
||||
my $timeStr = $_[0];
|
||||
@timeArray = split(":", $timeStr);
|
||||
# print STDERR "TimeArray: @timeArray\n";
|
||||
return ($timeArray[0] + $timeArray[1]/60.0);
|
||||
}
|
||||
|
||||
sub writeFlight {
|
||||
print XMLFILE " <flight>\n";
|
||||
print XMLFILE " <callsign>$_[0]</callsign>\n";
|
||||
print XMLFILE " <required-aircraft>$_[1]</required-aircraft>\n";
|
||||
print XMLFILE " <fltrules>$_[2]</fltrules>\n";
|
||||
print XMLFILE " <departure>\n";
|
||||
print XMLFILE " <port>$_[3]</port>\n";
|
||||
if ($_[4] =~ /[0-6]/) { print XMLFILE " <time>$_[4]/$_[5]:00</time>\n" }
|
||||
else { print XMLFILE " <time>$_[5]:00</time>\n" };
|
||||
print XMLFILE " </departure>\n";
|
||||
print XMLFILE " <cruise-alt>$_[6]</cruise-alt>\n";
|
||||
print XMLFILE " <arrival>\n";
|
||||
print XMLFILE " <port>$_[7]</port>\n";
|
||||
if ($_[8] =~ /[0-6]/) { print XMLFILE " <time>$_[8]/$_[9]:00</time>\n" }
|
||||
else { print XMLFILE " <time>$_[9]:00</time>\n" };
|
||||
print XMLFILE " </arrival>\n";
|
||||
if (($_[4] =~ /[0-6]/) && ($_[8] =~ /[0-6]/)) { print XMLFILE " <repeat>WEEK</repeat>\n" }
|
||||
else { print XMLFILE " <repeat>24Hr</repeat>\n" };
|
||||
print XMLFILE " </flight>\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@inputfiles = glob("???.conf");
|
||||
while ($infile = shift(@inputfiles)) {
|
||||
open (CONF, $infile) or die "Unable to open input configuration file";
|
||||
($outname = $infile) =~ s/conf/xml/;
|
||||
print "Opening $outname\n";
|
||||
open XMLFILE, ">$outname";
|
||||
while ($buf = readline(CONF)) {
|
||||
push @DataList, $buf;
|
||||
}
|
||||
close (CONF);
|
||||
print XMLFILE "<?xml version=\"1.0\"?>\n";
|
||||
print XMLFILE "<trafficlist>\n";
|
||||
while ($dataline = shift(@DataList)) {
|
||||
# print STDERR "Dataline: $dataline\n";
|
||||
@token = split(" ", $dataline);
|
||||
if (scalar(@token) > 0) {
|
||||
# print STDERR "Token: @token\n";
|
||||
if ($token[0] eq "AC")
|
||||
{
|
||||
print XMLFILE " <aircraft>\n";
|
||||
print XMLFILE " <model>$token[12]</model>\n";
|
||||
print XMLFILE " <livery>$token[6]</livery>\n";
|
||||
print XMLFILE " <airline>$token[5]</airline>\n";
|
||||
print XMLFILE " <home-port>$token[1]</home-port>\n";
|
||||
print XMLFILE " <required-aircraft>$token[3]$token[5]</required-aircraft>\n";
|
||||
print XMLFILE " <actype>$token[4]</actype>\n";
|
||||
print XMLFILE " <offset>$token[7]</offset>\n";
|
||||
print XMLFILE " <radius>$token[8]</radius>\n";
|
||||
print XMLFILE " <flighttype>$token[9]</flighttype>\n";
|
||||
print XMLFILE " <performance-class>$token[10]</performance-class>\n";
|
||||
print XMLFILE " <registration>$token[2]</registration>\n";
|
||||
print XMLFILE " <heavy>$token[11]</heavy>\n";
|
||||
print XMLFILE " </aircraft>\n";
|
||||
}
|
||||
if ($token[0] eq "FLIGHT") {
|
||||
$weekdays = $token[3];
|
||||
if (!(($weekdays =~ /^(0|\.)?(1|\.)?(2|\.)?(3|\.)?(4|\.)?(5|\.)?(6|\.)?$/) || ($weekdays eq "DAILY"))) {
|
||||
die "Syntax Error! Check days $weekdays for flight no. $token[1]!\n";
|
||||
}
|
||||
if ($token[4] !~ /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])$/) {
|
||||
die "Syntax Error! Check departure time $token[4] for flight no. $token[1]!\n"
|
||||
}
|
||||
if ($token[6] !~ /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])$/) {
|
||||
die "Syntax Error! Check arrival time $token[6] for flight no. $token[1]!\n"
|
||||
}
|
||||
# print STDERR "Weekdays: $weekdays\n";
|
||||
if ($weekdays =~ /^(0|\.)?(1|\.)?(2|\.)?(3|\.)?(4|\.)?(5|\.)?(6|\.)?$/) {
|
||||
# print STDERR "Weekly for flight no. $token[1]\n";
|
||||
# print STDERR "Day: $_\n";
|
||||
@day = split(//, $weekdays);
|
||||
foreach (@day) {
|
||||
if ($_ eq "\.") {
|
||||
next;
|
||||
} else {
|
||||
$depTime = parseTime($token[4]);
|
||||
# print STDERR "depTime: $depTime\n";
|
||||
$arrTime = parseTime($token[6]);
|
||||
# print STDERR "arrTime: $arrTime\n";
|
||||
$depDay = $_ + 1;
|
||||
if ($depDay > 6) { $depDay = 0 };
|
||||
$arrDay = $depDay;
|
||||
if ($depTime > $arrTime) { $arrDay++ };
|
||||
if ($arrDay > 6) { $arrDay = 0 };
|
||||
# print STDERR "depDay: $depDay, arrDay: $arrDay\n";
|
||||
writeFlight ($token[1], $token[9], $token[2], $token[5], $depDay, $token[4], $token[8], $token[7], $arrDay, $token[6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ($weekdays eq "DAILY") {
|
||||
# print STDERR "Daily flights for flight no. $token[1]\n";
|
||||
$depTime = parseTime($token[4]);
|
||||
$arrTime = parseTime($token[6]);
|
||||
writeFlight ($token[1], $token[9], $token[2], $token[5], 7, $token[4], $token[8], $token[7], 7, $token[6]);
|
||||
}
|
||||
else {
|
||||
die "System Error! Can't find days to place a flight!\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print XMLFILE "</trafficlist>\n";
|
||||
close XMLFILE;
|
||||
# print "Closing $outname\n";
|
||||
}
|
||||
99
scripts/perl/traffic/xml2conf.pl
Executable file
99
scripts/perl/traffic/xml2conf.pl
Executable file
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
#use strict;
|
||||
#use warnings;
|
||||
|
||||
# DEBUG
|
||||
# use Data::Dumper;
|
||||
# print Dumper($data) . "\n";
|
||||
# END
|
||||
|
||||
if (scalar (@ARGV) == 1) {
|
||||
@files = glob("$ARGV[0]");
|
||||
print "Processing : ", @files, "\n";
|
||||
} else {
|
||||
die "Usage : conf2xml.pl <inputfile> [ > outputfile ]\n";
|
||||
}
|
||||
$file = shift(@files);
|
||||
|
||||
use Switch;
|
||||
use XML::LibXML;
|
||||
my $parser = XML::LibXML->new();
|
||||
my $doc = $parser->load_xml(location => $file);
|
||||
my $data;
|
||||
|
||||
# reformatting days
|
||||
# According to http://wiki.flightgear.org/index.php/Interactive_Traffic
|
||||
# 0 = Sunday and 6 = saturday
|
||||
# For convenience we switch here to "classical" numbering
|
||||
# where 0 = Monday and 6 = sunday
|
||||
sub parseDay {
|
||||
my $day;
|
||||
$day = substr($_[0],0,1);
|
||||
switch ($day) {
|
||||
case 0 {$day="......6"} # Sunday
|
||||
case 1 {$day="0......"} # Monday
|
||||
case 2 {$day=".1....."} # Tuesday
|
||||
case 3 {$day="..2...."} # Wednesday
|
||||
case 4 {$day="...3..."} # Thrusday
|
||||
case 5 {$day="....4.."} # Friday
|
||||
case 6 {$day=".....5."} # Saturday
|
||||
else {$day="0123456"} # Daily
|
||||
};
|
||||
return $day;
|
||||
}
|
||||
|
||||
# reformatting times
|
||||
sub parseTime {
|
||||
return substr($_[0],2,5);
|
||||
}
|
||||
|
||||
print "# AC Homeport Registration RequiredAC AcTyp Airline Livery Offset Radius Flighttype PerfClass Heavy Model\n";
|
||||
# get aircraft data
|
||||
foreach $data ($doc->findnodes('/trafficlist/aircraft')) {
|
||||
my $AcMdl = $data->findnodes('./model');
|
||||
my $AcLvy = $data->findnodes('./livery');
|
||||
my $AcAln = $data->findnodes('./airline');
|
||||
my $AcHp = $data->findnodes('./home-port');
|
||||
my $AcReq = $data->findnodes('./required-aircraft');
|
||||
my $AcTyp = $data->findnodes('./actype');
|
||||
my $AcO = $data->findnodes('./offset');
|
||||
my $AcRad = $data->findnodes('./radius');
|
||||
my $AcFt = $data->findnodes('./flighttype');
|
||||
my $AcPrf = $data->findnodes('./performance-class');
|
||||
my $AcReg = $data->findnodes('./registration');
|
||||
my $AcHvy = $data->findnodes('./heavy');
|
||||
print "AC $AcHp $AcReg $AcReq $AcTyp $AcAln $AcLvy $AcO $AcRad $AcFt $AcPrf $AcHvy $AcMdl\n";
|
||||
}
|
||||
print "\n# FLIGHT Callsign Flightrule Days DeparTime DepartPort ArrivalTime ArrivalPort Altitude RequiredAc\n# 0 = Monday, 6 = Sunday\n";
|
||||
# get flight data
|
||||
foreach $data ($doc->findnodes('/trafficlist/flight')) {
|
||||
my $FlRep = $data->findnodes('repeat');
|
||||
my $FlDepPrt = $data->findnodes('departure/port');
|
||||
my $FlArrPrt = $data->findnodes('arrival/port');
|
||||
my $FlCs = $data->findnodes('callsign');
|
||||
my $FlFr = $data->findnodes('fltrules');
|
||||
my $FlCa = $data->findnodes('cruise-alt');
|
||||
my $FlReq = $data->findnodes('required-aircraft');
|
||||
my $FlDepDay = $data->findnodes('departure/time');
|
||||
my $FlDepTime = $data->findnodes('departure/time');
|
||||
my $FlArrDay = $data->findnodes('arrival/time');
|
||||
my $FlArrTime = $data->findnodes('arrival/time');
|
||||
my $FlDays = ".......";
|
||||
# handle flights depending on weekly or daily schedule
|
||||
if (lc($FlRep) eq "week") {
|
||||
$FlDays = parseDay($FlDepTime);
|
||||
$FlDepTime = parseTime($FlDepTime);
|
||||
$FlArrTime = parseTime($FlArrTime);
|
||||
} elsif (lc($FlRep) eq "24hr") {
|
||||
$FlDepDay = $data->findnodes('departure/time');
|
||||
$FlDepTime = substr($data->findnodes('departure/time'),0,5);
|
||||
$FlArrDay = $data->findnodes('arrival/time');
|
||||
$FlArrTime = substr($data->findnodes('arrival/time'),0,5);
|
||||
$FlDays = "0123456";
|
||||
} else {
|
||||
die "Error! No proper repetition found in XML!\n";
|
||||
}
|
||||
# output data
|
||||
print "FLIGHT $FlCs $FlFr $FlDays $FlDepTime $FlDepPrt $FlArrTime $FlArrPrt $FlCa $FlReq\n";
|
||||
}
|
||||
Reference in New Issue
Block a user