HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
scraper_custom_task.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 
4 """
5 HCE project, Python bindings, Distributed Tasks Manager application.
6 ScraperMultiItemsTask Class content main functional scrapering multi items.
7 
8 @package: dc_processor
9 @file scraper_multi_items_task.py
10 @author scorp
11 @link: http://hierarchical-cluster-engine.com/
12 @copyright: Copyright © 2013-2014 IOIX Ukraine
13 @license: http://hierarchical-cluster-engine.com/license/
14 @since: 0.1
15 """
16 
17 
18 import ppath
19 from ppath import sys
20 
21 # For profiling
22 import app.Profiler as Profiler
23 
24 
25 # Start profiling
26 pr = Profiler.Profiler()
27 if pr and pr.status > 0:
28  pr.start()
29 
30 
31 import pickle
32 import os
33 import sys
34 from dc_processor.ScraperCustomJson import ScraperCustomJson
35 import app.Consts as APP_CONSTS
36 
37 
38 # That script create main scrapering multi items application
39 
40 
41 app = None
42 exit_code = APP_CONSTS.EXIT_SUCCESS
43 
44 try:
45  # create the app
46  app = ScraperCustomJson()
47  # setup the application
48  app.setup()
49  # add support command line arguments
50  app.args.add_argument('-c', '--config', action='store', metavar='config_file', help='config ini-file', required=True)
51 
52  # run the application
53  app.run()
54 
55  exit_code = app.getExitCode()
56 
57  # log message about profiler
58  if pr.errorMsg and app.logger:
59  app.logger.error(pr.errorMsg)
60 
61 except Exception as err:
62  sys.stderr.write(str(err) + '\n')
63  exit_code = APP_CONSTS.EXIT_FAILURE
64 except:
65  exit_code = APP_CONSTS.EXIT_FAILURE
66 finally:
67  # stop profiling
68  if pr:
69  pr.stop()
70  # close the app
71  if app:
72  app.close()
73 
74  sys.stdout.flush()
75  os._exit(exit_code)