83 lines
1.9 KiB
Python
Executable File
83 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import sys
|
|
from copy import deepcopy
|
|
from random import randint
|
|
from shutil import rmtree
|
|
from threading import Thread
|
|
from time import sleep
|
|
from datetime import datetime
|
|
|
|
import pystray
|
|
from PIL import Image, ImageTk
|
|
from requests import post
|
|
from websocket import WebSocket
|
|
|
|
from compare_json import compare_json
|
|
from config import get_config
|
|
from dir_to_json import get_json
|
|
from misc import check_network
|
|
|
|
|
|
class MunyalClient(pystray.Icon):
|
|
def __init__(self):
|
|
super(MunyalClient, self).__init__("Munyal")
|
|
self.icon = Image.open("img/icons/standby.png")
|
|
self.config = get_config()
|
|
self.stack = []
|
|
|
|
def is_online(self):
|
|
ping = check_network("http://google.com", 443)
|
|
if ping:
|
|
self.icon = Image.open("img/icons/online.png")
|
|
else:
|
|
self.icon = Image.open("img/icons/offline.png")
|
|
|
|
def start(self):
|
|
thread_uploader = Thread(target=self.uploader, name="uploader", daemon=True)
|
|
thread_downloader = Thread(target=self.downloader, name="downloader", daemon=True)
|
|
thread_uploader.start()
|
|
thread_downloader.start()
|
|
self.run(self.__run)
|
|
|
|
def __run(self, icon):
|
|
print("_run")
|
|
icon.visible = True
|
|
sleep(60)
|
|
self.stop()
|
|
|
|
def listener(self):
|
|
pass
|
|
|
|
def uploader(self):
|
|
print("Uploader")
|
|
while True:
|
|
sleep(5)
|
|
self.icon = Image.open("img/icons/online.png")
|
|
|
|
|
|
def __upload(self, path):
|
|
pass
|
|
|
|
def downloader(self):
|
|
print("Downloader")
|
|
while True:
|
|
sleep(7)
|
|
self.icon = Image.open("img/icons/offline.png")
|
|
|
|
def __download(self, path):
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
client = MunyalClient()
|
|
client.start()
|
|
sys.exit(0)
|
|
except BaseException:
|
|
sys.exit(1)
|