def delete_item(self): """ 删除缓存 :return: """ key_info_list = self.cache_info_lb.get( self.cache_info_lb.curselection()).split(' ') key_id = key_info_list[0] result = tk.messagebox.askquestion('删除', '确定删除key为' + key_id + '的缓存?', icon='warning') if result == 'yes': re_result = tk.messagebox.askquestion('删除', '你刚才点了删除,真的要删除吗?', icon='warning') if re_result == 'yes': redis = RedisUtil(int(self.db_index.get())) try: redis.del_key(key_id) except ConnectionError: tk.messagebox.showerror('错误', '没有连接Redis') else: pass else: pass
def _handler_for_recent_games(self) -> str: """[Returns the recent games searched by the user] Returns: [str]: [games with separator as \n] """ return RedisUtil(self.message.author).get_all_games()
def print_key_value(self, event): """ 点击Listbox组件中一条缓存条目,查看对应数据 :param event: :return:None """ self.cache_content_text.delete('1.0', tk.END) #获取Listbox中选中的item的数据 key_info_list = self.cache_info_lb.get( self.cache_info_lb.curselection()).split(' ') key_id = key_info_list[0] key_type = key_info_list[1] third_value = key_info_list[2] #超时时间 or field_name(hash/set) redis = RedisUtil(int(self.db_index.get())) #如果数据类型是hash或者set,则在Listbox中显示hash或set的所有field if key_type in ['hash', 'set']: try: cache_info = redis.get_key_value(key_type, key_id, None) except ConnectionError: tk.messagebox.showerror('错误', '没有连接Redis') return self.fillin_listbox(key_type, key_id, cache_info) elif key_type in ['string', 'list', 'hash_field', 'set_field']: try: key_value = redis.get_key_value(key_type, key_id, third_value) except ConnectionError: tk.messagebox.showerror('错误', '没有连接Redis') return self.cache_content_text.insert(tk.INSERT, str(key_value))
def __init__(self): self.base_url = 'https://www.zhihu.com' self.settings = 'https://www.zhihu.com/settings/profile' self.headers = { "User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:41.0) Gecko/20100101 Firefox/41.0', "Referer": 'http://www.zhihu.com/', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate, br', 'Connection': 'keep-alive', 'Host': 'www.zhihu.com', } # 爬虫起点 self.start_user = None # 已爬取用户ID的Redis Set Key self.pass_key = 'zhihu:pass' # 爬取失败用户ID的Redis Set Key self.fail_key = 'zhihu:fail' # 待爬取用户ID的Redis List Key self.queue_key = 'user' # 知乎账号池 self.pool = AccountPool() # 采用requests库保存会话信息 self.session = requests.session() # mongodb存储爬取的用户信息 self.mongo = Mongo(database='zhihu') # redis存储爬取状态信息 self.redis = RedisUtil(host='localhost', port=6379, namespace='zhihu') # logger配置 logging.config.fileConfig("./Log/zhihu.conf") self.logger = logging.getLogger('zhihu') self.use_account()
def query_cache_info(self): """ 按查询条件查询缓存 :return: """ if self.db_index.get() in self.all_db: redis = RedisUtil(int(self.db_index.get())) else: tk.messagebox.showerror('错误', '参数不正确:没有选择数据库') return type_variable_value = self.type_variable.get() query_condition_key = self.input_value.get() self.cache_content_text.delete('1.0', tk.END) self.cache_info_lb.delete(0, tk.END) #2.按指定的key类型和key名称查询数据 if type_variable_value in ['string','list','set','hash'] and \ self.check_none(query_condition_key): try: cache_info = redis.get_key_value(type_variable_value, query_condition_key, None) except ConnectionError: tk.messagebox.showerror('错误', '没有连接Redis') return #如果数据类型是hash或者set,则在Listbox中显示hash或set的所有field if type_variable_value in ['hash', 'set']: self.fillin_listbox(type_variable_value, query_condition_key, cache_info) return #如果数据类型是string,则在Text中显示value,在Listbox中显示key self.cache_info_lb.delete(0, tk.END) try: key_info_tuple = redis.get_key_info(query_condition_key) result = query_condition_key + ' ' + type_variable_value + ' 超时时间:' + key_info_tuple[ 1] except ConnectionError: tk.messagebox.showerror('错误', '没有连接Redis') return self.cache_info_lb.insert(tk.END, result) self.cache_content_text.insert(tk.INSERT, str(cache_info)) #1.查询当前数据库中所有的key信息:key名称、key类型、key超时时间,在Listbox组件显示 elif type_variable_value == '选择数据类型': try: cache_info = redis.get_all_keys() except ConnectionError: tk.messagebox.showerror('错误', '没有连接Redis') return for item in cache_info: self.tmp_list.clear() self.tmp_list.append(item) #临时保存数据 self.cache_info_lb.insert(tk.END, item)
def _insert_game_in_db_if_exists(self): """ Insert game in redis if google query contains words like !google apple games, !google game of thrones etc. Otherwise does nothing. """ if "game" in self.user_message_lower: game_name = " ".join(self.user_message_lower.split(" ")[1:]) RedisUtil(self.message.author).insert_game(game_name)
def __init__(self): if utils.get_host_ip() == '10.1.13.49': self.HOST = '10.1.13.29' else: self.HOST = '202.107.204.50' self.conn = MySQLdb.connect(host=self.HOST, user='******', passwd='tdlabDatabase', db='techpooldata', port=3306, charset='utf8') self.tables = {'paper': 'expert_paper_join', 'patent': 'expert_patent_join', 'project': 'expert_project_join'} self.columns = {'paper': 'PAPER_ID', 'patent': 'PATENT_ID', 'project': 'PROJECT_ID'} self.redis = RedisUtil()
def conn_redis(self): env = self.env_value.get() host = self.host_value.get() port = self.port_value.get() password = self.password_value.get() is_Connection_success = RedisUtil(None).testConnection( host=host, port=port, password=password) if is_Connection_success: self.top_level.destroy() #销毁Toplevel窗口 conf_file_path = os.getcwd() + '\\conf\\redis_conf.cfg' RedisConf().write_cfg(file_path=conf_file_path, env=env, host=host, port=port, password=password) tk.messagebox.showinfo('连接成功', '连接Redis成功!') else: tk.messagebox.showwarning('连接失败', '连接Redis失败!')