-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env perl | ||
# -*- perl -*- | ||
|
||
# | ||
# Author: Slaven Rezic | ||
# | ||
# Copyright (C) 2024 Slaven Rezic. All rights reserved. | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the same terms as Perl itself. | ||
# | ||
# Mail: [email protected] | ||
# WWW: http://www.rezic.de/eserte/ | ||
# | ||
|
||
use strict; | ||
use warnings; | ||
use POSIX qw(strftime); | ||
|
||
my $headline_start_rx = qr{^\*+\s+(TODO|DONE|WAITING|WONTFIX|LATER)\s+}; | ||
|
||
my $file = shift or die "org mode file?"; | ||
|
||
my @locations; | ||
|
||
open my $fh, '<:encoding(utf-8)', $file | ||
or die "Can't open $file: $!"; | ||
my $active_headline; | ||
my $active_headline_is_TODO; | ||
while(<$fh>) { | ||
if (/$headline_start_rx/) { | ||
$active_headline = $_; | ||
$active_headline_is_TODO = $1 eq 'TODO'; | ||
} | ||
if ($active_headline_is_TODO && m{\[\[geo:([-+]?\d+(?:\.\d+)?),([-+]?\d+(?:\.\d+)?)(?:\?z=(\d+(?:\.\d+)?))?\](?:\[(.*?)\])?\]}) { | ||
my($lat, $lon, $zoom, $link_title) = ($1,$2,$3,$4); # $zoom not yet used | ||
if (!defined $active_headline) { | ||
warn "Found geo URI for $lat/$lon, but without an associated org-mode headline, skipping...\n"; | ||
next; | ||
} | ||
push @locations, { | ||
link_title => (defined $link_title ? $link_title : extract_headline($active_headline)), | ||
lon => $lon, | ||
lat => $lat, | ||
}; | ||
} | ||
} | ||
|
||
if (!@locations) { | ||
die "No locations found in $file.\n"; | ||
} | ||
|
||
binmode STDOUT, ':encoding(utf-8)'; | ||
print <<EOF; | ||
#: encoding: utf-8 | ||
#: map: polar | ||
#: | ||
# Converted from $file at @{[ strftime("%Y-%m-%d %H:%M:%S", localtime) ]} | ||
# | ||
EOF | ||
for my $location (@locations) { | ||
my $link_title = $location->{link_title}; | ||
$link_title =~ s{[\t\n]}{ }g; | ||
print "$link_title\tX $location->{lon},$location->{lat}\n"; | ||
} | ||
|
||
sub extract_headline { | ||
my $headline = shift; | ||
$headline =~ s{$headline_start_rx}{}; # TODO/DONE | ||
$headline =~ s{\[#A-F\]\s*}{}; # priority | ||
$headline =~ s{\s+:.*?:\s*$}{}; # tags | ||
$headline; | ||
} | ||
|
||
__END__ | ||
=head1 NAME | ||
org2bbd - find org-mode TODO items with geolocations and convert to bbd | ||
=head1 SYNOPSIS | ||
org2bbd TODO.org > TODO.bbd | ||
=head1 TODO | ||
* maybe make it public by moving to bbbike? | ||
* document pipe together with bbd2gpx | ||
* probably a better fallback for the location name would be a string on the same line like the geo link | ||
=cut |