In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
< 0: value["clean_days"] = "0" else: value["clean_days"] = self.line_gobackdays.text() except ValueError: value["clean_days"] = "0" value["is_clean"] = self.check_is_clean.isChecked() value["clean_pic"] = self.check_picdown.isChecked() value["clean_file"] = self.check_files.isChecked() value["clean_video"] = self.check_video.isChecked() value["clean_pic_cache"] = self.check_picscache.isChecked() with open(working_dir + "/config.json", "w", encoding="utf-8") as f: json.dump(self.config, f) self.setSuccessinfo("更新配置文件成功") self.Signal_OneParameter.emit(1) def __init__(self): super().__init__() loadUi(working_dir + "/images/config.ui", self) self._frame() self._connect() self.doFadeIn() self.create_config() self.show()class MainWindow(Window): def deal_emit_slot(self, set_status): if set_status and not self.config_exists: self.setSuccessinfo("已经准备好,可以开始了!") self.config_exists = True def closeEvent(self, event): sys.exit(0) def eventFilter(self, object, event): if event.type() == QEvent.MouseButtonPress: if object == self.lab_close: self.doFadeOut() return True elif object == self.lab_clean: try: self.setSuccessinfo("正在清理中...") self.justdoit() except: self.setWarninginfo("清理失败,请检查配置文件后重试") return True elif object == self.lab_config: cw = ConfigWindow() cw.Signal_OneParameter.connect(self.deal_emit_slot) return True return False def _eventfilter(self): # 事件过滤 self.lab_close.installEventFilter(self) self.lab_clean.installEventFilter(self) self.lab_config.installEventFilter(self) def get_fileNum(self, path, day, picCacheCheck, fileCheck, picCheck, videoCheck, file_list, dir_list): dir_name = PureWindowsPath(path) # Convert path to the right format for the current operating system correct_path = Path(dir_name) now = datetime.datetime.now() if picCacheCheck: path_one = correct_path / 'Attachment' path_two = correct_path / 'FileStorage/Cache' self.getPathFileNum(now, day, path_one, path_two, file_list, dir_list) if fileCheck: path_one = correct_path / 'Files' path_two = correct_path / 'FileStorage/File' self.getPathFileNum(now, day, path_one, path_two, file_list, dir_list) if picCheck: path_one = correct_path / 'Image/Image' path_two = correct_path / 'FileStorage/Image' self.getPathFileNum(now, day, path_one, path_two, file_list, dir_list) if videoCheck: path_one = correct_path / 'Video' path_two = correct_path / 'FileStorage/Video' self.getPathFileNum(now, day, path_one, path_two, file_list, dir_list) def pathFileDeal(self, now, day, path, file_list, dir_list): if os.path.exists(path): filelist = [ f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) ] for i in range(0, len(filelist)): file_path = os.path.join(path, filelist[i]) if os.path.isdir(file_path): continue timestamp = datetime.datetime.fromtimestamp( os.path.getmtime(file_path)) diff = (now - timestamp).days if diff >= day: file_list.append (file_path) def getPathFileNum (self, now, day, path_one, path_two, file_list, dir_list): # caculate path_one self.pathFileDeal (now, day, path_one, file_list Dir_list) td = datetime.datetime.now ()-datetime.timedelta (days=day) td_year = td.year td_month = td.month # caculate path_two if os.path.exists (path_two): osdir = os.listdir (path_two) dirlist = [] for i in range (0 Len (osdir): file_path = os.path.join (path_two, osdir [I]) if os.path.isdir (file_path): dirlist.append (osdirt [I]) for i in range (0, len (dirlist)): file_path = os.path.join (path_two) Dirlist [I]) if os.path.isfile (file_path): continue if re.match ('\ d {4} (\ -)\ d {2}', dirlist [I])! = None: cyear = int (dirlist [I] .split ('-', 1) [0]) cmonth = int (dirlist [I] .split ('-') 1) [1]) if self.__before_deadline (cyear, cmonth, td_year Td_month): dir_list.append (file_path) else: if cmonth = = td_month: self.pathFileDeal (now, day, file_path, file_list Dir_list) def _ _ before_deadline (self, cyear, cmonth, td_year, td_month): if cyear
< td_year: return True elif cyear >Td_year: return False elif cyear = = td_year: return cmonth < td_month def callback (self, v): value = v / int ((self.total_file + self.total_dir)) * 100self.bar_progress.setValue (value) if value = = 100: out = "this total clean file" + str (self.total_file) + " Folder "+ str (self.total_dir) +". Please go to the Recycle Bin to check and empty it. " Self.setSuccessinfo (out) return def justdoit (self): # the design of this Api is so stupid, in fact, dir can be put directly in user. Change fd = open (working_dir + "/ config.json") when you have time. Encoding= "utf-8") self.config = json.load (fd) I = 0 need_clean = False thread_list = [] total_file = 0 total_dir = 0 share_thread_arr = [0] for value in self.config ["users"]: file_list = [] dir_list = [] If value ["is_clean"]: self.get_fileNum (self.config ["data_dir"] [I] Int (value ["clean_days"]), value ["clean_pic_cache"], value ["clean_file"], value ["clean_pic"], value ["clean_video"], file_list Dir_list) if len (file_list) + len (dir_list)! = 0: need_clean = True total_file + = len (file_list) total_dir + = len (dir_list) thread_list.append (multiDeleteThread (file_list, dir_list) Share_thread_arr) thread_list [- 1] .delete _ process_signal.connect (self.callback) I = I + 1 if not need_clean: self.setWarninginfo ("no files to clean") else: self.total_file = total_file self.total_dir = total_dir for thread in Thread_list: thread.run () def _ _ init__ (self): super (). _ _ init__ () loadUi (working_dir + "/ images/main.ui" Self) self._frame () self._eventfilter () self.doFadeIn () self.config_exists = True # determine whether the configuration file exists if not os.path.exists (working_dir + "/ config.json"): self.setWarninginfo ("the configuration file does not exist! Please click "Settings" to create a configuration file) self.config_exists = False self.show () if _ _ name__ = ='_ _ main__': app = QApplication ([]) win = MainWindow () app.exec_ () the above is about "how to write Wechat cleaning tool based on Python". I believe you all have some understanding. I hope the content shared by the editor will be helpful to all of you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.