-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (32 loc) · 1.16 KB
/
main.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
from git import Repo, Git, exc
import time
import shutil
import os
def auto_git():
try:
repo = Repo()
except exc.InvalidGitRepositoryError:
if git_password:
credentials = f'{git_username}:{git_password}@'
else:
credentials = ''
Repo.clone_from(url=f"https://{credentials}github.com/{git_username}/{git_repository}.git", to_path=f'{os.getcwd()}/{git_repository}', branch=branch)
file_names = os.listdir(f'{os.getcwd()}/{git_repository}')
for file_name in file_names:
if file_name == __file__.split('\\')[-1]:
pass
else:
shutil.move(os.path.join(f'{os.getcwd()}/{git_repository}', file_name), os.getcwd())
repo = Repo()
print('Intialization Complete')
while True:
repo.remotes.origin.fetch()
if sum(1 for _ in repo.iter_commits('main..origin/main')):
repo.remotes.origin.pull()
print('Pulled from repo')
time.sleep(1)
git_username = 'NovaProtocol'
git_password = "" # optional. Leave blank if repo is public else add token
git_repository = 'GitHub-auto-pull'
branch = 'main'
auto_git()