forked from gil9red/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcycle_commit.py
More file actions
87 lines (61 loc) · 2.11 KB
/
Copy pathcycle_commit.py
File metadata and controls
87 lines (61 loc) · 2.11 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'ipetrash'
def wait(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0):
from datetime import timedelta, datetime
today = datetime.today()
timeout_date = today + timedelta(
days=days, seconds=seconds, microseconds=microseconds,
milliseconds=milliseconds, minutes=minutes, hours=hours, weeks=weeks
)
while today <= timeout_date:
def str_timedelta(td):
# Remove ms
td = str(td)
if '.' in td:
td = td[:td.index('.')]
return td
left = timeout_date - today
left = str_timedelta(left)
print('\r' * 100, end='')
print('До следующего запуска осталось {}'.format(left), end='')
import sys
sys.stdout.flush()
# Delay 1 seconds
import time
time.sleep(1)
today = datetime.today()
print('\r' * 100, end='')
print('\n')
if __name__ == '__main__':
from common import get_repo
repo = get_repo()
import os
new_file_name = os.path.join(repo.working_tree_dir, 'cycle_file')
while True:
try:
repo.remotes.origin.pull()
if not os.path.exists(new_file_name):
number = 0
print(number)
message = "Start cycle #{}".format(number)
else:
with open(new_file_name, 'r') as f:
number = int(f.read())
number += 1
print(number)
message = "Cycle commit #{}".format(number)
# Обновление значения
with open(new_file_name, 'w') as f:
f.write(str(number))
print(message)
repo.index.add([new_file_name])
repo.index.commit(message)
repo.remotes.origin.push()
print('Finish push')
# Every 1 hour
wait(hours=1)
except Exception as e:
print(e)
import time
time.sleep(30)