def selectAccount(self): """Returns an valid account name and data""" usable = [] for user, data in self.accounts.iteritems(): if not data['valid']: continue if "time" in data['options'] and data['options']['time']: time_data = "" try: time_data = data['options']['time'][0] start, end = time_data.split("-") if not compare_time(start.split(":"), end.split(":")): continue except Exception: self.logWarning( _("Your Time %s has wrong format, use: 1:22-3:44") % time_data) if user in self.infos: if "validuntil" in self.infos[user]: if self.infos[user]['validuntil'] > 0 and time.time( ) > self.infos[user]['validuntil']: continue if "trafficleft" in self.infos[user]: if self.infos[user]['trafficleft'] == 0: continue usable.append((user, data)) if not usable: return None, None return random.choice(usable)
def selectAccount(self): """ returns an valid account name and data""" usable = [] for user, data in self.accounts.iteritems(): if not data["valid"]: continue if "time" in data["options"] and data["options"]["time"]: time_data = "" try: time_data = data["options"]["time"][0] start, end = time_data.split("-") if not compare_time(start.split(":"), end.split(":")): continue except: self.logWarning(_("Your Time %s has wrong format, use: 1:22-3:44") % time_data) if user in self.infos: if "validuntil" in self.infos[user]: if self.infos[user]["validuntil"] > 0 and time() > self.infos[user]["validuntil"]: continue if "trafficleft" in self.infos[user]: if self.infos[user]["trafficleft"] == 0: continue usable.append((user, data)) if not usable: return None, None return choice(usable)
def isTimeReconnect(self): """Checks if pyload will try to make a reconnect :return: bool """ start = self.core.config['reconnect']['startTime'].split(":") end = self.core.config['reconnect']['endTime'].split(":") return compare_time(start, end) and self.core.config["reconnect"]["activated"]
def isTimeDownload(self): """Checks if pyload will start new downloads according to time in config. :return: bool """ start = self.core.config['downloadTime']['start'].split(":") end = self.core.config['downloadTime']['end'].split(":") return compare_time(start, end)
def select(self): """ Returns a valid account name and info """ free_accounts = {} premium_accounts = {} for user, info in self.info.items(): if not info['login']['valid']: continue data = info['data'] if "time" in data['options'] and data['options']['time']: time_data = "" try: time_data = data['options']['time'][0] start, end = time_data.split("-") if not compare_time(start.split(":"), end.split(":")): continue except Exception: self.log_warning(_("Wrong time format `%s` for account `%s`, use 1:22-3:44") % (user, time_data)) if data['trafficleft'] == 0: continue if time.time() > data['validuntil'] > 0: continue if data['premium']: premium_accounts[user] = info else: free_accounts[user] = info account_list = (premium_accounts or free_accounts).items() if not account_list: return None, None validuntil_list = [(user, info) for user, info in account_list if info['data']['validuntil']] if not validuntil_list: return random.choice(account_list) #@TODO: Random account?! Recheck in 0.4.10 return sorted(validuntil_list, key=lambda a: a[1]['data']['validuntil'], reverse=True)[0]
def isUsable(self): """Check several constraints to determine if account should be used""" if not self.valid or not self.activated: return False if self.options["time"]: time_data = "" try: time_data = self.options["time"] start, end = time_data.split("-") if not compare_time(start.split(":"), end.split(":")): return False except: self.logWarning(_("Your Time %s has a wrong format, use: 1:22-3:44") % time_data) if 0 <= self.validuntil < time(): return False if self.trafficleft is 0: # test explicitly for 0 return False return True
def isUsable(self): """Check several constraints to determine if account should be used""" if not self.valid or not self.activated: return False if self.options["time"]: time_data = "" try: time_data = self.options["time"] start, end = time_data.split("-") if not compare_time(start.split(":"), end.split(":")): return False except: self.logWarning( _("Your Time %s has a wrong format, use: 1:22-3:44") % time_data) if 0 <= self.validuntil < time(): return False if self.trafficleft is 0: # test explicitly for 0 return False return True