dump-github 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dump_github/__init__.py +2 -0
- dump_github/lib.py +31 -0
- dump_github/main.py +53 -0
- dump_github/mylib.py +31 -0
- dump_github-0.1.0.dist-info/LICENSE +21 -0
- dump_github-0.1.0.dist-info/METADATA +41 -0
- dump_github-0.1.0.dist-info/RECORD +10 -0
- dump_github-0.1.0.dist-info/WHEEL +5 -0
- dump_github-0.1.0.dist-info/entry_points.txt +3 -0
- dump_github-0.1.0.dist-info/top_level.txt +1 -0
dump_github/__init__.py
ADDED
dump_github/lib.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_page_of_repos(username, page, token=""):
|
|
5
|
+
url = "https://api.github.com/users/{}/repos?per_page=200&page={}".format(
|
|
6
|
+
username, page
|
|
7
|
+
)
|
|
8
|
+
headers = {"Authorization": token}
|
|
9
|
+
if token != "":
|
|
10
|
+
response = requests.get(url, headers=headers)
|
|
11
|
+
else:
|
|
12
|
+
response = requests.get(url)
|
|
13
|
+
if response.status_code == 200:
|
|
14
|
+
repos = response.json()
|
|
15
|
+
return repos
|
|
16
|
+
else:
|
|
17
|
+
raise []
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def serach_user_repos(username, token=""):
|
|
21
|
+
page = 0
|
|
22
|
+
res_repos = []
|
|
23
|
+
|
|
24
|
+
while True:
|
|
25
|
+
page += 1
|
|
26
|
+
repos = get_page_of_repos(username, page, token)
|
|
27
|
+
if len(repos) == 0:
|
|
28
|
+
break
|
|
29
|
+
res_repos += repos
|
|
30
|
+
|
|
31
|
+
return res_repos
|
dump_github/main.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
from .lib import *
|
|
4
|
+
|
|
5
|
+
# Config_MaxSize = 1_000
|
|
6
|
+
|
|
7
|
+
parser = argparse.ArgumentParser(
|
|
8
|
+
prog="dump_github",
|
|
9
|
+
description="Backup users github repo.",
|
|
10
|
+
epilog="https://github.com/Core2002/dump_github",
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
parser.add_argument("username")
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
"-d", "--download_zip", action="store_true", help="only download zip file"
|
|
16
|
+
)
|
|
17
|
+
parser.add_argument("-p", "--print", action="store_true", help="only print urls")
|
|
18
|
+
parser.add_argument("-t", "--token", action="store", default="", help="github token")
|
|
19
|
+
|
|
20
|
+
args = parser.parse_args()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def clone_repo(repo):
|
|
24
|
+
name = repo["name"]
|
|
25
|
+
url = repo["clone_url"]
|
|
26
|
+
size = repo["size"]
|
|
27
|
+
# if int(size) > Config_MaxSize:
|
|
28
|
+
# print(f"Keep repo [{name}], Becues size is too Big ({int(size)}).")
|
|
29
|
+
# return
|
|
30
|
+
print("Clone repo: {}".format(name))
|
|
31
|
+
os.system("git clone {}".format(url))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def download_zip(user_name, reop_name):
|
|
35
|
+
url = f"https://github.com/{user_name}/{reop_name}/archive/refs/heads/main.zip"
|
|
36
|
+
print("Downloading repo zip: {}".format(reop_name))
|
|
37
|
+
os.system("wget {} -O ./{}_{}.zip".format(url, user_name, reop_name))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def main():
|
|
41
|
+
# print(args)
|
|
42
|
+
repos = serach_user_repos(args.username, args.token)
|
|
43
|
+
for repo in repos:
|
|
44
|
+
if args.print == True:
|
|
45
|
+
print(repo["clone_url"])
|
|
46
|
+
elif args.download_zip == True:
|
|
47
|
+
download_zip(user_name, repo["name"])
|
|
48
|
+
else:
|
|
49
|
+
clone_repo(repo)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
main()
|
dump_github/mylib.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_page_of_repos(username, page, token=""):
|
|
5
|
+
url = "https://api.github.com/users/{}/repos?per_page=200&page={}".format(
|
|
6
|
+
username, page
|
|
7
|
+
)
|
|
8
|
+
headers = {"Authorization": token}
|
|
9
|
+
if token != "":
|
|
10
|
+
response = requests.get(url, headers=headers)
|
|
11
|
+
else:
|
|
12
|
+
response = requests.get(url)
|
|
13
|
+
if response.status_code == 200:
|
|
14
|
+
repos = response.json()
|
|
15
|
+
return repos
|
|
16
|
+
else:
|
|
17
|
+
raise []
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def serach_user_repos(username, token=""):
|
|
21
|
+
page = 0
|
|
22
|
+
res_repos = []
|
|
23
|
+
|
|
24
|
+
while True:
|
|
25
|
+
page += 1
|
|
26
|
+
repos = get_page_of_repos(username, page, token)
|
|
27
|
+
if len(repos) == 0:
|
|
28
|
+
break
|
|
29
|
+
res_repos += repos
|
|
30
|
+
|
|
31
|
+
return res_repos
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Core2002
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dump-github
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A small example package
|
|
5
|
+
Home-page: https://github.com/core2002/dump_github
|
|
6
|
+
Author: core2002
|
|
7
|
+
Author-email: core2002@aliyun.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: argparse
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
|
|
18
|
+
### Github Dumper
|
|
19
|
+
|
|
20
|
+
Github Dumper is a Python program designed to search for users' GitHub repositories and download the repositories. This tool can be used to back up users' GitHub repositories in case they need them later.
|
|
21
|
+
|
|
22
|
+
**Usage:**
|
|
23
|
+
```
|
|
24
|
+
usage: dump_github [-h] [-d] [-p] [-t TOKEN] username
|
|
25
|
+
|
|
26
|
+
Backup users github repo.
|
|
27
|
+
|
|
28
|
+
positional arguments:
|
|
29
|
+
username
|
|
30
|
+
|
|
31
|
+
options:
|
|
32
|
+
-h, --help show this help message and exit
|
|
33
|
+
-d, --download_zip only download zip file
|
|
34
|
+
-p, --print only print urls
|
|
35
|
+
-t TOKEN, --token TOKEN
|
|
36
|
+
github token
|
|
37
|
+
|
|
38
|
+
https://github.com/Core2002/dump_github
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
dump_github/__init__.py,sha256=3XLRrchVn7g3TYWiQpv3u2lKdTO-jDqg4_0-lpmRuRs,43
|
|
2
|
+
dump_github/lib.py,sha256=pHONzAjGbXkmAUvCGn8HkHWS7fyY2qu9R17to6jD1TU,715
|
|
3
|
+
dump_github/main.py,sha256=tZ3yPdcljCobzIGk2_Exwnb2ao-1JPAflwTVe--BnZg,1486
|
|
4
|
+
dump_github/mylib.py,sha256=pHONzAjGbXkmAUvCGn8HkHWS7fyY2qu9R17to6jD1TU,715
|
|
5
|
+
dump_github-0.1.0.dist-info/LICENSE,sha256=5tQa-lQLqvLhjTuELEk4bm70I5hcdjUeOn4qf3MK84E,1064
|
|
6
|
+
dump_github-0.1.0.dist-info/METADATA,sha256=SXU_x_Zs2ZMxAU8DDMuAsPL2vGVHIc869LUXe-kTvmY,1096
|
|
7
|
+
dump_github-0.1.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
8
|
+
dump_github-0.1.0.dist-info/entry_points.txt,sha256=bHSMsd4MLHu5N-1Vomjq7P_VLmFWN5VabwMVyJEJurA,50
|
|
9
|
+
dump_github-0.1.0.dist-info/top_level.txt,sha256=6oWfdkP2U1AN9zL6AUIUTxe6hYIeo_Nf8M8SWBxElUw,12
|
|
10
|
+
dump_github-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dump_github
|