data.webtools.get_token¶
Function ยท Source
token = mdnc.data.webtools.get_token(
token='', silent=True
)
Automatically get the Github OAuth token, if the argument token
is missing.
This function would try to get the token in the following orders:
- Try to find the value of the environmental variable
GITTOKEN
. - If not found, try to find the value of the environmental variable
GITHUB_API_TOKEN
. - If not found, and
silent is False
, would ask users to input the token. Whensilent is True
, would return''
.
Tip
The token could be formatted like the following two forms:
GITTOKEN=myusername:b05bpgw2dcn5okqpeltlz858eoi6x6j3wrrjhhhc
GITTOKEN=b05bpgw2dcn5okqpeltlz858eoi6x6j3wrrjhhhc
Another tip is that, you could skip entering the user name and password if you clone a private repository like this:
git clone https://myusername:b05bpgw2dcn5okqpeltlz858eoi6x6j3wrrjhhhc@github.com/myusername/myreponame.git myrepo
A repository cloned by this way does not require the user name and password for pull
and push
.
Arguments¶
Requries
Argument | Type | Description |
---|---|---|
token | str | The given OAuth token. Only when this argument is unset, the program will try to find a token from enviornmental variables. |
silent | bool | A flag. If set True and the token could not be found anywhere, this tool would not ask for a token, but just return '' . |
Returns
Argument | Description |
---|---|
token | A str . This is the detected OAuth token. |
Examples¶
Example
Run bash
,
1 |
|
Then, run python
,
1 2 3 4 |
|
xxxxxxxxxxxxxx
Last update: March 14, 2021