import sys sys.path.append('./') from lib.config import create_app create_app('local') import time import gevent import crawler from models import PlatformGame, Room crawlers_by_platform_name = { 'douyu': crawler.DouyuCrawler, 'twitch': crawler.TwitchCrawler, } def worker(crawler, platform_game): before_crawler = time.time() rooms = crawler.crawl() after_crawler = time.time() _store_rooms(rooms, platform_game) print '*****************' print 'crawler {count} rooms from {platform_name} {game_name}'.format( count=len(rooms), platform_name=platform_game.platform_name, game_name=platform_game.game_name) after_save = time.time() print 'Crawl time cost: ', after_crawler - before_crawler print 'Save time cost: ', after_save - after_crawler
from lib.config import create_app import gflags FLAGS = gflags.FLAGS gflags.DEFINE_enum('env', None, ['local', 'prod', 'qa', 'dev'], 'Zhibogame environment to use', short_name='e') create_app() def main(argv, run_func): try: argv = FLAGS(argv) except gflags.FlagsError as e: print '\n%s\nUsage: %s ARGS\n%s' % (e, argv[0], FLAGS) return 1 if len(FLAGS(argv)) > 1: run_func(argv[1:]) else: run_func()
import sys sys.path.append('./') from lib.config import create_app create_app('local') import time import gevent import crawler from models import PlatformGame, Room crawlers_by_platform_name = { 'douyu': crawler.DouyuCrawler, 'twitch': crawler.TwitchCrawler, } def worker(crawler, platform_game): before_crawler = time.time() rooms = crawler.crawl() after_crawler = time.time() _store_rooms(rooms, platform_game) print '*****************' print 'crawler {count} rooms from {platform_name} {game_name}'.format( count=len(rooms), platform_name=platform_game.platform_name, game_name=platform_game.game_name) after_save = time.time() print 'Crawl time cost: ', after_crawler - before_crawler
#!env/bin/python import sys sys.path.append('./') from lib.config import create_app create_app('prod') import schedule import time from django.core.exceptions import ObjectDoesNotExist from django.utils import timezone from gevent import spawn from gevent.queue import Queue from carsapp.models import Car from crawler import VroomCrawler, BeepiCrawler CRAWLERS = [VroomCrawler, BeepiCrawler] def run(): start_date = timezone.now() car_queue = Queue() crawler_finished = 0 def worker(crawler): for datum in crawler.crawl(): car_queue.put(datum) car_queue.put(None) for crawler in CRAWLERS:
#!env/bin/python import sys sys.path.append('./') from lib.config import create_app create_app('prod') import schedule import time from django.core.exceptions import ObjectDoesNotExist from django.utils import timezone from gevent import spawn from gevent.queue import Queue from carsapp.models import Car from crawler import VroomCrawler, BeepiCrawler CRAWLERS = [VroomCrawler, BeepiCrawler] def run(): start_date = timezone.now() car_queue = Queue() crawler_finished = 0 def worker(crawler): for datum in crawler.crawl(): car_queue.put(datum) car_queue.put(None)