Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scrapy.utils.project import get_project_settings
- from scrapy.crawler import CrawlerProcess
- from multiprocessing import Pool, Process
- from itertools import _grouper, groupby, zip_longest
- from geobot.geobot.settings import RESORT_URLS
- from geobot.geobot.spiders.weather_forecast import TurtellaWeatherSpider
- setting = get_project_settings()
- n=2
- def f(process, x):
- # for part in urls_parts:
- process.crawl('weather_forecast', x)
- # query dvh is custom argument used in your scrapy
- def grouper(n, iterable, fillvalue=None):
- "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
- args = [iter(iterable)] * n
- return zip_longest(*args, fillvalue=fillvalue)
- # return list(zip(*islice(*[iter(l)] * n)))
- if __name__ == '__main__':
- group_size = int(len(RESORT_URLS) / n)+1
- process = CrawlerProcess(setting)
- # urls_parts = chunks(RESORT_URLS, (len(RESORT_URLS)/n))
- urls_parts = list(grouper(group_size, RESORT_URLS))
- # urls_parts = list(zip(*(iter(RESORT_URLS),) * group_size))
- procs = []
- for num in range(n):
- procs.append(Process(target=TurtellaWeatherSpider, args=(process, urls_parts[n])))
- # Process(target=f, args=(process, urls_parts[num],)).start()
- map(lambda x: x.start(), procs)
- map(lambda x: x.join(), procs)
- process.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement