Skip to content

Commit 4252d29

Browse files
committed
Add optional download_folder
1 parent 70a6a80 commit 4252d29

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

geonames_importer.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
dbhost="localhost"
55
dbport=3306
66
dbname="geonames"
7-
dir=$( cd "$( dirname "$0" )" && pwd )
7+
#dir=$( cd "$( dirname "$0" )" && pwd )
8+
9+
download_folder="`pwd`/download"
810

911
logo() {
1012
echo "================================================================================================"
@@ -14,7 +16,7 @@ logo() {
1416

1517
usage() {
1618
logo
17-
echo "Usage 1: " $0 "--download-data"
19+
echo "Usage 1: " $0 "--download-data [folder]"
1820
echo "In this mode the current GeoNames.org's dumps are downloaded to the local machine."
1921
echo
2022
echo "Usage 2: " $0 "-a <action> -u <user> -p <password> -h <host> -r <port> -n <dbname>"
@@ -39,13 +41,14 @@ usage() {
3941

4042
download_geonames_data() {
4143
echo "Downloading GeoNames.org data..."
44+
download_folder="$1"
4245
dumps="allCountries.zip alternateNames.zip hierarchy.zip admin1CodesASCII.txt admin2Codes.txt featureCodes_en.txt timeZones.txt countryInfo.txt"
4346
zip_codes="allCountries.zip"
4447
for dump in $dumps; do
45-
wget -c http://download.geonames.org/export/dump/$dump
48+
wget -c -P "$download_folder" http://download.geonames.org/export/dump/$dump
4649
done
4750
for zip in $zip_codes; do
48-
wget -c -O "${zip:0:(-4)}_zip.zip" http://download.geonames.org/export/zip/$zip
51+
wget -c -P "$download_folder" -O "${zip:0:(-4)}_zip.zip" http://download.geonames.org/export/zip/$zip
4952
done
5053
unzip "*_zip.zip" -d ./zip
5154
rm *_zip.zip
@@ -61,9 +64,16 @@ fi
6164
logo
6265

6366
# Deals operation mode 1 (Download data bundles from geonames.org)
64-
if { [ $# == 1 ] && [ "$1" == "--download-data" ]; } then
65-
download_geonames_data
66-
exit 0
67+
if { [ "$1" == "--download-data" ]; } then
68+
if { [ "$2" != "" ]; } then
69+
if [ ! -d "$2" ]; then
70+
echo "Folder '$2' doesn't exists. Run mkdir..."
71+
mkdir "$2"
72+
fi
73+
download_folder="$2"
74+
fi
75+
echo "download_folder=$download_folder"
76+
download_geonames_data "$download_folder"
6777
fi
6878

6979
# Deals with operation mode 2 (Database issues...)

0 commit comments

Comments
 (0)