exoplanets.pl   exoplanets.pl 
#!/usr/bin/perl #!/usr/bin/perl
# #
# Tool for generate catalog of exoplanets # Tool for generate catalog of exoplanets
# #
# Copyright (C) 2013 Alexander Wolf # Copyright (C) 2013, 2014 Alexander Wolf
# #
# Permission is hereby granted, free of charge, to any person obtaining a # Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software") , # copy of this software and associated documentation files (the "Software") ,
# to deal in the Software without restriction, including without limitation # to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, # the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the # and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions: # Software is furnished to do so, subject to the following conditions:
# #
# The above copyright notice and this permission notice shall be included # The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software. # in all copies or substantial portions of the Software.
skipping to change at line 50 skipping to change at line 50
$CNT = "./count"; $CNT = "./count";
$CATALOG_FORMAT_VERSION = 1; $CATALOG_FORMAT_VERSION = 1;
$dbname = "exoplanets"; $dbname = "exoplanets";
$dbhost = "localhost"; $dbhost = "localhost";
$dbuser = "exoplanet"; $dbuser = "exoplanet";
$dbpass = "exoplanet"; $dbpass = "exoplanet";
$UA = LWP::UserAgent->new(keep_alive => 1, timeout => 360); $UA = LWP::UserAgent->new(keep_alive => 1, timeout => 360);
$UA->agent("Mozilla/5.0 (Stellarium Exoplanets Catalog Updater 1.2; http:// stellarium.org/)"); $UA->agent("Mozilla/5.0 (Stellarium Exoplanets Catalog Updater 2.1; http:// stellarium.org/)");
$request = HTTP::Request->new('GET', $URL); $request = HTTP::Request->new('GET', $URL);
$responce = $UA->request($request); $responce = $UA->request($request);
if ($responce->is_success) { if ($responce->is_success) {
open(OUT, ">$CSV"); open(OUT, ">$CSV");
$data = $responce->content; $data = $responce->content;
binmode OUT; binmode OUT;
print OUT $data; print OUT $data;
close OUT; close OUT;
} else { } else {
skipping to change at line 96 skipping to change at line 96
$dbh = DBI->connect($dsn, $dbuser, $dbpass, {'RaiseError' => 1}); $dbh = DBI->connect($dsn, $dbuser, $dbpass, {'RaiseError' => 1});
$sth = $dbh->do(q{SET NAMES utf8}); $sth = $dbh->do(q{SET NAMES utf8});
$sth = $dbh->do(q{TRUNCATE stars}); $sth = $dbh->do(q{TRUNCATE stars});
$sth = $dbh->prepare(q{SELECT COUNT(pid) FROM planets}); $sth = $dbh->prepare(q{SELECT COUNT(pid) FROM planets});
$sth->execute(); $sth->execute();
@ipcnt = $sth->fetchrow_array(); @ipcnt = $sth->fetchrow_array();
$initCnt = @ipcnt[0]; $initCnt = @ipcnt[0];
$sth = $dbh->do(q{TRUNCATE planets}); $sth = $dbh->do(q{TRUNCATE planets});
# parse first line for guessing format of catalog
$currformat = $catalog[0];
$currformat =~ s/\#//gi;
$currformat =~ s/\s//gi;
$status = $csvdata->parse($currformat);
@fdata = ();
@fdata = $csvdata->fields();
%column = ();
for ($i=0;$i<scalar(@fdata);$i++) {
if ($fdata[$i] eq "name") { $column{'pname'} = $i;
}
if ($fdata[$i] eq "mass") { $column{'pmass'} = $i;
}
if ($fdata[$i] eq "radius") { $column{'pradius'} = $i;
}
if ($fdata[$i] eq "orbital_period") { $column{'pperiod'} = $i;
}
if ($fdata[$i] eq "semi_major_axis") { $column{'paxis'} = $i;
}
if ($fdata[$i] eq "eccentricity") { $column{'pecc'} = $i;
}
if ($fdata[$i] eq "inclination") { $column{'pincl'} = $i;
}
if ($fdata[$i] eq "angular_distance") { $column{'angdist'} = $i;
}
if ($fdata[$i] eq "discovered") { $column{'discovered'} = $i;
}
if ($fdata[$i] eq "star_name") { $column{'starname'} = $i;
}
if ($fdata[$i] eq "ra") { $column{'sra'} = $i;
}
if ($fdata[$i] eq "dec") { $column{'sdec'} = $i;
}
if ($fdata[$i] eq "mag_v") { $column{'svmag'} = $i;
}
if ($fdata[$i] eq "star_distance") { $column{'sdist'} = $i;
}
if ($fdata[$i] eq "star_metallicity") { $column{'smetal'} = $i;
}
if ($fdata[$i] eq "star_mass") { $column{'smass'} = $i;
}
if ($fdata[$i] eq "star_radius") { $column{'sradius'} = $i;
}
if ($fdata[$i] eq "star_sp_type") { $column{'sstype'} = $i;
}
if ($fdata[$i] eq "star_teff") { $column{'sefftemp'} = $i;
}
}
# parse other all lines for get data
for ($i=1;$i<scalar(@catalog);$i++) { for ($i=1;$i<scalar(@catalog);$i++) {
$currdata = $catalog[$i]; $currdata = $catalog[$i];
$currdata =~ s/nan//gi; $currdata =~ s/nan//gi;
$status = $csvdata->parse($currdata); $status = $csvdata->parse($currdata);
@psdata = (); @psdata = ();
@psdata = $csvdata->fields(); @psdata = $csvdata->fields();
@cfname = (); @cfname = ();
@cfname = split(" ",$psdata[0]); @cfname = split(" ",$psdata[$column{'pname'}]);
if (scalar(@cfname)==4) { if (scalar(@cfname)==4) {
$csname = $cfname[0]." ".$cfname[1]." ".$cfname[2]; $csname = $cfname[0]." ".$cfname[1]." ".$cfname[2];
$pname = $cfname[3]; $pname = $cfname[3];
} elsif (scalar(@cfname)==3) { } elsif (scalar(@cfname)==3) {
$csname = $cfname[0]." ".$cfname[1]; $csname = $cfname[0]." ".$cfname[1];
$pname = $cfname[2]; $pname = $cfname[2];
} else { } else {
$csname = $cfname[0]; $csname = $cfname[0];
$pname = $cfname[1]; $pname = $cfname[1];
} }
$pmass = $psdata[1]; # planet mass $pmass = $psdata[$column{'pmass'}]; # planet mas
$pradius = $psdata[4]; # planet radius s
$pperiod = $psdata[7]; # planet period $pradius = $psdata[$column{'pradius'}]; # planet rad
$paxis = $psdata[10]; # planet axis ius
$pecc = $psdata[13]; # planet eccentricity $pperiod = $psdata[$column{'pperiod'}]; # planet per
$pincl = $psdata[21]; # planet inclination iod
$angdist = $psdata[16]; # planet angular distance $paxis = $psdata[$column{'paxis'}]; # planet axi
$discovered = $psdata[37]; # planet discovered s
$starname = $psdata[48]; # star name $pecc = $psdata[$column{'pecc'}]; # planet ecc
$sRA = $psdata[49]; # star RA entricity
$sDec = $psdata[50]; # star dec $pincl = $psdata[$column{'pincl'}]; # planet inc
$sVmag = $psdata[51]; # star v magnitude lination
$sdist = $psdata[56]; # star distance $angdist = $psdata[$column{'angdist'}]; # planet ang
$smetal = $psdata[57]; # star metallicity ular distance
$smass = $psdata[58]; # star mass $discovered = $psdata[$column{'discovered'}]; # planet dis
$sradius = $psdata[59]; # star radius covered
$sstype = $psdata[60]; # star spectral type $starname = $psdata[$column{'starname'}]; # star name
$sefftemp = $psdata[62]; # star effective temperature $sRA = $psdata[$column{'sra'}]; # star RA
$sDec = $psdata[$column{'sdec'}]; # star dec
$sVmag = $psdata[$column{'svmag'}]; # star v mag
nitude
$sdist = $psdata[$column{'sdist'}]; # star dista
nce
$smetal = $psdata[$column{'smetal'}]; # star metal
licity
$smass = $psdata[$column{'smass'}]; # star mass
$sradius = $psdata[$column{'sradius'}]; # star radiu
s
$sstype = $psdata[$column{'sstype'}]; # star spect
ral type
$sefftemp = $psdata[$column{'sefftemp'}]; # star effec
tive temperature
$part = $sRA/15; $part = $sRA/15;
$hour = int($part); $hour = int($part);
$mint = int(($part-$hour)*60); $mint = int(($part-$hour)*60);
$sect = int((($part-$hour)*3600-60*$mint)*10)/10; $sect = int((($part-$hour)*3600-60*$mint)*10)/10;
$deg = int($sDec); $deg = int($sDec);
$min = int(($sDec-$deg)*60); $min = int(($sDec-$deg)*60);
$sec = int((($sDec-$deg)*3600-60*$min)*10)/10; $sec = int((($sDec-$deg)*3600-60*$min)*10)/10;
skipping to change at line 158 skipping to change at line 189
$hour = 19; $hour = 19;
} }
# fixed bug for omi CrB # fixed bug for omi CrB
if ($starname =~ m/omi\s+CrB/gi) { if ($starname =~ m/omi\s+CrB/gi) {
$hour = 15; $mint = 20; $sect = 8.4; $hour = 15; $mint = 20; $sect = 8.4;
$deg = 29; $min = 36; $sec = 57.9; $deg = 29; $min = 36; $sec = 57.9;
} }
$outRA = $hour."h".abs($mint)."m".abs($sect)."s"; $outRA = $hour."h".abs($mint)."m".abs($sect)."s";
$outDE = $deg."d".abs($min)."m".abs($sec)."s"; $outDE = $deg."d".abs($min)."m".abs($sec)."s";
# fixed bug for 24 Sex
if ($starname =~ m/24\s+Sex/gi) {
$outDE = "-".$outDE;
}
$sname = $starname; $sname = $starname;
$sname =~ s/^alpha/α/gi; $sname =~ s/^alpha/α/gi;
$sname =~ s/^alf/α/gi; $sname =~ s/^alf/α/gi;
$sname =~ s/^beta/β/gi; $sname =~ s/^beta/β/gi;
$sname =~ s/^gamma/γ/gi; $sname =~ s/^gamma/γ/gi;
$sname =~ s/^delta/δ/gi; $sname =~ s/^delta/δ/gi;
$sname =~ s/^epsilon/ε/gi; $sname =~ s/^epsilon/ε/gi;
$sname =~ s/^eps/ε/gi; $sname =~ s/^eps/ε/gi;
 End of changes. 6 change blocks. 
21 lines changed or deleted 89 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/