text: # coding=utf-8
  # 爬虫基类
  
  import random
  import threading
  import time
  
  from ..config import RANDOM_DELAY, start_url
  from ..place.city import cities
  from ..util.date import get_date_string
  
  
  class BaseSpider(object):
      def __init__(self, name):
          self.name = name
          self.cities = cities
          # 准备日期信息，爬到的数据存放到日期相关文件夹下
          self.date_string = get_date_string()
          print('Today date is: %s' % self.date_string)
  
          self.total_num = 0  # 总的小区个数，用于统计
          print("Target site is {0}".format(start_url))
          self.mutex = threading.Lock()  # 创建锁
  
      def create_prompt_text(self):
          """
          根据已有城市中英文对照表拼接选择提示信息
          :return: 拼接好的字串
          """
          city_info = list()
          count = 0
          for en_name, ch_name in self.cities.items():
              count += 1
              city_info.append(en_name)
              city_info.append(": ")
              city_info.append(ch_name)
              if count % 4 == 0:
                  city_info.append("\n")
              else:
                  city_info.append(", ")
          return 'Which city do you want to crawl?\n' + ''.join(city_info)
  
      def get_chinese_city(self, en):
          """
          拼音拼音名转中文城市名
          :param en: 拼音
          :return: 中文
          """
          return self.cities.get(en, None)
  
      @staticmethod
      def random_delay():
          if RANDOM_DELAY:
              time.sleep(random.randint(0, 16))
  