-
Notifications
You must be signed in to change notification settings - Fork 1
/
github_search.py
54 lines (30 loc) · 1.47 KB
/
github_search.py
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
from github_response_parser import GithubResponseParser
from request_process import RequestProcess
from sleep import Sleep
API = 'https://api.github.com/search/code?o=desc&q='
SEARCH_QUERY = 'org%3A{}+{}+NOT+filename:CHANGELOG.md+NOT+filename:Changelog+NOT+filename:CHANGES.md+NOT+filename:COMMITTERS.md+NOT+filename:CONTRIBUTORS.md+NOT+filename:contributors.rst&type=Code'
class GithubSearch:
def __init__(self, user, query):
self.url = self.format_url(user, query)
self.sleep = Sleep()
def format_url(self, user, query):
searchQuery = SEARCH_QUERY.format(user, query)
return f'{API}{searchQuery}'
def get_url(self):
return self.url
def result_total_pages(self):
request_process = RequestProcess(self.url)
response = request_process.get()
github_response_parser = GithubResponseParser(response)
return github_response_parser.get_search_pages_count()
def page_result(self, page_number):
url = f'{self.url}&page={page_number}'
request_process = RequestProcess(url)
response = request_process.get()
github_response_parser = GithubResponseParser(response)
return github_response_parser.get_search_results()
def page_content_result(self):
request_process = RequestProcess(self.url)
response = request_process.get()
github_response_parser = GithubResponseParser(response)
return github_response_parser.get_page_content()