-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelpers.py
41 lines (35 loc) · 1.61 KB
/
helpers.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
import json
def get_number_of(gdownloader, repo_api_address, statistic_type, parameter = None):
"""
Posts a request using an instance of GithubDownloader and returns the number of
a given statistic (e.g. number of issues, number of commits, etc.).
:param gdownloader: an instance of GithubDownloader.
:param statistic_type: the type for which the statistic is downloaded.
:param parameter: an optional parameter for the statistic (e.g. for issues set this to "state=all" to get all of them).
:returns: the value for the statistic as an absolute number.
"""
r = gdownloader.download_request(repo_api_address + "/" + statistic_type, ["per_page=100"] if parameter == None else ["per_page=100", parameter])
if "link" in r.headers:
address = r.headers["link"].split(',')[1].split('<')[1].split('>')[0]
data = gdownloader.download_object(address)
return 100 * (int(address.split('=')[-1]) - 1) + len(data) if data != None else None
else:
data = json.loads(r.text or r.content) if r.status_code != 204 else {}
return len(data)
def read_file_in_lines(filename):
"""
Reads a file into lines.
:param filename: the filename of the file to be read.
:returns: a list with the lines of the file.
"""
with open(filename) as infile:
lines = infile.readlines()
return [line.strip() for line in lines]
def print_usage():
"""
Prints the usage information of this python file.
"""
print("Usage: python gddownloader.py arg")
print("where arg can be one of the following:")
print(" github url (e.g. https://github.com/user/repo)")
print(" path to txt file containing github urls")