Created
June 19, 2010 02:53
-
-
Save elecnix/444526 to your computer and use it in GitHub Desktop.
"Upload to OpenStreetMap" script for Nautilus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl -w | |
| # For Gnome users, name this file "Upload to OpenStreetMap", make it executable, and place it | |
| # into your ~/.gnome2/nautilus-scripts/ folder. Then, when you right-click a file, you can go | |
| # to "Scripts", and "Upload to OpenStreetMap". You will be prompted to enter a description for | |
| # the GPX trace, and a visibility. | |
| # | |
| # Based on: http://wiki.openstreetmap.org/wiki/Batch_Upload#Perl | |
| # Converted to Zenity by Nicolas Marchildon (elecnix), June 2010 | |
| use HTTP::Request::Common; | |
| use LWP::UserAgent; | |
| $yourusername=''; # put your OSM username between the quotes | |
| $yourpassword=''; # put your OSM password between the quotes | |
| foreach $filename (@ARGV) { | |
| $ua=LWP::UserAgent->new; | |
| $ua->credentials('www.openstreetmap.org:80','Web Password',$yourusername, $yourpassword); | |
| print "Uploading $filename\n"; | |
| $description=`zenity --entry --title 'Uploading $filename' --text='Description de la trace GPX:' --entry-text='$filename'`; | |
| if (!$description) { exit 1; } | |
| $visibility=`zenity --list --radiolist --column "" --column "" --hide-header TRUE identifiable FALSE trackable FALSE private`; | |
| $tags=''; | |
| chomp $visibility; | |
| $response=$ua->request(POST 'http://www.openstreetmap.org/api/0.6/gpx/create', | |
| Content_Type => 'form-data', | |
| Content => [ file =>[$filename], | |
| description=>$description, | |
| tags =>$tags, | |
| visibility =>$visibility ] ); | |
| if ($response->code==200) { | |
| `zenity --info --text="Uploaded $filename successfully"`; | |
| } else { | |
| $content=$response->content; | |
| `zenity --info --text="Couldn't upload $filename: $content"`; | |
| exit 1 | |
| } | |
| } | |
| foreach $filename (@ARGV) { | |
| $ua=LWP::UserAgent->new; | |
| $ua->credentials('www.openstreetmap.org:80','Web Password',$yourusername, $yourpassword); | |
| print "Uploading $filename\n"; | |
| $description=`zenity --entry --title 'Uploading $filename' --text='Description de la trace GPX:'`; | |
| if (!$description) { exit 1; } | |
| $visibility=`zenity --list --radiolist --column "" --column "" --hide-header TRUE identifiable FALSE trackable FALSE private`; | |
| $tags=''; | |
| chomp $visibility; | |
| $response=$ua->request(POST 'http://www.openstreetmap.org/api/0.6/gpx/create', | |
| Content_Type => 'form-data', | |
| Content => [ file =>[$filename], | |
| description=>$description, | |
| tags =>$tags, | |
| visibility =>$visibility ] ); | |
| if ($response->code==200) { | |
| `zenity --info --text="Uploaded $filename successfully"`; | |
| } else { | |
| $content=$response->content; | |
| `zenity --info --text="Couldn't upload $filename: $content"`; | |
| exit 1 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment