简单小练习_阅读稍后提醒

#ReadManger(c) -> (tool & context)
from time import ctime
import os
import threading
import webbrowser

class ReadManager(object):
    
    def __init__(self, config):
        self.read_time= config['time']
        self.folder_path = config['folder_path']
        self.urls = self.urls_parse(self.folder_path)

    def urls_parse(self,path):
        urls = []
        for f in os.listdir(path):
            if not f.startswith('.'):
                full_path = path + f
                with open(full_path,'r') as raw_url:
                    url = raw_url.read().split('URL=')[-1].strip('\n')
                    urls.append(url)
        return urls



    def time_to_read(self):
        return self.read_time == ctime().split()[-2]

    def sent_to_browser(self):
        for url in self.urls:
            webbrowser.open_new_tab(url)

    def run(self):
        def _run():
            while True:
                if self.time_to_read:
                    self.sent_to_browser()
        t = threading.Thread(target=_run)
        t.daemon =True
        t.start()


managers = [ReadManager(c) for c in CONFIGS]
# for m in managers:
#     m.run()

 

posted @ 2018-06-25 13:36  Erick-LONG  阅读(110)  评论(0编辑  收藏  举报