Skip to content

download and load a complete stackexchange project #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Schema hints are taken from [a post on Meta.StackExchange](http://meta.stackexch
## Dependencies

- [`lxml`](http://lxml.de/installation.html)
- [`psychopg2`](http://initd.org/psycopg/docs/install.html)
- [`psycopg2`](http://initd.org/psycopg/docs/install.html)

## Usage

Expand Down
13 changes: 10 additions & 3 deletions load_into_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,23 @@ def moveTableToSchema(table, schemaName, dbConnectionParam):
# load a project
elif args.so_project:
import libarchive
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify that you are using libarchive-c library instead of libarchive?

I will add this to the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am indeed using libarchive-c (in version 2.8).

import tempfile

filepath = None
if args.file:
filepath = args.file
url = filepath
else:
# download the 7z archive in /tmp
# download the 7z archive in tempdir
file_name = args.so_project + '.stackexchange.com.7z'
url = '{0}/{1}'.format(args.archive_url, file_name)
filepath = '/tmp/'+file_name
six.print_('Downloading the archive, please be patient ...')
temp_dir = tempfile.gettempdir()
if temp_dir == 'None':
six.print_('WARNING: Could not find temporary directory. Use current directory instead.')
temp_dir = os.getcwd()
filepath = os.path.join(temp_dir, file_name)
six.print_('Downloading the archive in {0}'.format(filepath))
six.print_('please be patient ...')
try:
six.moves.urllib.request.urlretrieve(url, filepath, show_progress)
except Exception as e:
Expand Down