| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import json
- import random
- import time
- import requests
- from commons.Logger import logger
- from commons.conn_mysql import MySQLPoolOnline, MySQLPool39
- from spiders.taobao.snapshot_taobao_crawl2 import TaobaoCrawl
- from commons.scheduler import CrawlerScheduler
- from commons.feishu_webhook import send_text
- from commons.config import TB_DEVICE_ID
- platform_name = "淘宝"
- class TaobaoMain:
- def __init__(self):
- # self.db_online = MySQLPool39()
- self.db_online = MySQLPoolOnline()
- self.crawl_count = ""
- self.task_id = ""
- self.task_dict = None
- self.driver = None
- self.cumulative_pages = 0
- self.cumulative_items = 0
- self.cumulative_stored = 0
- self.cumulative_skipped = 0
- def run(self):
- spider_schedule = CrawlerScheduler(TB_DEVICE_ID, 1)
- spider_schedule.start()
- time.sleep(3)
- while 1:
- print(f'not spider_schedule.end:{not spider_schedule.end}')
- if not spider_schedule.end:
- print('进入工作')
- self.task_dict = spider_schedule.get_task()
- if not self.task_dict:
- logger.info(f"{platform_name}暂无任务")
- time.sleep(35)
- continue
- print(self.task_dict)
- self.task_dict.update({'collect_equipment_account_id': TB_DEVICE_ID})
- self.crawl_count, is_success, self.driver, self.cumulative_pages, self.cumulative_items, self.cumulative_stored, self.cumulative_skipped = TaobaoCrawl(self.task_dict, spider_schedule, self.driver, self.cumulative_pages, self.cumulative_items, self.cumulative_stored, self.cumulative_skipped).run()
- spider_schedule.stop()
- else:
- spider_schedule.start()
- print('休息')
- time.sleep(35)
- time.sleep(30)
- if __name__ == '__main__':
- # 每10分钟执行一次
- while True:
- TaobaoMain().run()
- interval_time = random.randint(1200, 1800)
- logger.info(f"程序睡眠{interval_time}秒后继续执行")
- time.sleep(interval_time)
|