-
Notifications
You must be signed in to change notification settings - Fork 0
/
自动检查repos更新
46 lines (45 loc) · 1.32 KB
/
自动检查repos更新
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
# -*- coding: utf-8 -*-
import requests, time
url="https://api.github.com/repos/AleoHQ/snarkOS"
class Autocheck_repos():
def __init__(self,repos):
self.repos=repos
def get_newest(self):
try:
ret=requests.get(self.repos).json()
except Exception as e:
raise e
update=ret['updated_at']
# str="2022-12-13T01:11:16Z"
tmp=time.strptime(update, "%Y-%m-%dT%H:%M:%S%z")
update_time=time.mktime(tmp)
return str(update_time)
def op(self,new_version):
if new_version:
print("需要更新")
with open("./update.txt","w") as f:
f.write(new_version)
else:
print("已经是最新。。。。")
pass
def cmp_version(self,new_version):
with open("./update.txt", "r") as f:
tmp=f.readline().strip()
if tmp != new_version:
return new_version
else:
return 0
def op(self):
pass
#实现更新逻辑
def run(self):
newest=self.get_newest()
update=self.cmp_version(newest)
if update:
print("需要更新")
self.op()
else:
print("已经是最新版")
if __name__ == '__main__':
aleo=Autocheck_repos(url)
aleo.run()