Please see: https://github.com/wikimedia/labs-tools-gdrive-to-commons
This tool is developed to Upload images directly from Google drive to Wikimedia Commons and is currently deployed at Toollabs.
Development and codebase moved to Wikimedia Gerrit. This repo is read only now. Read how to contribute on the Gerrit Tutorial. Thank you!
We use python 3.5.3
on production. Make sure you have this installed on
your machine, or use pyenv
as described later in this documentation under steps for local development.
The tool authenticates to the Wikimedia cluster using Wikimedia OAuth and to Google using Google OAuth. Hence, we need a couple of secret keys in your local_settings.py
to start development.
SOCIAL_AUTH_MEDIAWIKI_KEY
&SOCIAL_AUTH_MEDIAWIKI_SECRET
: You can request for an OAuth client using Wikimedia:OAuth. Once created, you will get both keys. Remember that you set the right Mediawiki OAuth callback URL.GOOGLE_APP_ID
: We need an application running on Google cloud to authorize and access Google drive. You can create your application at Google cloud console.GOOGLE_APP_ID
is your project id.GOOGLE_CLIENT_ID
: You can create a new OAuth 2.0 Client at Google cloud credentials.GOOGLE_API_DEV_KEY
: You need to enable the Google Picker API on Google cloud console. Once enabled, a dev key is generated, and you can find it on your Google cloud credentials.
For Wikimedia developers, you can find more information on development keys here
And also, the Google Drive to Wikimedia Commons Developer credentials are provided at the following link:
https://phabricator.wikimedia.org/P10014 .
Developers need not create new secret keys and can use the credentials given in the above link as instructed later in this documentation under steps for local development.
-
Create a local fork of https://github.com/tonythomas01/gdrive_to_commons using your GitHub account by running the following command in terminal:
$ git clone https://github.com/username/gdrive-to-commons.git
-
If homebrew is not installed before, install homebrew package manager by following the instructions given in the below link:
https://docs.brew.sh/Homebrew-on-Linux -
Install pyenv and virtual manager by running the following commands in terminal:
$ brew install pyenv $ brew install pyenv-virtualenv $ export PATH="$HOME/.pyenv/bin:$PATH" $ eval "$(pyenv init -)" $ eval "$(pyenv virtualenv-init -)" $ pyenv install 3.5.3 $ eval "$(pyenv init -)"
-
navigate into the repository by running the following command in terminal:
$ cd gdrive_to_commons
Now you are in the
gdrive_to_commons
directory and all the following commands are run in this directory. -
Create pyenv-virtualenv by running the following command in terminal:
gdrive_to_commons/$ pyenv virtualenv 3.5.3 gdrive-env-3.5.3
This will create a pyenv-virtualenv for you and probably place it on your
~/home/<username>/.pyenv/versions/
. -
Activate the virtual environment manually by running the following command:
gdrive_to_commons/$ source ~/.pyenv/versions/gdrive-env-3.5.3/bin/activate
or even better:
gdrive_to_commons/$ pyenv activate gdrive-env-3.5.3
or,
there are better ways to do this if you follow https://github.com/pyenv/pyenv-virtualenv.Now you are in the right environment if your terminal shows:
(gdrive-env-3.5.3) gdrive_to_commons/$
All the following commands are run in this environment and in this directory only.
-
Install dependencies by running the following command:
(gdrive-env-3.5.3) gdrive_to_commons/$ pip install -r requirements.txt
-
We use pre-commit hooks to format code. install precommit framework by running the following command:
(gdrive-env-3.5.3) gdrive_to_commons/$ pip install pre-commit
Now, install our pre-commit hooks using:(gdrive-env-3.5.3) gdrive_to_commons/$ pre-commit install
-
There are some
localsettings
you need to have as part of running the server. You can copy a template using:(gdrive-env-3.5.3) gdrive_to_commons/$ cp gdrive_to_commons/local_settings_sample.py gdrive_to_commons/local_settings.py
Few credentials have to be modified inlocal_setting.py
The credentials that are to be pasted in thelocal_settings.py
are given in the following link:
https://phabricator.wikimedia.org/P10014.
Paste the Google Drive to Wikimedia Commons Dev credentials inlocal_settings.py
-
Run the Django standard runserver steps:
(gdrive-env-3.5.3) gdrive_to_commons/$ python manage.py makemigrations
(gdrive-env-3.5.3) gdrive_to_commons/$ python manage.py migrate
(gdrive-env-3.5.3) gdrive_to_commons/$ python manage.py collectstatic
(gdrive-env-3.5.3) gdrive_to_commons/$ python manage.py runserver localhost:8000
or even better, run it from pyCharm using your debugger.
Note: Only paste the command after $ in terminal while setting up and do not paste the whole line which might cause error.