flickru 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/geowiki +35 -9
- data/lib/flickru.rb +1 -1
- data/lib/flickru/location.rb +6 -4
- data/lib/flickru/version.rb +1 -1
- metadata +1 -1
data/bin/geowiki
CHANGED
@@ -1,21 +1,42 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
+
###########
|
4
|
+
# Globals #
|
5
|
+
###########
|
6
|
+
|
3
7
|
APP_NAME=`basename $0`
|
8
|
+
PAGE=`echo "$1" | tr ' ' '_'`
|
4
9
|
|
5
|
-
|
6
|
-
#
|
7
|
-
|
8
|
-
}
|
10
|
+
#############
|
11
|
+
# Functions #
|
12
|
+
#############
|
9
13
|
|
10
|
-
|
14
|
+
function usage {
|
11
15
|
echo "$APP_NAME - find coordinates of a place described by Wikipedia"
|
12
16
|
echo "usage: $APP_NAME <place Wikipedia page>"
|
13
17
|
echo "example: $APP_NAME 'Mille-Isles, Quebec'"
|
18
|
+
}
|
19
|
+
|
20
|
+
function error {
|
21
|
+
echo -e "\033[31m$APP_NAME: $1: $2\033[0m" 1>&2
|
22
|
+
}
|
23
|
+
|
24
|
+
#################
|
25
|
+
# Preconditions #
|
26
|
+
#################
|
27
|
+
|
28
|
+
if [ "$1" == "-h" -o "$1" == "--help" ]; then
|
29
|
+
usage
|
30
|
+
exit
|
31
|
+
elif [ $# -ne 1 ]; then
|
32
|
+
usage
|
14
33
|
error $LINENO "wrong number of arguments"
|
15
34
|
exit 1
|
16
35
|
fi
|
17
36
|
|
18
|
-
|
37
|
+
#########
|
38
|
+
# Setup #
|
39
|
+
#########
|
19
40
|
|
20
41
|
# temporal file management
|
21
42
|
if [ -d /tmp ]; then
|
@@ -29,7 +50,11 @@ function clean_up {
|
|
29
50
|
}
|
30
51
|
trap clean_up SIGHUP SIGINT SIGTERM
|
31
52
|
|
32
|
-
|
53
|
+
########
|
54
|
+
# Main #
|
55
|
+
########
|
56
|
+
|
57
|
+
curl "http://en.wikipedia.org/wiki/$PAGE" -o "$TMP" 2> /dev/null
|
33
58
|
|
34
59
|
if [ $? -ne 0 ]; then
|
35
60
|
error $LINENO "Wikipedia page '$PAGE' not found"
|
@@ -43,13 +68,14 @@ URL=`cat "$TMP" | tr '"' '\n' | grep geohack | head -n 1 | sed -e 's|&|\&|'`
|
|
43
68
|
clean_up 1
|
44
69
|
fi
|
45
70
|
|
46
|
-
curl "$URL"
|
71
|
+
curl "$URL" -o "$TMP" 2> /dev/null
|
47
72
|
|
48
73
|
if [ $? -ne 0 ]; then
|
49
74
|
error $LINENO "GeoHack URL '$URL' not found"
|
50
75
|
clean_up 1
|
51
76
|
fi
|
52
77
|
|
53
|
-
cat "$TMP" | grep '<span class="geo"'
|
78
|
+
cat "$TMP" | grep '<span class="geo"' \
|
79
|
+
| sed -e 's|^.*"Latitude">\([^<]*\)</span>, .*"Longitude">\([^<]*\)</span>.*$|\1, \2|'
|
54
80
|
|
55
81
|
clean_up
|
data/lib/flickru.rb
CHANGED
@@ -89,7 +89,7 @@ def self.flickru photo_dir
|
|
89
89
|
" and better collection mosaics can be randomised."
|
90
90
|
rescue Exception => e
|
91
91
|
file_line = e.backtrace[0].split(':')
|
92
|
-
Printer.error "error:#{File.basename file_line[
|
92
|
+
Printer.error "error:#{File.basename file_line[-3]}:#{file_line[-2]}: #{e.message}"
|
93
93
|
exit 1
|
94
94
|
end
|
95
95
|
|
data/lib/flickru/location.rb
CHANGED
@@ -62,10 +62,12 @@ private
|
|
62
62
|
def self.locate place
|
63
63
|
the_place = place # needed for RuntimeError reporting
|
64
64
|
begin
|
65
|
-
is_win = RbConfig::CONFIG['target_os']
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
is_win = case RbConfig::CONFIG['target_os']
|
66
|
+
when /mswin|mingw|cygwin/i then true
|
67
|
+
else false end
|
68
|
+
command = Escape.shell_command((is_win ? ['bash'] : []) + [GEOWIKI, place])
|
69
|
+
null = is_win ? 'NUL' : '/dev/null'
|
70
|
+
place = `#{command} 2> #{null}`[0..-2] \
|
69
71
|
if place !~ /^#{COORD_PATTERN}, *#{COORD_PATTERN}$/
|
70
72
|
if place =~ /^#{COORD_PATTERN}, *#{COORD_PATTERN}$/
|
71
73
|
# latitude, longitude
|
data/lib/flickru/version.rb
CHANGED