我可以将此GraphQL API请求转换为可以在Python中用作json的格式吗?

时间:2019-09-01 20:46:24

标签: python json formatting graphql

我是这个领域的菜鸟,需要一些帮助。

我使用Github v4 API进行了GraphQL查询,使用以下代码过滤搜索存储库。但是我对输出格式不满意。

query {
  search(
    type:REPOSITORY, 
    query: """
      stars:<1000
      forks:>10
      size:>2000
      pushed:>=2019-08-01
      created:>=2018-08-01

    """,
    last: 100
  ) {
    repos: edges {
      repo: node {
        ... on Repository {
          name
          description
          url
          owner{__typename}
          licenseInfo{name}
          watchers{watchers: totalCount}
          releases {releases: totalCount}
          forks: forkCount
          pullRequests {pullRequests: totalCount}
          stargazers {stars: totalCount}
          openIssues: issues(states:OPEN){totalCount}
          totalIssues: issues {totalIssues: totalCount}
          primaryLanguage {primaryLanguage: name}
          languages(first: 3) { nodes {name} }
          repositoryTopics(first: 3) {nodes {topic {name}}}
          createdAt
          pushedAt
          updatedAt

       }
      }
    }
  }
}

我想做的是将查询导入为.json,以便可以在Python中使用它。

我尝试了以下方法在python中使用,但是我在json格式方面苦苦挣扎

import requests

url = 'https://api.github.com/graphql'
json = {'query': '{stars:<1000} {forks:>10} {size:>2000 {pushed:>=2019-08-01} {created:>=2018-08-01}}'}
api_token = "abc.."
headers = {'Authorization': 'token %s' % api_token}

r = requests.post(url=url, json=json, headers=headers)
print (r.text)

0 个答案:

没有答案