0

I am using PyGithub, GitHub.search_code(query) for searching swagger/openapi files with apache/mit license: (path:/swagger.yml OR path:/openapi.json) AND (apache OR mit license). It gives me 3.7k results in Github advanced search.

data_query = ["(path:/swagger.yml OR path:/openapi.json) AND (apache OR mit license)"]

def find_files_with_criteria(github_token, data_query, limit): # Initialize PyGitHub with your token auth = Auth.Token(github_token) g = Github(auth=auth)

files = []
count = 0
results = g.search_code(query=data_query)
iter_obj = iter(results)
while count < limit:
    try:
        content_file = next(iter_obj)
        files.append(content_file)
        count += 1
    except StopIteration:
        break #loop end
    except RateLimitExceededException:
        search_rate_limit = g.get_rate_limit().search
        logger.info('search remaining: {}'.format(search_rate_limit.remaining))
        reset_timestamp = calendar.timegm(search_rate_limit.reset.timetuple())
        # add 10 seconds to be sure the rate limit has been reset
        sleep_time = reset_timestamp - calendar.timegm(time.gmtime()) + 10
        time.sleep(sleep_time)
        continue

return files

I have:

GithubException: 422 {"message": "ERROR_TYPE_QUERY_PARSING_FATAL unable to parse query!", "documentation_url": "https://docs.github.com/rest/search/search#search-code"}

Could you help me writing proper query?

I can have two queries: ["path:swagger extension:yml", "path:openapi extension:json"] but I would like to have yml and json combined with specific licences. Thank you for every help.

0 Answers0