-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from hopcity/split_download_and_ingest
split download and ingest logic into two scripts
- Loading branch information
Showing
9 changed files
with
162 additions
and
74 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 |
---|---|---|
|
@@ -68,4 +68,6 @@ cityscrape/* | |
|
||
# Tempfiles | ||
*.zip | ||
*.tmp | ||
*.tmp | ||
|
||
workdir/* |
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
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
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
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,13 @@ | ||
#!/bin/bash -e | ||
|
||
CONFIGFILE="config/cityscrape-config.sh" | ||
|
||
# Bootstrap the config into our bash env | ||
. $CONFIGFILE | ||
|
||
# Activate virtualenv | ||
. $CITYSCRAPE_VIRTUALENV_DIR/bin/activate | ||
|
||
echo "Running Cityscrape Download" | ||
|
||
python $BASEDIR/src/grab_all_files.py |
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,49 @@ | ||
#!/bin/bash -e | ||
|
||
CONFIGFILE="config/cityscrape-config.sh" | ||
|
||
. $CONFIGFILE | ||
|
||
echo "Running Cityscrape PostgreSQL Ingest" | ||
pushd $OUTPUT_DIR | ||
|
||
echo "Unzipping files..." | ||
unzip -f "*.zip" | ||
|
||
if [ -z "$(ls *.shp)" ] | ||
then | ||
echo "No *.shp files found, exiting..." | ||
break | ||
else | ||
for f in *.shp | ||
do | ||
echo "Loading "$f | ||
|
||
ogr2ogr -overwrite -progress -skipfailures -f "PostgreSQL" PG:"host=localhost user=postgres dbname=city" $f# | ||
|
||
done | ||
fi | ||
|
||
for f in *.mdb | ||
|
||
do | ||
echo "Extracting tables from $f" | ||
|
||
mdb-schema $f postgres | sed 's/Char/Varchar/g' | sed 's/Postgres_Unknown 0x0c/text/g' | psql -h localhost -U postgres -d city | ||
|
||
tables=$(echo -en $(mdb-schema $f postgres | grep "CREATE TABLE" | awk '{ print $3 }' | sed -e 's/"//g');) | ||
|
||
for i in $tables | ||
|
||
do | ||
echo "[File: "$f" ] [Table - "$i"]" | ||
|
||
mdb-export -D ‘%%Y-%%m-%%d %%H:%%M:%%S’ -I postgress -q \’ -R \; $f $i | psql -d city -U postgres -w -h localhost | ||
|
||
done | ||
|
||
done | ||
|
||
# # return to project root $BASEDIR | ||
popd | ||
|
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
#!/bin/bash | ||
|
||
CONFIGFILE="config/cityscrape-config.sh" | ||
|
||
. $CONFIGFILE | ||
|
||
echo "Running Cityscrape PostgreSQL Ingest" | ||
|
||
pushd $WORKDIR | ||
echo "Unzipping files..." | ||
|
||
zip_files=$(echo `ls *.zip 2>/dev/null`) | ||
if [ -z "$zip_files" ]; then | ||
echo "No *.zip files found, skipping unzip..." | ||
else | ||
for zip_file in $zip_files; | ||
do | ||
unzip -o $zip_file | ||
done | ||
echo "Unzip complete" | ||
fi | ||
|
||
shp_files=$(echo `ls *.shp 2>/dev/null`) | ||
if [ -z "$shp_files" ]; then | ||
echo "No *.shp files found, skipping ogr2ogr..." | ||
else | ||
for shp_file in $shp_files; | ||
do | ||
echo `ls $shp_file` | ||
# ogr2ogr -overwrite -progress -skipfailures -f "PostgreSQL" PG:"host=localhost user=postgres dbname=city" $shp_file | ||
done | ||
fi | ||
|
||
pushd $DDL_FILES | ||
echo "Building ddl sql files now..." | ||
|
||
mdb_files=$(echo `ls *.mdb 2>/dev/null`) | ||
if [ -z "$mdb_files" ]; then | ||
echo "No *.mdb files found, exiting..." | ||
else | ||
for mdb_file in $mdb_files | ||
do | ||
echo "Extracting tables from $mdb_file" | ||
ddl_file=$mdb_file$DDL_FILE_SUFFIX | ||
|
||
mdb-schema $mdb_file | sed 's/Char/Varchar/g' | sed 's/Postgres_Unknown 0x0c/text/g' > "$ddl_file" | ||
|
||
tables=$(echo -en $(mdb-schema $mdb_file postgres | grep "CREATE TABLE IF NOT EXISTS" | awk '{ print $3 }' | sed -e 's/"//g');) | ||
|
||
if [ -z "$tables" ] | ||
then | ||
echo "No tables found, skipping table ddl generation." | ||
else | ||
for table in $tables | ||
do | ||
echo $table > "$table$DDL_FILE_SUFFIX" | ||
done | ||
fi | ||
done | ||
fi | ||
|
||
popd | ||
|
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