| 1336 |
rajveer |
1 |
from datastore.DataAccessor import DataHelper
|
|
|
2 |
import os
|
|
|
3 |
import sys
|
|
|
4 |
import subprocess
|
|
|
5 |
from mail import *
|
|
|
6 |
|
|
|
7 |
"""
|
|
|
8 |
Documentation for script consetup.py
|
|
|
9 |
This is the first script called by test.py, this file is created because before importing
|
|
|
10 |
datasore, its PYTHONPATH must be set which is done in test.py, so now we can import it.
|
|
|
11 |
Task of this script is to run the spiders for individual suppliers and call the modules to
|
|
|
12 |
generate respective csv files.
|
|
|
13 |
In the code, for each supplier a separate section is made, in that section last part is for
|
|
|
14 |
csv file generation, rest of the part is for spiders.
|
|
|
15 |
initxy method is called so as to make database visible in this scope
|
|
|
16 |
@param path to the folder in which spider-projects reside (:/home/gaurav/code) but start with pathsep
|
|
|
17 |
"""
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
path = sys.argv[1]
|
|
|
21 |
ps = os.pathsep
|
|
|
22 |
ds = os.sep
|
|
|
23 |
path0 = path[1:len(path)]+ds+"ScrapyDatastore"+ds+"src"
|
|
|
24 |
path1 = path+ds+"ExtraFunctions"+ds+"src"
|
|
|
25 |
path2 = path+ds+"filterforname"+ds+"src"
|
|
|
26 |
path3 = path0+path1+path2
|
|
|
27 |
os.environ['PYTHONPATH'] = path3
|
|
|
28 |
|
|
|
29 |
da = DataHelper()
|
|
|
30 |
da.initxy()
|
|
|
31 |
da.add_newcrawler()
|
|
|
32 |
attach = ""
|
|
|
33 |
|
|
|
34 |
# infibeam
|
|
|
35 |
path4 = path
|
|
|
36 |
path4 = path4.replace(ps,"")
|
|
|
37 |
path4 = path4+ds+"runinfibeam.py"
|
|
|
38 |
subprocess.call(["python", path4, path])
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
phones = da.get_all_infibeam_data()
|
|
|
42 |
if not phones:
|
|
|
43 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for infibeam spider. This mail is automatically generated via python script",attach)
|
|
|
44 |
|
|
|
45 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
46 |
path4 = path+ds+"data2csv"+ds+"src"
|
|
|
47 |
path3 = path3 + path4
|
|
|
48 |
os.putenv("PYTHONPATH",path3)
|
|
|
49 |
path4 = path4.replace(ps,"")
|
|
|
50 |
path4 = path4+ds+"data2csv"+ds+"testfilteredinfibeam.py"
|
|
|
51 |
subprocess.call(["python", path4])
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
#babuchak
|
|
|
55 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
56 |
path4 = path+ds+"babuchakScrapypass1"+ds+"src"
|
|
|
57 |
path3 = path3 + path4
|
|
|
58 |
os.putenv("PYTHONPATH",path3)
|
|
|
59 |
path4 = path4.replace(ps,"")
|
|
|
60 |
path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
61 |
subprocess.call(["python", path4, "crawl", "babuchak"])
|
|
|
62 |
|
|
|
63 |
urls = da.get_allbabuchakurls()
|
|
|
64 |
if not urls:
|
|
|
65 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for first babuchak spider. This mail is automatically generated via python script",attach)
|
|
|
66 |
|
|
|
67 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
68 |
path4 = path + ds+"babuchakScrapypass2"+ds+"src"
|
|
|
69 |
path3 = path3 + path4
|
|
|
70 |
os.putenv("PYTHONPATH",path3)
|
|
|
71 |
path4 = path4.replace(ps,"")
|
|
|
72 |
path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
73 |
subprocess.call(["python", path4, "crawl", "babuchak1"])
|
|
|
74 |
|
|
|
75 |
purls = da.get_allbabuchakphoneurls()
|
|
|
76 |
if urls and not purls:
|
|
|
77 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for second babuchak spider. This mail is automatically generated via python script",attach)
|
|
|
78 |
|
|
|
79 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
80 |
path4 = path + ds+"babuchakScrapypass3"+ds+"src"
|
|
|
81 |
path3 = path3 + path4
|
|
|
82 |
os.putenv("PYTHONPATH",path3)
|
|
|
83 |
path4 = path4.replace(ps,"")
|
|
|
84 |
path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
85 |
subprocess.call(["python", path4, "crawl", "babuchak2"])
|
|
|
86 |
|
|
|
87 |
phones = da.get_allbabuchakphones()
|
|
|
88 |
if urls and purls and not phones:
|
|
|
89 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for third babuchak spider. This mail is automatically generated via python script",attach)
|
|
|
90 |
|
|
|
91 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
92 |
path4 = path + ds+"data2csv"+ds+"src"
|
|
|
93 |
path3 = path3 + path4
|
|
|
94 |
os.putenv("PYTHONPATH",path3)
|
|
|
95 |
path4 = path4.replace(ps,"")
|
|
|
96 |
path4 = path4 + ds+"data2csv"+ds+"testbabuchak.py"
|
|
|
97 |
subprocess.call(["python", path4])
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
#indiaplaza
|
|
|
102 |
path4 = path
|
|
|
103 |
path4 = path4.replace(ps,"")
|
|
|
104 |
path4 = path4+ds+"runindiaplaza.py"
|
|
|
105 |
subprocess.call(["python", path4, path])
|
|
|
106 |
|
|
|
107 |
purls = da.get_all_ipbasic()
|
|
|
108 |
if not purls:
|
|
|
109 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for first indiaplaza spider. This mail is automatically generated via python script",attach)
|
|
|
110 |
|
|
|
111 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
112 |
path4 = path + ds+"indiaplazascapypass2"+ds+"src"
|
|
|
113 |
path3 = path3 + path4
|
|
|
114 |
os.putenv("PYTHONPATH",path3)
|
|
|
115 |
path4 = path4.replace(ps,"")
|
|
|
116 |
path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
117 |
subprocess.call(["python", path4, "crawl", "indiaplaza1"])
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
phones = da.get_all_indiaplaza_phones()
|
|
|
121 |
if purls and not phones:
|
|
|
122 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for second indiaplaza spider. This mail is automatically generated via python script",attach)
|
|
|
123 |
|
|
|
124 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
125 |
path4 = path + ds+"data2csv"+ds+"src"
|
|
|
126 |
path3 = path3 + path4
|
|
|
127 |
os.putenv("PYTHONPATH",path3)
|
|
|
128 |
path4 = path4.replace(ps,"")
|
|
|
129 |
path4 = path4 + ds+"data2csv"+ds+"testfilterindiaplaza.py"
|
|
|
130 |
subprocess.call(["python", path4])
|
|
|
131 |
|
|
|
132 |
#This section commented out by ashish as it was running in infinite loop
|
|
|
133 |
#naaptol
|
|
|
134 |
#path3 = str(os.getenv("PYTHONPATH"))
|
|
|
135 |
#path4 = path + ds+"naaptolpass1"+ds+"src"
|
|
|
136 |
#path3 = path3 + path4
|
|
|
137 |
#os.putenv("PYTHONPATH",path3)
|
|
|
138 |
#path4 = path4.replace(ps,"")
|
|
|
139 |
#path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
140 |
#subprocess.call(["python", path4, "crawl", "naaptol"])
|
|
|
141 |
|
|
|
142 |
#urls = da.get_allnaaptolurls()
|
|
|
143 |
#if not urls:
|
|
|
144 |
# mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for first naaptol spider. This mail is automatically generated via python script",attach)
|
|
|
145 |
|
|
|
146 |
#path3 = str(os.getenv("PYTHONPATH"))
|
|
|
147 |
#path4 = path + ds+"naaptolpass2"+ds+"src"
|
|
|
148 |
#path3 = path3 + path4
|
|
|
149 |
#os.putenv("PYTHONPATH",path3)
|
|
|
150 |
#path4 = path4.replace(ps,"")
|
|
|
151 |
#path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
152 |
#subprocess.call(["python", path4, "crawl", "naaptol1"])
|
|
|
153 |
|
|
|
154 |
#path3 = str(os.getenv("PYTHONPATH"))
|
|
|
155 |
#path4 = path + ds+"naaptolpass3"+ds+"src"
|
|
|
156 |
#path3 = path3 + path4
|
|
|
157 |
#os.putenv("PYTHONPATH",path3)
|
|
|
158 |
#path4 = path4.replace(ps,"")
|
|
|
159 |
#path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
160 |
#subprocess.call(["python", path4, "crawl", "naaptol2"])
|
|
|
161 |
|
|
|
162 |
#phones = da.get_allnaaptolphones()
|
|
|
163 |
#if urls and not phones:
|
|
|
164 |
# mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for second or third naaptol spider. This mail is automatically generated via python script",attach)
|
|
|
165 |
|
|
|
166 |
#path3 = str(os.getenv("PYTHONPATH"))
|
|
|
167 |
#path4 = path + ds+"data2csv"+ds+"src"
|
|
|
168 |
#path3 = path3 + path4
|
|
|
169 |
#os.putenv("PYTHONPATH",path3)
|
|
|
170 |
#path4 = path4.replace(ps,"")
|
|
|
171 |
#path4 = path4 + ds+"data2csv"+ds+"testnaaptol.py"
|
|
|
172 |
#subprocess.call(["python", path4])
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
#univercell
|
|
|
176 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
177 |
path4 = path + ds+"universalScrapypass1"+ds+"src"
|
|
|
178 |
path3 = path3 + path4
|
|
|
179 |
os.putenv("PYTHONPATH",path3)
|
|
|
180 |
path4 = path4.replace(ps,"")
|
|
|
181 |
path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
182 |
subprocess.call(["python", path4, "crawl", "univercell"])
|
|
|
183 |
|
|
|
184 |
vendors = da.get_all_univervendors()
|
|
|
185 |
if not vendors:
|
|
|
186 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for first univercell spider. This mail is automatically generated via python script",attach)
|
|
|
187 |
|
|
|
188 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
189 |
path4 = path + ds+"univercellScrapypass2"+ds+"src"
|
|
|
190 |
path3 = path3 + path4
|
|
|
191 |
os.putenv("PYTHONPATH",path3)
|
|
|
192 |
path4 = path4.replace(ps,"")
|
|
|
193 |
path4 = path4 + ds+"scrapy-ctl.py"
|
|
|
194 |
subprocess.call(["python", path4, "crawl", "univercell1"])
|
|
|
195 |
|
|
|
196 |
phones = da.get_all_univercell_phones()
|
|
|
197 |
if vendors and not phones:
|
|
|
198 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for second univercell spider. This mail is automatically generated via python script",attach)
|
|
|
199 |
|
|
|
200 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
201 |
path4 = path + ds+"data2csv"+ds+"src"
|
|
|
202 |
path3 = path3 + path4
|
|
|
203 |
os.putenv("PYTHONPATH",path3)
|
|
|
204 |
path4 = path4.replace(ps,"")
|
|
|
205 |
path4 = path4 + ds+"data2csv"+ds+"testfilterunivercell.py"
|
|
|
206 |
subprocess.call(["python", path4])
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
#mobilestore
|
|
|
210 |
path4 = path
|
|
|
211 |
path4 = path4.replace(ps,"")
|
|
|
212 |
path4 = path4+ds+"runmobstore.py"
|
|
|
213 |
subprocess.call(["python", path4, path])
|
|
|
214 |
|
|
|
215 |
phones = da.get_allmobstorephones_new()
|
|
|
216 |
if not phones:
|
|
|
217 |
mail("ashish.singh@shop2020.in","Bug","There is some mistake in parameters for mobilestore spider. This mail is automatically generated via python script",attach)
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
221 |
path4 = path + ds+"data2csv"+ds+"src"
|
|
|
222 |
path3 = path3 + path4
|
|
|
223 |
os.putenv("PYTHONPATH",path3)
|
|
|
224 |
path4 = path4.replace(ps,"")
|
|
|
225 |
path4 = path4 + ds+"data2csv"+ds+"new_mobilestore.py"
|
|
|
226 |
subprocess.call(["python", path4])
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
#call indexing
|
|
|
230 |
path3 = str(os.getenv("PYTHONPATH"))
|
|
|
231 |
path4 = path + ds+"Lucene"+ds+"src"
|
|
|
232 |
path3 = path3 + path4
|
|
|
233 |
os.putenv("PYTHONPATH",path3)
|
|
|
234 |
path4 = path4.replace(ps,"")
|
|
|
235 |
path4 = path4 + ds+"Searching"+ds+"Searchbymodel.py"
|
|
|
236 |
subprocess.call(["python", path4])
|
|
|
237 |
|