Esempio n. 1
0
 def get_recent_result(self, key):
     """output: urls, size_ratio"""
     if key not in self.__url_map:
         return None, None
     [retrieved_date, new_result, urls, size_ratio] = self.__url_map[key]
     if not self.__network_reachable or Crawler.__STOP_SEARCH:
         show(get_msg(Msg.use_previous_search_result))
         # though size_ratio can be valid, we do not return it for caller usage is not expected
         return urls, None
     # spec.: we will execute a new search when there is enough new result on previous search
     #       => if previous new result is n, all result is m, we will have a new search after m/n days
     #       => if all previous result is new, then after 1 day we will have a search
     #       => if no previous result is new, then we will have a search after 'TARGET_SEARCH_RESULT_SIZE' days
     valid_day_size = len(urls) / new_result if new_result > 0 else \
         1 if NA is new_result else \
         TARGET_SEARCH_RESULT_SIZE  # new_result = 0 => no new result before
     from util.global_def import get_search_latency
     valid_day_size *= get_search_latency()
     current_date = datetime.today()
     date_diff = current_date - retrieved_date
     if date_diff > timedelta(days=valid_day_size):  # 'valid_day_size' is the valid duration of search result
         return None, size_ratio
     to_next_query = timedelta(days=valid_day_size) - date_diff
     hours, remainder = divmod(to_next_query.seconds, 3600)
     minutes, seconds = divmod(remainder, 60)
     show(get_msg(Msg.to_next_search),
          to_next_query.days, get_msg(Msg.day),
          hours, get_msg(Msg.hour),
          minutes, get_msg(Msg.minute),
          seconds, (get_msg(Msg.second) + ","), get_msg(Msg.current_url_count), len(urls))
     # though size_ratio can be valid, we do not return it for caller usage is not expected
     return urls, None
Esempio n. 2
0
 def set_general_setting(self):
     lang = get_lang() if not self.__config.has_option("reminder", "lang") else \
         self.__config.get("reminder", "lang")
     if type(lang) is str:
         lang = EN if "EN" == lang else CHT if "CHT" == lang else None
     assert lang is not None
     data_home = get_data_home() if not self.__config.has_option("reminder", "data_location") else \
         self.__config.get("reminder", "data_location")
     slideshow_frequency = get_slideshow_frequency() if not self.__config.has_option("image", "slideshow_frequency") else \
         float(self.__config.get("image", "slideshow_frequency"))
     phrase_appear_ratio = get_phrase_appear_ratio() if not self.__config.has_option("phrase", "ratio") else \
         float(self.__config.get("phrase", "ratio"))
     api_key = get_api_key() if not self.__config.has_option("search", "api_key") else \
         self.__config.get("search", "api_key")
     cx = get_cx() if not self.__config.has_option("search", "cx") else \
         self.__config.get("search", "cx")
     search_latency = get_search_latency() if not self.__config.has_option("search", "search_latency") else \
         float(self.__config.get("search", "search_latency"))
     fullscreen_mode2 = get_fullscreen_mode2() if not self.__config.has_option("reminder", "fullscreen_mode2") else \
         "True" == self.__config.get("reminder", "fullscreen_mode2")
     verbose = get_verbose() if not self.__config.has_option("reminder", "verbose") else \
         "True" == self.__config.get("reminder", "verbose")
     set_lang(lang)
     set_data_home(data_home)
     set_slideshow_frequency(slideshow_frequency)
     set_phrase_appear_ratio(phrase_appear_ratio)
     set_search_latency(search_latency)
     set_api_key(api_key)
     set_cx(cx)
     set_fullscreen_mode2(fullscreen_mode2)
     set_verbose(verbose)
     print("=======  reminder setting  =============")
     print("data home:       ", data_home)
     print("slideshow:       ", slideshow_frequency)
     print("phrase ratio:    ", phrase_appear_ratio)
     print("search latency:  ", search_latency)
     print("api key:         ", api_key if "" != api_key else "None")
     print("cx:              ", cx if "" != cx else "None")
     print("========================================")