-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequests_github_demo.py
More file actions
61 lines (60 loc) · 2.31 KB
/
Copy pathrequests_github_demo.py
File metadata and controls
61 lines (60 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
#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
class Github:
def __init__(self):
self.api_url = "https://api.github.com"
def getUser(self, username):
response = requests.get(self.api_url+'/users/'+username)
return response.json()
def getRepository(self,username):
response = requests.get(self.api_url+'/users/'+username+'/repos')
return response.json()
def createRepository(self,token,name):
response = requests.post(self.api_url+'/users/repos?access_token='+token,json = {
"name": name,
'description': 'This is my test repository.',
'homepage': 'https://github.com/josephnade',
'private': False,
'has_issues': True,
'has_project': True,
'has_wiki':True
})
return response.json()
github = Github()
def getRepo(username):
result = github.getRepository(username)
c = 1
for i in result:
print(f"{c}. Repository = {i['name']}")
c+=1
while True:
choose = input("[1]Find User\n[2]Get Repositories\n[3]Create Repository\n[4]Exit\nChoose [1-4] number=")
if choose == "4":
break
else:
if choose == "1":
#Find User
username = input("Please enter username you are looking for= ")
result = github.getUser(username)
print(f"User ID = {result['id']}\nNumber of Repository = {result['public_repos']}\nFollowers = {result['followers']}\nFollowing = {result['following']}")
elif choose == "2":
#Get Repositories
username = ""
if len(username) == 0:
print("Please enter your username first!")
username = input("Please enter username you are looking for= ")
getRepo(username)
else:
getRepo(username)
elif choose == "3":
#Create Repository
try:
name = input("Please enter a repository name: ")
token = input("Please enter the token: ")
result = github.createRepository(token,name)
print(result)
except Exception as e:
print("Wrong token")
pass
else:
print("Wrong choose")