-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcloneGIT.py
42 lines (39 loc) · 1.32 KB
/
cloneGIT.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
from time import sleep
from github import Github
import time
from datetime import datetime
import os
from http.client import RemoteDisconnected
# 1.增加下面两行
import urllib3
from urllib3.exceptions import ProtocolError
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
urllib3.disable_warnings()
with open("token.txt", "r") as f:
access_token = f.read()
g = Github(access_token)
print(g.get_user())
end_time = time.time() - 86400000
start_time = end_time - 8640000
for i in range(5):
start_time_str = datetime.utcfromtimestamp(start_time).strftime("%Y-%m-%d")
end_time_str = datetime.utcfromtimestamp(end_time).strftime("%Y-%m-%d")
query = f"language:c++ created:{start_time_str}..{end_time_str}"
print(query)
result = g.search_repositories(query)
print(result.totalCount)
for repository in result:
print(f"{repository.clone_url}")
try:
os.system(f"git clone {repository.clone_url} "
f"G:/repos_qt/{repository.owner.login}/{repository.name}")
except ConnectionError:
print('ConnectionError')
except ProtocolError:
print('ProtocolError')
except RemoteDisconnected:
print('RemoteDisconnected')
except Exception:
print('Unexpected error')
sleep(1)