VlibrasCheckVersion.py
2.23 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
# -*- coding: cp1252 -*-
import json, zipfile, subprocess,urllib
from os import popen
import sys
PATH_RESOURCE = 'c:/vlibras-libs/update/'
TXT_LOCAL_VERSION = PATH_RESOURCE+'version/version.txt'
JSON_LOCAL_NAME = PATH_RESOURCE+'version/version.json'
JSON_API_NAME = PATH_RESOURCE+'download/versionApi.json'
URL_REQUEST_API = 'http://150.165.205.94:8000/versionApi.json'
def check():
try:
with open(JSON_LOCAL_NAME) as data_file:
json_data = json.load(data_file)
my_dict_version_full = json_data['dictionaryVersion'].encode('utf-8')
my_player_version = json_data['playerVersion'].encode('utf-8').replace(".", "")
my_dict_version = my_dict_version_full.replace(".", "").replace("_", "")
if(not downladFileApi(URL_REQUEST_API)):
return 'erro'
with open(JSON_API_NAME) as data:
json_data = json.load(data)
api_dict_version = json_data['dictionaryVersion'].encode('utf-8').replace(".", "").replace("_", "")
api_player_version = json_data['playerVersion'].encode('utf-8').replace(".", "")
url_download_player = json_data['playerUrl'].encode('utf-8')
url_download_dict = json_data['dictionaryUrl'].encode('utf-8')
if int(api_player_version) > int(my_player_version):
return url_download_player
elif int(api_dict_version) > int(my_dict_version):
return url_download_dict
else:
return 'atualizado'
except Exception, e:
print e
return 'erro'
def downladFileApi(_url):
try:
urllib.urlretrieve (_url, JSON_API_NAME)
return True
except Exception, e:
print e
return False
if __name__ == '__main__':
txt_local_version = open(TXT_LOCAL_VERSION, 'w')
result = check()
if result.endswith('.exe'):
txt_local_version.write('1')
elif result.endswith('.zip'):
txt_local_version.write('2')
elif (result == 'atualizado'):
txt_local_version.write('0')
else:
txt_local_version.write('-1')
txt_local_version.close()
print result