This repository was archived by the owner on Jan 11, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ import requests
2+ import datetime
3+ import time
4+ import getpass
5+ from functools import partial
6+
7+ end = "https://api.github.com/"
8+
9+
10+ def authorize (func ):
11+ """
12+ Authorize application
13+
14+ :param func:
15+ function to decorate for required authorization.
16+ """
17+
18+ username = input ('Enter GitHub Username: ' )
19+ password = getpass .getpass ()
20+ return partial (func , auth = (username , password ))
21+
22+
23+ @authorize
24+ def create_token (end , auth ):
25+ """
26+ Get the Personal access token or create one if not exists already.
27+
28+ :param end:
29+ End point of the API.
30+ :param auth:
31+ A tuple consisting of username and password
32+ """
33+
34+ params = {
35+ "scope" : ["gist" ],
36+ "note" : "gistey"
37+ }
38+
39+ rq = requests .post (end + "authorizations/" , params = params , auth = auth )
40+
41+ if "X-GitHub-OTP" in rq .headers :
42+ otp = input ("Enter 2FA code: " )
43+ rq = requests .put (end + "authorizations/" , params = params , auth = auth ,
44+ headers = {"X-GitHub-OTP" : otp })
45+
46+ return rq
47+ # TODO Returns 404 =/ Confusing
You can’t perform that action at this time.
0 commit comments