import json from configparser import ConfigParser # 读取设置 def __read_setting(): cp = ConfigParser() cp.read("res/setting.conf") return cp # 写入配置 def __write_setting(cp): cp.write(open("res/setting.conf", "w", encoding="gbk")) def __get_setting(cp, type, key): try: return cp.get(type, key) except: return None # ------------------------------浏览器位置----------------------------- def set_chrome_path(_path): # 设置是否置顶 cp = __read_setting() cp.set("config", "chrome_path", _path) __write_setting(cp) # 获取是否置顶 def get_chrome_path(): cp = __read_setting() return cp.get("config", "chrome_path") # -------------------------------浏览器驱动-------------------------- def set_chromedriver_path(_path): # 设置是否置顶 cp = __read_setting() cp.set("config", "chromedriver_path", _path) __write_setting(cp) # 获取是否置顶 def get_chromedriver_path(): cp = __read_setting() return cp.get("config", "chromedriver_path") # --------------------------------是否点赞-------------------------------- def set_click_like(enable): # 设置是否置顶 cp = __read_setting() if enable: enable = 1 else: enable = 0 cp.set("config", "click_like", f"{enable}") __write_setting(cp) # 获取是否置顶 def is_click_like(): cp = __read_setting() return int(cp.get("config", "click_like")) # --------------------------------是否回复评论-------------------------------- def set_reply_comment(enable): cp = __read_setting() if enable: enable = 1 else: enable = 0 cp.set("config", "reply_comment", f"{enable}") __write_setting(cp) def is_reply_comment(): cp = __read_setting() val = __get_setting(cp, "config", "reply_comment") if val: return int(val) else: return 0 # -------------------------------评论内容-------------------------- def set_comment_templates(content): # 设置是否置顶 cp = __read_setting() cp.set("config", "comment_templates", content) __write_setting(cp) # 获取是否置顶 def get_comment_templates(): cp = __read_setting() return cp.get("config", "comment_templates") # -------------------------------常用表情-------------------------- def set_common_emojis(content): # 设置是否置顶 cp = __read_setting() cp.set("config", "common_emojis", content) __write_setting(cp) # 获取是否置顶 def get_common_emojis(): try: cp = __read_setting() return cp.get("config", "common_emojis") except: return "" # -------------------------------点赞条件-------------------------- def set_like_conditions(content): # 设置是否置顶 cp = __read_setting() cp.set("config", "like_conditions", content) __write_setting(cp) # 获取是否置顶 def get_like_conditions(): try: cp = __read_setting() return cp.get("config", "like_conditions") except: return "" if __name__ == "__main__": pass