def random(self): youtube_ids = redis.srandmember("musicacommonset", 30) if not youtube_ids: return {"success": False} nonrecent = [] total = 0 for youtube_id in youtube_ids: youtube_id = youtube_id.decode() ltime = redis.get("musicatime.%s" % youtube_id) if ltime is None or time.time() - (float(ltime.decode()) or 0) >= 3600: for i in range( int( redis.get("musicacommon.%s" % youtube_id).decode()) or 1): nonrecent.append(youtube_id) if not youtube_ids: return {"success": False} youtube_id = query_search(random.choice(nonrecent), search=False) if youtube_id else None if not youtube_id: return {"success": False} youtube_id = youtube_id[0] redis.rpush( "musicaqueue", json.dumps({ "ytid": youtube_id, "uuid": str(uuid.uuid4()) })) redis.rpush("musicaload", youtube_id) redis.set("musicatime.%s" % youtube_id, time.time()) return {"success": True, "ytid": youtube_id}
def set_cards_participant(hash_position: str) -> None: """ Cria as cartelas do participante. Parameters: hash_position: número do usuário. """ while redis.scard(CARD + hash_position) < 15: redis.sadd(CARD + hash_position, redis.srandmember(CARDS))
def get_proxy_param(self, redis): headers = { "user-agent": self.ua.random } proxy = redis.srandmember('good_proxy', 1)[0] proxies = {"http": proxy} params = {"headers": headers, "verify": False, "proxies": proxies, "cookies": self.cookie} self.request_cnt += 1 if self.request_interval > 0: time.sleep(self.request_interval) return params
def dequeue_proxy_url(): url = redis.srandmember("proxy_urls") if url: url = url.decode() return url
def fetch_favors_in_range(self, member_id, quantity_per_page): redis_structure_name = Constant.FAVORS + member_id return redis.srandmember(redis_structure_name, quantity_per_page)