Skip to content

Instantly share code, notes, and snippets.

@yanaiela
Last active April 23, 2024 09:42
Show Gist options
  • Save yanaiela/cfef50380de8a5bfc8c272bb0c91d6e1 to your computer and use it in GitHub Desktop.
Save yanaiela/cfef50380de8a5bfc8c272bb0c91d6e1 to your computer and use it in GitHub Desktop.
simple bash script for downloading the Google word2vec model (https://code.google.com/archive/p/word2vec/) from Google-Drive
#!/bin/bash
# usage:
# first make the file executable
# ./word2vec-download300model.sh output-file
OUTPUT=$( wget --save-cookies cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=0B7XkCwpI5KDYNlNUTTlSS21pQmM' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/Code: \1\n/p' )
CODE=${OUTPUT##*Code: }
echo $CODE
F='GoogleNews-vectors-negative300.bin.gz'
if [ -z "$1" ]
then
OUT_F=$F
else
OUT_F=$1/$F
fi
echo $OUT_F
wget --load-cookies cookies.txt 'https://docs.google.com/uc?export=download&confirm='$CODE'&id=0B7XkCwpI5KDYNlNUTTlSS21pQmM' -O $OUT_F
@Imane0
Copy link

Imane0 commented Jul 19, 2017

I copied-past the first command, i.e the one that assigns a value to 'OUTPUT'. But I am getting a sed error message

sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
--2017-07-19 09:16:51--  https://docs.google.com/uc?export=download&id=0B7XkCwpI5KDYNlNUTTlSS21pQmM
Resolving docs.google.com... 172.217.22.142, 2a00:1450:4009:804::200e
Connecting to docs.google.com|172.217.22.142|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘STDOUT’


    [ <=>                                              ] 0           --.-K/s   in 0s      


Cannot write to ‘-’ (Success).

Because of this, the variable 'CODE' is empty.

@yanaiela
Copy link
Author

Hey,
This script is supposed to be download and use a bash script. The input for it should be the directory where you want it to get downloaded.
It seems like you just executed line by line, and this why you haven't configured the relevant directory

@JafferWilson
Copy link

Hello Can you add a line how to execute the command using bash and where to give the folder to the script?

@yanaiela
Copy link
Author

yanaiela commented Oct 2, 2017

Just added it to the file.
./word2vec-download300model.sh output-file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment