ulvis.paste.net

Paste Search Dynamic
Recent pastes
requests
  1. import requests
  2.  
  3. headers = {"Authorization": "token 378f16bbd3ec9216b3933ff61eda7adc62445360"}
  4.  
  5.  
  6. def run_query(query):
  7.     request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
  8.     if request.status_code == 200:
  9.         return request.json()
  10.     else:
  11.         raise exception("Query failed to run with code {}".format(request.status_code))
  12.  
  13.  
  14. def get_user_info(username):
  15.     query = """
  16.    {
  17.      user(login: "%s") {
  18.        name
  19.        login
  20.        email
  21.        url
  22.        repositories(first: 10) {
  23.          edges {
  24.            node {
  25.              nameWithOwner
  26.            }
  27.          }
  28.        }
  29.      }
  30.    }
  31.    """ % username
  32.     result = run_query(query)
  33.     return result['data']['user']
  34.  
  35.  
  36. def get_repo_info(user_repo_name):
  37.     username, repo_name = user_repo_name.split('/')
  38.     query = """
  39.    {
  40.      repository(owner: "%s", name: "%s"){
  41.        name,
  42.        description,
  43.        diskUsage,
  44.        url
  45.      }
  46.    }
  47.    """ % (username, repo_name)
  48.     result = run_query(query)
  49.     return result['data']['repository']
  50.  
  51.  
  52. def get_args(message):
  53.     return message.text.split()[1:]
  54.  
  55.  
  56. if __name__ == '__main__':
  57.     print(get_user_info('seytonic'))
  58.     print(get_repo_info("andrew4ever/treethon"))
Parsed in 0.013 seconds