Advertisement
AlexProfi

Untitled

Aug 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. from scrapy.utils.project import get_project_settings
  2. from scrapy.crawler import CrawlerProcess
  3. from multiprocessing import Pool, Process
  4. from itertools import _grouper, groupby, zip_longest
  5.  
  6. from geobot.geobot.settings import RESORT_URLS
  7. from geobot.geobot.spiders.weather_forecast import TurtellaWeatherSpider
  8.  
  9. setting = get_project_settings()
  10.  
  11. n=2
  12.  
  13. def f(process, x):
  14. # for part in urls_parts:
  15. process.crawl('weather_forecast', x)
  16. # query dvh is custom argument used in your scrapy
  17.  
  18. def grouper(n, iterable, fillvalue=None):
  19. "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
  20. args = [iter(iterable)] * n
  21. return zip_longest(*args, fillvalue=fillvalue)
  22. # return list(zip(*islice(*[iter(l)] * n)))
  23.  
  24. if __name__ == '__main__':
  25. group_size = int(len(RESORT_URLS) / n)+1
  26. process = CrawlerProcess(setting)
  27.  
  28. # urls_parts = chunks(RESORT_URLS, (len(RESORT_URLS)/n))
  29. urls_parts = list(grouper(group_size, RESORT_URLS))
  30. # urls_parts = list(zip(*(iter(RESORT_URLS),) * group_size))
  31. procs = []
  32.  
  33. for num in range(n):
  34. procs.append(Process(target=TurtellaWeatherSpider, args=(process, urls_parts[n])))
  35.  
  36. # Process(target=f, args=(process, urls_parts[num],)).start()
  37. map(lambda x: x.start(), procs)
  38. map(lambda x: x.join(), procs)
  39.  
  40. process.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement