Skip to content

Commit 4c2a230

Browse files
author
Sergio Cruz
committed
Fixed the download issues (v2)
1 parent 9cdfd89 commit 4c2a230

File tree

1 file changed

+52
-40
lines changed

1 file changed

+52
-40
lines changed

geonames_importer.sh

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ dbport=3306
66
dbname="geonames"
77
#dir=$( cd "$( dirname "$0" )" && pwd )
88

9-
download_folder="`pwd`/download"
9+
#download_folder="`pwd`/download"
10+
download_folder="`pwd`"
1011

1112
logo() {
1213
echo "================================================================================================"
13-
echo " G E O N A M E S D A T A I M P O R T E R "
14+
echo " G E O N A M E S D A T A I M P O R T E R V 2.0 "
1415
echo "================================================================================================"
1516
}
1617

1718
usage() {
1819
logo
19-
echo "Usage 1: " $0 "--download-data [folder]"
20-
echo "In this mode the current GeoNames.org's dumps are downloaded to the local machine."
21-
echo
22-
echo "Usage 2: " $0 "-a <action> -u <user> -p <password> -h <host> -r <port> -n <dbname>"
20+
echo "Usage: " $0 "-a <action> -u <user> -p <password> -h <host> -r <port> -n <dbname>"
2321
echo " This is to operate with the geographic database"
2422
echo " Where <action> can be one of this: "
25-
echo " download-data Downloads the last packages of data available in GeoNames."
23+
echo " download-data Downloads the last packages of data available in GeoNames. An additional parameter with a download directory should be used."
2624
echo " create-db Creates the mysql database structure with no data."
2725
echo " create-tables Creates the tables in the current database. Useful if we want to import them in an exsiting db."
2826
echo " import-dumps Imports geonames data into db. A database is previously needed for this to work."
@@ -39,22 +37,22 @@ usage() {
3937
exit -1
4038
}
4139

42-
download_geonames_data() {
43-
echo "Downloading GeoNames.org data..."
44-
download_folder="$1"
45-
dumps="allCountries.zip alternateNames.zip hierarchy.zip admin1CodesASCII.txt admin2Codes.txt featureCodes_en.txt timeZones.txt countryInfo.txt"
46-
zip_codes="allCountries.zip"
47-
for dump in $dumps; do
48-
wget -c -P "$download_folder" http://download.geonames.org/export/dump/$dump
49-
done
50-
for zip in $zip_codes; do
51-
wget -c -P "$download_folder" -O "${zip:0:(-4)}_zip.zip" http://download.geonames.org/export/zip/$zip
52-
done
53-
unzip "*_zip.zip" -d ./zip
54-
rm *_zip.zip
55-
unzip "*.zip"
56-
rm *.zip
57-
}
40+
# download_geonames_data() {
41+
# echo "Downloading GeoNames.org data..."
42+
# download_folder="$1"
43+
# dumps="allCountries.zip alternateNames.zip hierarchy.zip admin1CodesASCII.txt admin2Codes.txt featureCodes_en.txt timeZones.txt countryInfo.txt"
44+
# zip_codes="allCountries.zip"
45+
# for dump in $dumps; do
46+
# wget -c -P "$download_folder" http://download.geonames.org/export/dump/$dump
47+
# done
48+
# for zip in $zip_codes; do
49+
# wget -c -P "$download_folder" -O "${zip:0:(-4)}_zip.zip" http://download.geonames.org/export/zip/$zip
50+
# done
51+
# unzip "*_zip.zip" -d ./zip
52+
# rm *_zip.zip
53+
# unzip "*.zip"
54+
# rm *.zip
55+
# }
5856

5957
if [ $# -lt 1 ]; then
6058
usage
@@ -64,17 +62,17 @@ fi
6462
logo
6563

6664
# Deals operation mode 1 (Download data bundles from geonames.org)
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"
77-
fi
65+
#if { [ "$1" == "--download-data" ]; } then
66+
# if { [ "$2" != "" ]; } then
67+
# if [ ! -d "$2" ]; then
68+
# echo "Folder '$2' doesn't exists. Run mkdir..."
69+
# mkdir "$2"
70+
# fi
71+
# download_folder="$2"
72+
# fi
73+
# echo "download_folder=$download_folder"
74+
# download_geonames_data "$download_folder"
75+
#fi
7876

7977
# Deals with operation mode 2 (Database issues...)
8078
# Parses command line parameters.
@@ -93,7 +91,21 @@ done
9391

9492
case $action in
9593
download-data)
96-
download_geonames_data
94+
if { [ "$3" != "" ]; } then
95+
if [ ! -d "$3" ]; then
96+
echo "Temporary download data folder '$2' doesn't exists. Creating it."
97+
mkdir "$3"
98+
fi
99+
download_folder="`pwd`/$2"
100+
fi
101+
dumps="allCountries.zip alternateNames.zip hierarchy.zip admin1CodesASCII.txt admin2Codes.txt featureCodes_en.txt timeZones.txt countryInfo.txt"
102+
for dump in $dumps; do
103+
wget -c -P "$download_folder" http://download.geonames.org/export/dump/$dump
104+
if [ ${dump: -4} == ".zip" ]; then
105+
echo "Unzipping $dump..."
106+
unzip "$download_folder/$dump" -d "`pwd`"
107+
fi
108+
done
97109
exit 0
98110
;;
99111
esac
@@ -125,11 +137,11 @@ case "$action" in
125137
mysql -h $dbhost -P $dbport -u $dbusername -p$dbpassword $dbname < $dir/geonames_db_struct.sql
126138
;;
127139

128-
create-tables)
129-
echo "Creating tables for database $dbname..."
130-
mysql -h $dbhost -P $dbport -u $dbusername -p$dbpassword -Bse "USE $dbname;"
131-
mysql -h $dbhost -P $dbport -u $dbusername -p$dbpassword $dbname < $dir/geonames_db_struct.sql
132-
;;
140+
# create-tables)
141+
# echo "Creating tables for database $dbname..."
142+
# mysql -h $dbhost -P $dbport -u $dbusername -p$dbpassword -Bse "USE $dbname;"
143+
# mysql -h $dbhost -P $dbport -u $dbusername -p$dbpassword $dbname < $dir/geonames_db_struct.sql
144+
# ;;
133145

134146
import-dumps)
135147
echo "Importing geonames dumps into database $dbname"

0 commit comments

Comments
 (0)