Untitled

 avatar
unknown
plain_text
2 years ago
1.8 kB
12
Indexable
import requests
import json


class Github:
    def __init__(self):
        self.api_url="https://api.github.com"
        self.token="YOUR GİTHUB KEY"

    def getUser(self,username):
        response=requests.get(self.api_url+"/users/"+username)
        return json.loads(response.text)

    def getRepositories(self,username):
        response = requests.get(self.api_url+'/users/'+username+'/repos')
        return json.loads(response.text)
        
        
    def crateRepository(self,name):
        page=input("Searcging Profile: ")
        response= requests.post(self.api_url+'/user/repos?access_token='+self.token,json={
            "name": name,
            "description": "This is your first reposityor",
            "homepage": "https://github.com/"+(f"{page}"),
            "private": False,
            "has_issues": True,
            "has_projects": True,
            "has_wiki": True
        }) 
        
        return json.loads(response.text)
        
github= Github()


while True:
    choice=input("1-Find User\n2- Get Repositories\n3- Create Repository\n4- Exit\nChoice: ")
    
    
    if choice=="4":
        break
    else:
        if choice=="1":
            username=input("Username: ")
            result=github.getUser(username)
            print(f"name: {result['name']} public repos: {result['public_repos']}, follower: {result['followers']}")
        elif choice=="2":
            username=input("Username: ")
            result=github.getRepositories(username)
            for repo in result:
                print(repo['name'])
        elif choice=="3":
            name=input("Repository name: ")
            result=github.crateRepository(name)
            print(result)
        else:
            print("Wrong choice")
Editor is loading...