def _all_(m): if m.chat.type == "group" or m.chat.type == "supergroup": uid = m.from_user.id cid = m.chat.id uname = m.from_user.first_name or "ادمین" status = redis.get(key + str(cid) + ":status") or "off" if bot.get_chat_member(cid, uid).status == "member": if status == "on": if redis.sismember(key + str(cid) + ":allow_list", uid) == False: bot.delete_message(cid, m.message_id) max_add = redis.get(key + str(cid) + ":max_add") or 3 if redis.sismember(key + str(cid) + ":warn_list", uid) == False: text = """کاربر [{}](tg://user?id={}): برای چت کردن در این گروه باید 3 نفر را به گروه دعوت کنید!""".format( uname, uid, max_add) bot.send_message(cid, text, parse_mode="Markdown") redis.sadd(key + str(cid) + ":warn_list", uid) else: if m.text == "/panel": bot.delete_message(cid, m.message_id) text = "[{}](tg://user?id={}):\nبا دکمه های زیر حد اکثر تعداد دعوت ممبر ها را تایین کنید🎈😁".format( uname, uid) bot.send_message(cid, text, parse_mode="Markdown", reply_markup=panel(cid))
def is_mod(chat_id, user_id): var = False if bot.get_chat_member(chat_id, user_id).status in [ "creator", "administrator" ] or redis.sismember('promotes' + str(chat_id), user_id) and redis.sismember('groups', chat_id): var = True return var
def process_links(project, url, spider): if redis.sismember("seen", json.dumps([project, url, spider])): print "Skipping %s; it has already been processed (For %s)" % (url.encode("utf-8"), project.encode("utf-8")) else: print "Processing %s for urls (For %s)" % (url.encode("utf-8"), project.encode("utf-8")) resp = session.get(url, timeout=15) resp.raise_for_status() html = lxml.html.document_fromstring(resp.content) if spider: for link in itertools.chain(html.find_rel_links("download"), html.find_rel_links("homepage")): try: link.make_links_absolute(url) except ValueError: continue if "href" in link.attrib and not installable(project, link.attrib["href"]): parsed = urlparse.urlparse(link.attrib["href"]) if parsed.scheme.lower() in ["http", "https"]: redis.rpush("queue", json.dumps([project, link.attrib["href"], False])) # Process all links in html for installable items for link in html.xpath("//a"): try: link.make_links_absolute(url) except ValueError: continue if "href" in link.attrib and installable(project, link.attrib["href"]): redis.rpush("results", json.dumps([project, url, link.attrib["href"]])) redis.sadd("seen", json.dumps([project, url, spider]))
def game() -> None: """ Método correspondente ao funcionamento do jogo. Ele gerá os participantes e sorteia as cartelas (80) para o jogo. A cada sorteio, a cartela será listada. Quando algum participante atingir 15 pontos, o método listará o parcipante e será finalizado. Se não houver vencedores, será listado. """ generate_cards(CARDS) generate_participants() print('Start of the game!!') numbers = redis.spop(CARDS, 80) for index, number in enumerate(numbers): number = int(number) print(f'Round {index+1}: {number}') round_winners = '' for i in range(1, 51): i = str(i) if redis.sismember(CARD + i, number): redis.zincrby(SCORES, 1, SCORE + i) round_winners += f'player {i} - score {redis.zscore("scores", SCORE + i)} | ' print('Round winners: ' + round_winners) winners = redis.zrangebyscore(SCORES, 15, 15) if winners: winners = [re.sub(r'\D', '', str(s)) for s in winners] print('Winning participant(s): ' + str(winners)) print('End of the game') return print('No winner...')
def callback_inline(call) : mn = redis.sismember("bans", call.from_user.id) if mn == False: if call.data == "pars": markup = types.InlineKeyboardMarkup() a = types.InlineKeyboardButton("⚜ سازنده ⚜", callback_data='help') markup.add(a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="سلام👋🏻\n🔅به ربات FaceApp خوش امدید.\n➖➖➖➖➖➖➖➖\n⛑برای استفاده از این ربات تنها کافی است عکس مورد نظر خود را برای تغییر چهره ی ان ارسال نمایید.\n⚠️توجه : عکس باید تک نفره و از یک چهره ی کاملا واضح باشد.", reply_markup=markup) elif call.data == "eng": markup = types.InlineKeyboardMarkup() a = types.InlineKeyboardButton("⚜ Creator ⚜", callback_data='help') markup.add(a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Hi👋🏻\n🔅Welcome to FaceApp bot.\n➖➖➖➖➖➖➖➖\n⛑For use this robot you just need to send your picture for face changing.\n⚠️Note : Picture must be a single picture and have a bright face.", reply_markup=markup) elif call.data == "help": bot.send_message(call.message.chat.id, "💟 cafe_girls1 💟\n➖➖➖➖➖➖➖➖\n🔹 admin : @mmdhiddenn\n😻 Channel : @cafe_girls1") else : s = bot.get_chat_member(channel, call.message.chat.id) if s.status == "member" or s.status == "creator" or s.status == "administrator": try : code = call.data ff = TemporaryFile() ff.write(requests.get("http://dev.magic-team.ir/faceapp/download/?hash="+code).content) ff.seek(0) bot.send_photo(call.message.chat.id,ff,reply_to_message_id=call.message.message_id) ff.close() except Exception as e: print(e)
def start(m): s = bot.get_chat_member(channel, m.chat.id) mn = redis.sismember("bans", m.from_user.id) if mn == False: if s.status == "member" or s.status == "creator" or s.status == "administrator": markup = types.InlineKeyboardMarkup() a = types.InlineKeyboardButton("🇮🇷فارسی🇮🇷", callback_data='pars') b = types.InlineKeyboardButton("🇬🇧English🇬🇧", callback_data='eng') markup.add(a, b) bot.send_message( m.chat.id, "🇮🇷لطفا زبان خود با انتخاب کنید :\n➖➖➖➖➖➖➖➖\n🇬🇧Please select your language :", reply_markup=markup) else: markup = types.InlineKeyboardMarkup() start4 = types.InlineKeyboardButton( "👈 عضویت در کانال 👉", url="https://telegram.me/joinchat/AAAAAEC-CTpnz_0J0dplCg") markup.add(start4) bot.send_message( m.chat.id, "⚠️ کاربر عزیز جهت استفاده از این ربات ابتدا باید در کانال ما عضو شوید.\n\n🔅 برای عضویت در کانال بر روی لینک زیر کلیک کنید و دکمه join را بزنید👇\n<a href='https://telegram.me/joinchat/AAAAAEC-CTpnz_0J0dplCg'>@tgMember</a>\n<a href='https://telegram.me/joinchat/AAAAAEC-CTpnz_0J0dplCg'>@tgMember</a>\n\nپس از عضویت در کانال بر روی 👈 /start کلیک کنید تا ربات فعال شود!", parse_mode="HTML", reply_markup=markup) redis.sadd('mbrs_bot', '{}'.format(m.from_user.id))
def is_cr(chat_id, user_id): var = False if bot.get_chat_member(chat_id, user_id).status in ["creator" ] and redis.sismember( 'groups', chat_id): var = True return var
def check_pm(m): if m.chat.type == 'supergroup': redis.sadd(m.content_type, m.message_id) if redis.sismember('groups', m.chat.id): if not redis.get('expire' + str(m.chat.id)): bot.reply_to(m, '🔴 اعتبار گروه به پایان رسیده است 🔴') redis.srem('groups', m.chat.id) bot.leave_chat(m.chat.id) else: check(m) if m.chat.type == 'private': if m.reply_to_message.forward_from: if is_sudo(m.from_user.id): id = m.reply_to_message.forward_from.id if m.text == 'مسدود': redis.set('ban' + str(id), True) bot.reply_to( m, 'این کاربر دیگر قادر به استفاده از پیوی ربات نیست ❌') elif m.text: bot.send_message(id, m.text) bot.reply_to(m, 'رفت براش') elif m.sticker: bot.send_sticker(id, m.sticker.file_id) bot.reply_to(m, 'رفت براش') elif m.photo: bot.send_photo(id, m.photo[-1].file_id) bot.reply_to(m, 'رفت براش')
def doWelfareById(redis, uid, account, id): """ 福利 """ today = datetime.now().strftime("%Y-%m-%d") if id == '2': playerCoin = redis.hget(FORMAT_USER_TABLE % uid, 'gold') playerCoin = playerCoin if playerCoin else 0 if int(playerCoin) >= SIGN_LINE: return {'code': 1, 'msg': u'未达到低保线无法领取'} key = WELFARE_USER_INSURANCE % (account, today) if redis.llen(key) >= SIGN_MAX: return {'code': 1, 'msg': u'已经领取了 {0} 次'.format(SIGN_MAX)} redis.lpush(key, SIGN_COINNUM) player_add_gold(redis, account, SIGN_COINNUM) elif id == '1': # 新手礼包 if redis.hget(GOLD_REWARD_NEW_PRESENT_HASH, account) == MESSION_STATUS_OVER: return {'code': 1, 'msg': u'您已领取,无法再次领取'} redis.hset(GOLD_REWARD_NEW_PRESENT_HASH, account, MESSION_STATUS_OVER) elif id == '0': # 每日首冲奖励 if not redis.sismember(DAILY_USER_GOLD2_SET % today, account): return {'code': 1, 'msg': u'您今日还未完成首冲'} elif redis.hget(GOLD_REWARD_DAY_BUY_GOLD_HASH % today, account) == MESSION_STATUS_OVER: return {'code': 1, 'msg': u'您已领取,无法再次领取'} redis.hget(GOLD_REWARD_DAY_BUY_GOLD_HASH % today, account, MESSION_STATUS_OVER) return {'code': 0, 'msg': u'领取成功'}
def article_switch_vote(redis, user, from_article, to_article): to_article_id = to_article.split(':')[-1] from_article_id = from_article.split(':')[-1] if redis.sismember( 'voted:' + from_article_id, user) and redis.sismember('voted:' + to_article_id, user) is False: if redis.smove('voted:' + from_article_id, 'voted:' + to_article_id, user): redis.zincrby(name='score:', value=to_article, amount=VOTE_SCORE) redis.hincrby(name=to_article, key='votes', amount=1) redis.zincrby(name='score:', value=from_article, amount=-VOTE_SCORE) redis.hincrby(name=from_article, key='votes', amount=-1)
def personal(msg): try: if msg.from_user.id == naji and msg.text: if re.match("/fwd", msg.text) and msg.reply_to_message: for i in redis.smembers("bot:all", msg.chat.id): try: bot.forward_message(i, msg.chat.id, msg.reply_to_message.id) except Exception as e: print(e) if re.match("/stats", msg.text): bot.send_message( msg.chat.id, "آمار\nگروه ها : {}\nخصوصی ها : {}".format( redis.scard("bot:gps"), redis.scard("bot:pvs"))) else: bot.send_message( msg.chat.id, "رباتی برای افزایش اعضای گروه\nفقط کافیه به گروهت دعوتش کنی و ادمینش کنی" ) if not redis.sismember("bot:all", msg.chat.id): redis.sadd("bot:pvs", msg.chat.id) redis.sadd("bot:all", msg.chat.id) except Exception as e: print(e) pass
def doPatchSign(redis, account, date): """ 补签接口 补签需要消耗2张房卡 """ user_info = get_user_info(redis, account) uid = user_info['uid'] agentid = user_info['parentAg'] roomcard = redis.get(USER4AGENT_CARD % (agentid, uid)) roomcard = int(roomcard) if roomcard else 0 if roomcard < PATCH_SIGN_FEE: return {'code': 1, 'msg': "钻石不足"} month = datetime.strptime(date, '%Y-%m-%d').month key = WELFARE_USER_PATCH_SIGN % (account, month) if redis.sismember(key, date): return {'code': 1, 'msg': "已补签过"} times = redis.scard(key) # 每月补签次数是否达到上限 if times and int(times) > PATCH_SIGN_MAX: return {'code': 1, 'msg': "当月补签已达上限"} redis.sadd(key, date) return {'code': 0, 'msg': "补签成功"}
def saveBuyGoldRecord(redis, account, data): """ 保存金币流水 """ try: if not redis.sismember(GOLD_ACCOUNT_SET_TOTAL, account): redis.sadd(GOLD_ACCOUNT_SET_TOTAL, account) prredis = getPrivateRedisInst(redis, MASTER_GAMEID) num = prredis.incr(GOLD_BUY_RECORD_COUNT_TABLE) record_key = GOLD_BUY_RECORD_TABLE % num pipe = prredis.pipeline() data['account'] = account pipe.hmset(record_key, data) pipe.expire(record_key, GOLD_ROOM_MAX_TIME) pipe.lpush(GOLD_BUY_RECORD_ACCOUNT_LIST % account, record_key) pipe.lpush(GOLD_BUY_RECORD_LIST_TOTAL, record_key) pipe.incr(GOLD_BUY_RECORD_ACCOUNT_GOLD_SUM % account, data['gold']) pipe.incr(GOLD_BUY_RECORD_ACCOUNT_MOENY_SUM % account, data['money']) pipe.execute() user_info = get_user_info(redis, account) if not user_info: return agentid = user_info['parentAg'] gold = user_info['gold'] prredis.zadd(GOLD_MONEY_RANK_WITH_AGENT_ZSET % agentid, account, gold) except Exception, ex: traceback.print_exc()
def parse_result(resp): for insta in resp['data']: if redis.sismember("insta", insta.id): print("Mr T says: No new fun for you!") break else: print("We found ourselfs new data from", insta.user.username) point = 0 for potential_point in insta.tags: p = potential_point.name.lower() if p == "1hp": point = 1 elif p == "2hp": point = 2 elif p == "5hp": point = 5 elif p == "10hp": point = 10 elif p == "25hp": point = 25 elif p == "50hp": point = 50 if point > 0: user = insta.user.username userdata = {"name":insta.user.username,"fullname":insta.user.full_name, "pic": insta.user.profile_picture, "src":"insta"} print("Adding new score by", userdata) redis.sadd(user, json.dumps(userdata)) redis.zincrby("leaderboard", user, point) redis.sadd("insta", insta.id)
def find(cls, experiment_name, redis=None): if not redis.sismember(_key("e"), experiment_name): raise ValueError('experiment does not exist') return cls(experiment_name, Experiment.load_alternatives(experiment_name, redis), redis=redis)
def get_next_callee(): index = redis.incr(CALLEE_COUNTER_KEY) - 1 callee = CALLEES[index] if redis.sismember(CALLED_NUMBERS_SET_KEY, callee['phone']): store_event('skipped_repeat_number', callee) return get_next_callee() else: redis.sadd(CALLED_NUMBERS_SET_KEY, callee['phone']) return index, callee
def __setitem__(self, id, data): redis = self.redis if not redis.sismember(self.key, id): raise KeyError(id) now = str(time.time()) pipe = redis.pipeline() pipe.set(id, data) pipe.set('%s.mtime' % id, now) pipe.set(self.mtime_key, now) pipe.execute()
def check_pm(m): if m.chat.type == 'supergroup': redis.sadd(m.content_type, m.message_id) if redis.sismember('groups', m.chat.id): if not redis.get('expire' + str(m.chat.id)): bot.reply_to(m, '🔴 اعتبار گروه به پایان رسیده است 🔴') redis.srem('groups', m.chat.id) bot.leave_chat(m.chat.id) else: check(m)
def article_switch_vote(redis, user, from_article, to_article): # HOMEWORK 2 Part I # check member exist from_article_id = from_article.split(':')[-1] to_article_id = to_article.split(':')[-1] if redis.sismember('voted:' + from_article_id, user): # move member redis.smove('voted:' + from_article_id, 'voted:' + to_article_id, user) redis.zincrby(name='score:', value=from_article, amount=-VOTE_SCORE) redis.hincrby(name=from_article, key='votes', amount=-1) redis.zincrby(name='score:', value=to_article, amount=VOTE_SCORE) redis.hincrby(name=to_article, key='votes', amount=1)
def crawl_page(thread_name, page_url): # print(spider.gather_links(page_url)) # exit() if not redis.sismember(spider.redis_cralw, com.md5_url(page_url)): print(thread_name + ' now crawling ' + str(page_url)) print('Queue ' + str(redis.scard(spider.redis_queue)) + ' | Crawled ' + str(redis.scard(spider.redis_cralw))) redis.sadd(spider.redis_cralw, com.md5_url(page_url)) # cralw add spider.gather_links(page_url) # 搜索url # redis.srem(spider.redis_queue,page_url)# queue remove mysqldb.insertCrawl(spider.project_name, page_url) else: print("it is cralw")
def __getitem__(self, id): redis = self.redis if not redis.sismember(self.key, id): raise KeyError(id) pipe = redis.pipeline() pipe.get(id) pipe.get('%s.mtime' % id) data, mtime = pipe.execute() item = Item(data) item.__parent__ = self item.__name__ = id item.mtime = float(mtime) return item
def article_switch_vote(redis, user, from_article, to_article): cutoff = datetime.datetime.now() - datetime.timedelta( seconds=ONE_WEEK_IN_SECONDS) to_ = (not datetime.datetime.fromtimestamp( redis.zscore('time:', to_article)) < cutoff) from_ = (not datetime.datetime.fromtimestamp( redis.zscore('time:', from_article)) < cutoff) #if both articles are within the cutoff if to_ and from_: vrem = 'voted:' + from_article.split(':')[-1] vadd = 'voted:' + to_article.split(':')[-1] #verify user voting status on articles if redis.sismember(vrem, user) and not redis.sismember(vadd, user): #remove vote from from_article redis.srem(vrem, user) redis.zincrby(name='score:', value=from_article, amount=-1 * VOTE_SCORE) redis.hincrby(name=from_article, key='votes', amount=-1) #add vote to to_article redis.sadd(vadd, user) redis.zincrby(name='score:', value=to_article, amount=VOTE_SCORE) redis.hincrby(name=to_article, key='votes', amount=1)
def get_items_ids(self, response): soup = BeautifulSoup(response.text, 'lxml') ids = None try: ids = re.search(r'ordered_service_ids = (.*)?]', soup.text, re.M).group(0).replace('ordered_service_ids = ', '') ids = eval(ids) except Exception as e: print(e) print(response.url + ' cannot get app\'s ids, and had skipped.') return ids redis = redis_resource() for _id in ids: if redis.sismember(consumedKey(response.persist['category']), _id): print('id: %s under %s had already crawlered, auto skip done' % (_id, response.persist['category'])) continue else: redis.lpush(response.persist['category'], _id) return {response.persist['category']: ids}
def main(msg): if not redis.sismember("bot:all", msg.chat.id): redis.sadd("bot:gps", msg.chat.id) redis.sadd("bot:all", msg.chat.id) try: if msg.text and re.match("^[!#/][Ss]etlimit", msg.text): admin = bot.get_chat_member(msg.chat.id, msg.from_user.id) max = re.search("(\d+)", msg.text).group(1) if (admin and admin.status == 'creator' or msg.from_user.id == naji) and max: redis.hset(msg.chat.id, "limit", int(max)) bot.reply_to( msg, "🍃 افزودن {} عضو جهت رفع محدودیت در گفتوگو ثبت شد 🍃". format(max)) if not allowed(msg): name = msg.from_user.last_name and msg.from_user.first_name + msg.from_user.last_name or msg.from_user.first_name try: if redis.hget(msg.from_user.id, msg.chat.id): try: bot.delete_message( msg.chat.id, redis.hget(msg.from_user.id, msg.chat.id)) except Exception as e: print(e) bot.delete_message(msg.chat.id, msg.message_id) except Exception as e: print(e) return "" finally: pm = bot.send_message( msg.chat.id, "🌺 کاربر عزیز {} 🌺\nهر عضو گروه موظفه {} نفرو به گروه اضافه کنه تا بتونه چت کنه 😅\n\nتعداد اعضا افزوده شده توسط شما : 💫 {}💫" .format(name, redis.hget(msg.chat.id, "limit") or 1, redis.hget(msg.chat.id, msg.from_user.id) or 0)) redis.hset(msg.from_user.id, msg.chat.id, pm.message_id) except Exception as e: print(e) pass
def post(): """Add item to cart""" redis = current_app.config['redis'] args = request.get_json(force=True) product = args['product_id'] user = args['cart_id'] # Validate if product exists # Get Cart for products url = 'http://' + current_app.config['CATALOG_ENDPOINT'] + '/api/v1/product/' + product r = requests.get(url, timeout=1) if r.status_code != 200: return jsonify({"code": 404, "status": "Product does not exist"}), 404 if redis.sismember(user, product): return jsonify({"message": "Product already in cart", "status": 200}), 200 else: redis.sadd(user, product) return jsonify({"message": "Product added to Cart", "status": 200}), 200
def photos(m): s = bot.get_chat_member(channel, m.chat.id) mn = redis.sismember("bans", m.from_user.id) if mn == False: if s.status == "member" or s.status == "creator" or s.status == "administrator": try: ff = TemporaryFile() ff.write(bot.download_file(bot.get_file(m.photo[-1].file_id).file_path)) ff.seek(0) links = requests.post("http://dev.magic-team.ir/faceapp/apply_filter/?format=json",files={"photo" : ff}).json() if links["status"] != True : bot.reply_to(m.from_user.id,"⚠️Face Not found!\n➖➖➖➖➖➖➖➖\n⚠️چهره شناسایی نشد!") ff.close() return markup = types.InlineKeyboardMarkup() markup.row(types.InlineKeyboardButton(text='👴🏻',callback_data=links['result']['old'].replace("http://dev.magic-team.ir/faceapp/download/?hash=","")),types.InlineKeyboardButton(text='😻',callback_data=links['result']['hot'].replace("http://dev.magic-team.ir/faceapp/download/?hash=","")),types.InlineKeyboardButton(text='👶🏻',callback_data=links['result']['young'].replace("http://dev.magic-team.ir/faceapp/download/?hash=",""))) markup.row(types.InlineKeyboardButton(text='👱🏻',callback_data=links['result']['male'].replace("http://dev.magic-team.ir/faceapp/download/?hash=","")),types.InlineKeyboardButton(text='👱🏻♀️',callback_data=links['result']['female'].replace("http://dev.magic-team.ir/faceapp/download/?hash=",""))) markup.row(types.InlineKeyboardButton(text='😁',callback_data=links['result']['smile'].replace("http://dev.magic-team.ir/faceapp/download/?hash=","")),types.InlineKeyboardButton(text='☺️',callback_data=links['result']['smile_2'].replace("http://dev.magic-team.ir/faceapp/download/?hash=",""))) ff.seek(0) bot.send_photo(m.chat.id,ff,reply_markup=markup,reply_to_message_id=m.message_id) ff.close() except Exception as e: print(e)
def get_welfare_info(redis, account): today = datetime.now().strftime("%Y-%m-%d") first = first_day_of_month() last = date.today() - timedelta(days=1) res = copy.deepcopy(WELFARE_CONFIG) res['date'] = today res['signed'] = [] res['unsinged'] = [] # 今天是否签到 if redis.exists(WELFARE_USER_SIGN % (account, today)): res['issigned'] = 1 else: res['issigned'] = 0 while first <= last: if redis.exists(WELFARE_USER_SIGN % (account, first)): res['signed'].append(first.strftime('%d')) elif redis.sismember(WELFARE_USER_PATCH_SIGN % (account, first.strftime("%m")), first.strftime('%Y-%m-%d')): res['signed'].append(first.strftime('%d')) else: res['unsinged'].append(first.strftime('%d')) first += timedelta(1) # 七天奖励 if not redis.exists(GOLD_WELFARE_SIGN_7DAYS): res['rewardlist'][0]['status'] = MESSION_STATUS_NO elif redis.hget(GOLD_WELFARE_SIGN_7DAYS, account) == MESSION_STATUS_OVER: res['rewardlist'][0]['status'] = MESSION_STATUS_OVER else: res['rewardlist'][0]['status'] = MESSION_STATUS_OK # 十五天奖励 if not redis.exists(GOLD_WELFARE_SIGN_15DAYS): res['rewardlist'][0]['status'] = MESSION_STATUS_NO elif redis.hget(GOLD_WELFARE_SIGN_15DAYS, account) == MESSION_STATUS_OVER: res['rewardlist'][0]['status'] = MESSION_STATUS_OVER else: res['rewardlist'][0]['status'] = MESSION_STATUS_OK # 月奖励 if not redis.exists(GOLD_WELFARE_SIGN_MONTH): res['rewardlist'][0]['status'] = MESSION_STATUS_NO elif redis.hget(GOLD_WELFARE_SIGN_MONTH, account) == MESSION_STATUS_OVER: res['rewardlist'][0]['status'] = MESSION_STATUS_OVER else: res['rewardlist'][0]['status'] = MESSION_STATUS_OK # 每日首冲奖励 if not redis.sismember(DAILY_USER_GOLD2_SET % today, account): res['messionlist'][0]['status'] = MESSION_STATUS_NO res['messionlist'][0]['parent_mode'] = CHECK_MALL else: if redis.hget(GOLD_REWARD_DAY_BUY_GOLD_HASH % today, account) == MESSION_STATUS_OVER: res['messionlist'][0]['status'] = MESSION_STATUS_OVER else: res['messionlist'][0]['status'] = MESSION_STATUS_OK # 新手礼包 if redis.hget(GOLD_REWARD_NEW_PRESENT_HASH, account) == MESSION_STATUS_OVER: res['messionlist'][1]['status'] = MESSION_STATUS_OVER else: res['messionlist'][1]['status'] = MESSION_STATUS_OK # 破产补助 key = WELFARE_USER_INSURANCE % (account, today) if not redis.exists(WELFARE_USER_INSURANCE % (account, today)): res['messionlist'][2]['status'] = MESSION_STATUS_OK else: if redis.llen(key) >= SIGN_MAX: res['messionlist'][2]['status'] = MESSION_STATUS_OVER else: res['messionlist'][2]['status'] = MESSION_STATUS_OK return res
def is_parsed(comment_id): return redis.sismember("parsed_comments", comment_id)
"农家院":"20045"} conn = pymysql.connect(host='127.0.0.1', port=3306, user='******', password='******', db='spider', charset='utf8') # connect to mysql cursor = conn.cursor() redis = redis.Redis(host='127.0.0.1', port=6379, db=1) sql = "INSERT INTO `hotel_type`(`typename`, `code`) VALUES('%s', '%s')" memberedSql = "SELECT `typename`, `code`, `id` FROM `hotel_type` order by `id`" cursor.execute(memberedSql) conn.commit() alltype = cursor.fetchall() for type in alltype: # save existed type to redis redis.sadd('hoteltype', type[0]) for x in hoteltype.keys(): if redis.sismember('hoteltype', x) == 0: # is remember the hotel redis.sadd('hoteltype', x) data = (x, str(hoteltype[x])) cursor.execute(sql%data) conn.commit() redis.sadd('hoteltype', x) hotellist = "http://hotel.meituan.com/kunming?mtt=1.index%2Ffloornew.nc.33.j6x8ynqd#ci=2017-08-29&co=2017-08-30&sort=&w=&attrs=20022:" for x in alltype: tempurl = hotellist+str(x[1]) options = webdriver.ChromeOptions() options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"]) # 屏蔽掉浏览器的认证错误 options.add_experimental_option('prefs', {"profile.managed_default_content_settings.images": 2}) # 使chrome 浏览器不加载图片信息 driver = webdriver.Chrome('/usr/bin/chromedriver', chrome_options=options) driver.get(url=tempurl)
def add_links_to_queue(url): if not redis.sismember(LinkFinder.redis_cralw, com.md5_url(url)) or ( redis.sismember(LinkFinder.redis_queue, url)): if LinkFinder.domain_name == com.get_domain_name(url): # redis.sadd(LinkFinder.redis_cralw, com.md5_url(url)) redis.sadd(LinkFinder.redis_queue, str(url))
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path = [root] + sys.path import store import config redis = redis.Redis() # Get our search for the previous hour keys current = datetime.datetime.utcnow() lasthour = current - datetime.timedelta(hours=1) search = "downloads:hour:%s:*:*" % lasthour.strftime("%y-%m-%d-%H") # Make sure we haven't integrated this already if redis.sismember("downloads:integrated", search): print("Already Integrated '%s'" % search) sys.exit(0) # Fetch all of the keys keys = redis.keys(search) if not keys: print("No keys match '%s'" % search) sys.exit(0) # Fetch all of the download counts (in batches of 200) counts = [] for batch in izip_longest(*[iter(keys)] * 200): batch = [x for x in batch if x is not None] counts.extend(redis.mget(*batch))