Exemplo n.º 1
0
class YandexDiskClass:
    def __init__(self):
        self.path_main = "TelegramCouponBOT"
        self.disk = YaDisk(config.DISK_LOGIN, config.DISK_PASSWORD_APP)
        elements = self.disk.ls("/")
        for element in elements:
            if element['isDir'] and element['displayname'] == self.path_main:
                return
        self.disk.mkdir(self.path_main)

    def get_user(self, userID):
        try:
            return self.disk.ls(f"{self.path_main}/{userID}")
        except:
            return None

    def mkdir_user(self, userID):
        try:
            self.disk.mkdir(f"{self.path_main}/{userID}")
        except:
            print(
                f"YandexDisk Error: <{userID}> Данный пользователь уже создан")

    def add_file(self, userID, file):
        if not self.get_user(userID):
            self.mkdir_user(userID)
        elements_path = file.split('/')
        file_name = elements_path[len(elements_path) - 1]
        self.disk.upload(file, f"/{self.path_main}/{userID}/{file_name}")
Exemplo n.º 2
0
 def upload_yandex_disk(self):
     disk = YaDisk(self.Ylogin, self.Ypassword)
     print('{0}video.mp4'.format(self.videofolder))
     disk.mkdir('Videos/{0}/{1}'.format(self.game, self.timestamp))
     disk.upload(
         '{0}video.mp4'.format(self.videofolder),
         'Videos/{0}/{1}/video.mp4'.format(self.game, self.timestamp))
     disk.upload(
         '{0}hashtags.txt'.format(self.videofolder),
         'Videos/{0}/{1}/hashtags.txt'.format(self.game, self.timestamp))
     disk.upload(
         '{0}link_to_original.txt'.format(self.videofolder),
         'Videos/{0}/{1}/link_to_original.txt'.format(
             self.game, self.timestamp))
     return
Exemplo n.º 3
0
while try_ != False and try_i <= 5:
	try:
		disk.ls( path_webdav_today )
		try_ = False
	except YaDiskException as e:
		if e.code == 404:
			dir_webdav = '/'
			for dir in path_webdav_today.split('/'):
				if dir:
					dir_webdav += dir +"/"
					try:
						dir_webdav_ls = disk.ls( dir_webdav )
					except YaDiskException as e:
						try:
							disk.mkdir( dir_webdav )
							try_ = False
						except YaDiskException as e:
							if e.code == 500:
								try_ = True
	try_i += 1
######### <<

######### >> Сохраняем БД и заливаем на ЯДиск
if backup_db:
	dbs = str( subprocess.Popen( "mysql -u"+ mysql_u +" -p'"+ mysql_p +"' -e'show databases;' | grep -v information_schema | grep -v Database", stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True, universal_newlines=True ).communicate()[0] )

	for db in dbs.split('\n'):
		if db and db != 'mysql' and db != 'performance_schema' and db != 'pma':
			if not db in exclude:
				db_file = date_today_str +"-www-"+ db +".sql.bz2"
Exemplo n.º 4
0
class YandexDiskClass:
    def __init__(self):
        self.path_main = "TelegramBOT"
        self.disk = YaDisk(config.DISK_LOGIN, config.DISK_PASSWORD_APP)
        elements = self.disk.ls("/")
        for element in elements:
            if element['isDir'] and element['displayname'] == self.path_main:
                return
        self.disk.mkdir(self.path_main)

    def get_departments(self):
        return self.disk.ls(self.path_main)

    def get_department(self, departmentName):
        try:
            return self.disk.ls(f"{self.path_main}/{departmentName}")
        except:
            return None

    def get_staffer(self, stafferID, departmentName):
        try:
            return self.disk.ls(
                f"{self.path_main}/{departmentName}/{stafferID}")
        except:
            return None

    def get_order_staffer(self, orderID, stafferID, departmentName):
        try:
            return self.disk.ls(
                f"{self.path_main}/{departmentName}/{stafferID}/{orderID}")
        except:
            return None

    def mkdir_department(self, departmentName):
        try:
            self.disk.mkdir(f"{self.path_main}/{departmentName}")
        except:
            print(
                f"YandexDisk Error: <{departmentName}> Данный отдел уже создан"
            )

    def mkdir_staffer(self, stafferID, departmentName):
        try:
            if self.get_department(departmentName):
                self.disk.mkdir(
                    f"{self.path_main}/{departmentName}/{stafferID}")
            else:
                print(
                    f"YandexDisk Error: <{departmentName}> Данный отдел не создан"
                )
        except:
            print(
                f"YandexDisk Error: <{stafferID}> Данный сотрудник уже добавлен в <{departmentName}>"
            )

    def mkdir_order(self, orderID, stafferID, departmentName):
        try:
            if self.get_staffer(stafferID, departmentName):
                self.disk.mkdir(
                    f"{self.path_main}/{departmentName}/{stafferID}/{orderID}")
            else:
                print(
                    f"YandexDisk Error: В <{departmentName}> этом отделе нет сотрудника <{stafferID}>"
                )
        except:
            print(
                f"YandexDisk Error: <{orderID}> Данный заказ уже добавлен сотруднику <{stafferID}> отдела <{departmentName}>"
            )

    def rename_department(self, departmentNameOld, departmentNameNew):
        try:
            self.disk.mkdir(f"/{self.path_main}/{departmentNameNew}/")
        except:
            print(
                f"YandexDisk Error: <{departmentNameNew}> Данный отдел уже создан"
            )
            return
        self.disk.cp(f"/{self.path_main}/{departmentNameOld}/",
                     f"/{self.path_main}/{departmentNameNew}/")
        time.sleep(2)
        self.disk.rm(f"{self.path_main}/{departmentNameOld}")

    def add_file(self, stafferID, departmentName, orderID, file):
        if not self.get_department(departmentName):
            self.mkdir_department(departmentName)
        if not self.get_staffer(stafferID, departmentName):
            self.mkdir_staffer(stafferID, departmentName)
        if not self.get_order_staffer(orderID, stafferID, departmentName):
            self.mkdir_order(orderID, stafferID, departmentName)
        elements_path = file.split('/')
        file_name = elements_path[len(elements_path) - 1]
        self.disk.upload(
            file,
            f"/{self.path_main}/{departmentName}/{stafferID}/{orderID}/{file_name}"
        )
Exemplo n.º 5
0
while try_ != False and try_i <= 5:
    try:
        disk.ls(path_webdav_today)
        try_ = False
    except YaDiskException as e:
        if e.code == 404:
            dir_webdav = '/'
            for dir in path_webdav_today.split('/'):
                if dir:
                    dir_webdav += dir + "/"
                    try:
                        dir_webdav_ls = disk.ls(dir_webdav)
                    except YaDiskException as e:
                        try:
                            disk.mkdir(dir_webdav)
                            try_ = False
                        except YaDiskException as e:
                            if e.code == 500:
                                try_ = True
    try_i += 1
######### <<

######### >> Сохраняем БД и заливаем на ЯДиск
if backup_db:
    dbs = str(
        subprocess.Popen(
            "mysql -u" + mysql_u + " -p'" + mysql_p +
            "' -e'show databases;' | grep -v information_schema | grep -v Database",
            stderr=subprocess.PIPE,
            stdout=subprocess.PIPE,