55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from threading import Thread
 | |
| from macros import *
 | |
| from config import *
 | |
| from time import sleep
 | |
| import urllib, os, requests
 | |
| 
 | |
| class UThread(Thread):
 | |
| 	path = os.path.dirname(__file__)
 | |
| 
 | |
| 	def __init__(self):
 | |
| 		super(UThread, self).__init__()
 | |
| 
 | |
| 
 | |
| 	def run(self):
 | |
| 		global VERSION
 | |
| 
 | |
| 		try:
 | |
| 			SUCC('Updater started!')
 | |
| 			while 1:
 | |
| 				if not CONF.get('updates'):
 | |
| 					sleep(1)
 | |
| 					continue
 | |
| 
 | |
| 				version = requests.get('https://mirror.bitheaven.ru/main/versions/Bit.ASICmon-a').text
 | |
| 
 | |
| 				if version == VERSION:
 | |
| 					sleep(300)
 | |
| 					continue
 | |
| 
 | |
| 				INFO('Update found! Downloading...')
 | |
| 				if LINUX:
 | |
| 					with urllib.request.urlopen("https://mirror.bitheaven.ru/main/archive/Bit.ASICmon-a_linux") as upd:
 | |
| 						with open(self.path, "wb+") as f:
 | |
| 							INFO('Installing update...')
 | |
| 							f.write(upd.read())
 | |
| 							INFO('Stopping process...')
 | |
| 							break
 | |
| 				elif MACOS:
 | |
| 					with urllib.request.urlopen("https://mirror.bitheaven.ru/main/archive/Bit.ASICmon-a_macos") as upd:
 | |
| 						with open(self.path, "wb+") as f:
 | |
| 							INFO('Installing update...')
 | |
| 							f.write(upd.read())
 | |
| 							INFO('Stopping process...')
 | |
| 							break
 | |
| 				elif MUSTDIE:
 | |
| 					with urllib.request.urlopen("https://mirror.bitheaven.ru/main/archive/Bit.ASICmon-a_mustdie.exe") as upd:
 | |
| 						with open(self.path, "wb+") as f:
 | |
| 							INFO('Installing update...')
 | |
| 							f.write(upd.read())
 | |
| 							INFO('Stopping process...')
 | |
| 							break
 | |
| 		except Exception as e:
 | |
| 			CRIT(str(e))
 | |
| 			os._exit(1)
 |