| 16561 |
amit.gupta |
1 |
from datetime import datetime
|
| 17233 |
amit.gupta |
2 |
from email import encoders
|
|
|
3 |
from email.mime.base import MIMEBase
|
|
|
4 |
from email.mime.multipart import MIMEMultipart
|
|
|
5 |
from email.mime.text import MIMEText
|
| 16561 |
amit.gupta |
6 |
from paramiko.client import SSHClient
|
| 14843 |
amit.gupta |
7 |
import StringIO
|
|
|
8 |
import base64
|
|
|
9 |
import gzip
|
| 16561 |
amit.gupta |
10 |
import logging
|
|
|
11 |
import os
|
|
|
12 |
import paramiko
|
| 14843 |
amit.gupta |
13 |
import pymongo
|
| 16561 |
amit.gupta |
14 |
import random
|
| 17233 |
amit.gupta |
15 |
import smtplib
|
| 16561 |
amit.gupta |
16 |
import socket
|
| 13572 |
kshitij.so |
17 |
import time
|
| 14843 |
amit.gupta |
18 |
import urllib
|
| 14736 |
kshitij.so |
19 |
import urllib2
|
| 15906 |
kshitij.so |
20 |
import urlparse
|
| 18092 |
manas |
21 |
from Crypto.Hash import MD5
|
|
|
22 |
from Crypto.Cipher import DES
|
|
|
23 |
import string
|
| 14705 |
kshitij.so |
24 |
#TODO Need to add messy stuff to conf.
|
| 17233 |
amit.gupta |
25 |
|
|
|
26 |
|
|
|
27 |
SENDER = "cnc.center@shop2020.in"
|
|
|
28 |
PASSWORD = "5h0p2o2o"
|
|
|
29 |
SMTP_SERVER = "smtp.gmail.com"
|
|
|
30 |
SMTP_PORT = 587
|
|
|
31 |
|
| 18092 |
manas |
32 |
_password = 'dtr18Feb2015'
|
|
|
33 |
_salt = '\xA9\x9B\xC8\x32\x56\x35\xE3\x03'
|
|
|
34 |
_iterations = 19
|
| 17233 |
amit.gupta |
35 |
|
| 18092 |
manas |
36 |
ALPHABET = string.ascii_uppercase + string.ascii_lowercase + \
|
|
|
37 |
string.digits + '-_'
|
|
|
38 |
ALPHABET_REVERSE = dict((c, i) for (i, c) in enumerate(ALPHABET))
|
|
|
39 |
BASE = len(ALPHABET)
|
|
|
40 |
SIGN_CHARACTER = '$'
|
| 17233 |
amit.gupta |
41 |
|
| 14708 |
kshitij.so |
42 |
con=None
|
| 18257 |
manas |
43 |
conDtrData = None
|
| 14736 |
kshitij.so |
44 |
headers = {
|
|
|
45 |
'User-agent':'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
|
|
|
46 |
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
|
47 |
'Accept-Language' : 'en-US,en;q=0.8',
|
|
|
48 |
'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
|
|
|
49 |
'Connection':'keep-alive',
|
|
|
50 |
'Accept-Encoding' : 'gzip,deflate,sdch'
|
|
|
51 |
}
|
| 17340 |
kshitij.so |
52 |
PROXY_MESH_LIVE = "ch.proxymesh.com:31280"
|
| 18153 |
kshitij.so |
53 |
PROXY_MESH_GENERAL = "de.proxymesh.com:31280"
|
| 17273 |
kshitij.so |
54 |
PROXY_FLIPKART = "117.240.187.35:3128"
|
| 15152 |
kshitij.so |
55 |
|
| 14843 |
amit.gupta |
56 |
PUSH_NOTIFICATION_URL='http://api.profittill.com/admin/users/push'
|
|
|
57 |
DTR_API_BASIC_AUTH = base64.encodestring('%s:%s' % ("dtr", "dtr18Feb2015")).replace('\n', '')
|
| 16371 |
amit.gupta |
58 |
statusMap = {1:'Active',2:'EOL',3:'In Process',4:'Exclusive'}
|
| 17041 |
manish.sha |
59 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6, 'HOMESHOP18.COM':7}
|
| 14747 |
kshitij.so |
60 |
|
| 16398 |
amit.gupta |
61 |
CB_INIT = 'Waiting Confirmation'
|
|
|
62 |
CB_PENDING = 'Pending'
|
|
|
63 |
CB_CREDIT_IN_PROCESS = 'Credit in process'
|
|
|
64 |
CB_CREDITED = 'Credited to wallet'
|
|
|
65 |
CB_NA = 'Not Applicable'
|
|
|
66 |
CB_APPROVED = 'Approved'
|
|
|
67 |
CB_REJECTED = 'Rejected'
|
|
|
68 |
CB_ONHOLD = 'On hold'
|
|
|
69 |
CB_CANCELLED = 'Cancelled'
|
|
|
70 |
|
| 16399 |
amit.gupta |
71 |
ORDER_PLACED = 'Order Placed'
|
|
|
72 |
ORDER_DELIVERED = 'Delivered'
|
|
|
73 |
ORDER_SHIPPED = 'Shipped' #Lets see if we can make use of it
|
|
|
74 |
ORDER_CANCELLED = 'Cancelled'
|
| 16398 |
amit.gupta |
75 |
|
| 16538 |
kshitij.so |
76 |
AFFILIATE_OFFER_API= {1:"https://www.spicesafar.com/FreeBapp/fetchOffersSM?deviceId=%s&retailerCode=%d"}
|
|
|
77 |
AFFILIATE_OFFER_DESC_API = {1:"https://www.spicesafar.com/FreeBapp/individualOffersSM?deviceId=%s&offerId=%s&retailerCode=%d"}
|
| 16736 |
amit.gupta |
78 |
CREDIT_TYPE_ORDER = "Order"
|
|
|
79 |
CREDIT_TYPE_APP = "App"
|
| 17873 |
kshitij.so |
80 |
SUB_CATEGORY_MAP = {7:'Memory Card',8:'Cable',9:'USB Lights',10:"Screen Magnifier",11:"Car Charger",12:"Power Bank",13:"Pendrive",14:"Combo",15:"Charger",16:"Bluetooth Headset",17:"Speaker", \
|
| 18476 |
kshitij.so |
81 |
18:"Adapter",19:"Cases",20:"Screen Guard",21:"Headphone",22:"Card Reader",23:"Mobile Holder",24:"AUX Cable",25:"OTG Cable",26:"Selfie Stick",27:"Carrying Case",28:"Tempered Glass",29:"Battery"}
|
| 16399 |
amit.gupta |
82 |
|
| 14705 |
kshitij.so |
83 |
def get_mongo_connection(host='localhost', port=27017):
|
|
|
84 |
global con
|
|
|
85 |
if con is None:
|
|
|
86 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
87 |
try:
|
|
|
88 |
con = pymongo.MongoClient(host, port)
|
|
|
89 |
except Exception, e:
|
|
|
90 |
print e
|
|
|
91 |
return None
|
|
|
92 |
return con
|
|
|
93 |
|
| 18257 |
manas |
94 |
def get_mongo_connection_dtr_data(host='45.33.50.227', port=27017):
|
|
|
95 |
global conDtrData
|
|
|
96 |
if conDtrData is None:
|
|
|
97 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
98 |
try:
|
|
|
99 |
conDtrData = pymongo.MongoClient(host, port)
|
|
|
100 |
except Exception, e:
|
|
|
101 |
print e
|
|
|
102 |
return None
|
|
|
103 |
return conDtrData
|
|
|
104 |
|
| 13572 |
kshitij.so |
105 |
def to_java_date(py_timestamp):
|
|
|
106 |
try:
|
|
|
107 |
java_date = int(time.mktime(py_timestamp.timetuple())) * 1000 + py_timestamp.microsecond / 1000
|
|
|
108 |
return java_date
|
|
|
109 |
except:
|
| 14705 |
kshitij.so |
110 |
return None
|
| 16631 |
manish.sha |
111 |
|
|
|
112 |
def to_py_date(java_timestamp):
|
| 16658 |
manish.sha |
113 |
try:
|
| 16660 |
manish.sha |
114 |
date = datetime.fromtimestamp(java_timestamp / 1e3)
|
| 16658 |
manish.sha |
115 |
except:
|
|
|
116 |
return None
|
|
|
117 |
|
| 16631 |
manish.sha |
118 |
return date
|
| 14705 |
kshitij.so |
119 |
|
|
|
120 |
def getCashBack(skuId, source_id, category_id, mc, mongoHost):
|
| 17605 |
kshitij.so |
121 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14705 |
kshitij.so |
122 |
populateCashBack(mc, mongoHost)
|
|
|
123 |
itemCashBackMap = mc.get("item_cash_back")
|
|
|
124 |
itemCashBack = itemCashBackMap.get(skuId)
|
|
|
125 |
if itemCashBack is not None:
|
|
|
126 |
return itemCashBack
|
|
|
127 |
cashBackMap = mc.get("category_cash_back")
|
|
|
128 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
129 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
130 |
for cashBack in sourceCashBack:
|
|
|
131 |
if cashBack.get(category_id) is None:
|
|
|
132 |
continue
|
|
|
133 |
else:
|
|
|
134 |
return cashBack.get(category_id)
|
|
|
135 |
else:
|
|
|
136 |
return {}
|
|
|
137 |
|
|
|
138 |
def populateCashBack(mc, mongoHost):
|
|
|
139 |
print "Populating cashback"
|
|
|
140 |
cashBackMap = {}
|
|
|
141 |
itemCashBackMap = {}
|
|
|
142 |
cashBack = list(get_mongo_connection(host=mongoHost).Catalog.CategoryCashBack.find())
|
|
|
143 |
for row in cashBack:
|
|
|
144 |
temp_map = {}
|
|
|
145 |
temp_list = []
|
|
|
146 |
if cashBackMap.has_key(row['source_id']):
|
|
|
147 |
arr = cashBackMap.get(row['source_id'])
|
|
|
148 |
for val in arr:
|
|
|
149 |
temp_list.append(val)
|
|
|
150 |
temp_map[row['category_id']] = row
|
|
|
151 |
temp_list.append(temp_map)
|
|
|
152 |
cashBackMap[row['source_id']] = temp_list
|
|
|
153 |
else:
|
|
|
154 |
temp_map[row['category_id']] = row
|
|
|
155 |
temp_list.append(temp_map)
|
|
|
156 |
cashBackMap[row['source_id']] = temp_list
|
|
|
157 |
itemCashBack = list(get_mongo_connection(host=mongoHost).Catalog.ItemCashBack.find())
|
|
|
158 |
for row in itemCashBack:
|
|
|
159 |
if not itemCashBackMap.has_key(row['skuId']):
|
|
|
160 |
itemCashBackMap[row['skuId']] = row
|
|
|
161 |
mc.set("item_cash_back", itemCashBackMap, 24 * 60 * 60)
|
|
|
162 |
mc.set("category_cash_back", cashBackMap, 24 * 60 * 60)
|
|
|
163 |
|
| 14736 |
kshitij.so |
164 |
def ungzipResponse(r):
|
|
|
165 |
headers = r.info()
|
|
|
166 |
if headers.get('Content-Encoding')=='gzip':
|
|
|
167 |
url_f = StringIO.StringIO(r.read())
|
|
|
168 |
gz = gzip.GzipFile(fileobj=url_f)
|
|
|
169 |
html = gz.read()
|
|
|
170 |
gz.close()
|
|
|
171 |
return html
|
|
|
172 |
return r.read()
|
|
|
173 |
|
|
|
174 |
|
| 17267 |
kshitij.so |
175 |
def fetchResponseUsingProxy(url, headers=headers, livePricing=None, proxy=True, flipkart=False):
|
| 17041 |
manish.sha |
176 |
if livePricing is None:
|
|
|
177 |
PROXY_URL = PROXY_MESH_GENERAL
|
| 17267 |
kshitij.so |
178 |
elif flipkart:
|
|
|
179 |
PROXY_URL = PROXY_FLIPKART
|
| 17041 |
manish.sha |
180 |
else:
|
|
|
181 |
PROXY_URL = PROXY_MESH_LIVE
|
|
|
182 |
if proxy:
|
|
|
183 |
print PROXY_URL
|
|
|
184 |
proxy = urllib2.ProxyHandler({'http': PROXY_URL})
|
|
|
185 |
opener = urllib2.build_opener(proxy)
|
|
|
186 |
urllib2.install_opener(opener)
|
| 14736 |
kshitij.so |
187 |
req = urllib2.Request(url,headers=headers)
|
|
|
188 |
response = urllib2.urlopen(req)
|
|
|
189 |
response_data = ungzipResponse(response)
|
|
|
190 |
response.close()
|
|
|
191 |
return response_data
|
|
|
192 |
|
| 14948 |
amit.gupta |
193 |
def getCurrTimeStamp():
|
|
|
194 |
return toTimeStamp(datetime.now())
|
|
|
195 |
|
|
|
196 |
def toTimeStamp(dateTimeObj):
|
|
|
197 |
return int(time.mktime(dateTimeObj.timetuple()))
|
| 14987 |
amit.gupta |
198 |
def fromTimeStamp(timestamp):
|
| 15166 |
amit.gupta |
199 |
return datetime.fromtimestamp(timestamp)
|
|
|
200 |
|
| 16499 |
kshitij.so |
201 |
def getNlcPoints(deal):
|
|
|
202 |
if not(deal.get('minNlc') and deal.get('maxNlc')):
|
|
|
203 |
print "Raising exception minNlc, maxNlc not found for %d"%(deal.get('_id'))
|
| 15182 |
kshitij.so |
204 |
raise
|
| 16499 |
kshitij.so |
205 |
if deal.get('status') == 2:
|
| 15182 |
kshitij.so |
206 |
eolWeight = .60
|
|
|
207 |
else:
|
|
|
208 |
eolWeight = 1.0
|
| 16499 |
kshitij.so |
209 |
if deal.get('category_id') == 3:
|
| 15182 |
kshitij.so |
210 |
basePointPercentage = 5.0
|
|
|
211 |
maxNlcPoints = 200
|
| 16499 |
kshitij.so |
212 |
elif deal.get('category_id') == 5:
|
| 15182 |
kshitij.so |
213 |
basePointPercentage = 8.0
|
|
|
214 |
maxNlcPoints = 150
|
|
|
215 |
else:
|
|
|
216 |
basePointPercentage = 10.0
|
|
|
217 |
maxNlcPoints = 150
|
| 16499 |
kshitij.so |
218 |
discFromMinNlc = float((deal.get('minNlc') - (deal.get('available_price'))))/(deal.get('available_price')) *100
|
|
|
219 |
discFromMaxNlc = float((deal.get('maxNlc') - (deal.get('available_price'))))/(deal.get('available_price')) *100
|
| 15182 |
kshitij.so |
220 |
print discFromMinNlc
|
|
|
221 |
print discFromMaxNlc
|
|
|
222 |
if discFromMinNlc > 0:
|
|
|
223 |
nlcPoints = 100/basePointPercentage * discFromMinNlc
|
|
|
224 |
elif discFromMinNlc < 0 and discFromMaxNlc > 0:
|
|
|
225 |
nlcPoints = 0
|
|
|
226 |
else:
|
|
|
227 |
nlcPoints = 100/basePointPercentage * discFromMinNlc
|
|
|
228 |
if (min(nlcPoints,maxNlcPoints)) > 0:
|
|
|
229 |
nlcPoints = (min(nlcPoints,maxNlcPoints)) * eolWeight
|
|
|
230 |
else:
|
|
|
231 |
nlcPoints = (min(nlcPoints,maxNlcPoints))
|
|
|
232 |
|
|
|
233 |
return nlcPoints
|
|
|
234 |
|
| 15166 |
amit.gupta |
235 |
def getLogger(filePath):
|
|
|
236 |
lgr = logging.getLogger()
|
|
|
237 |
lgr.setLevel(logging.DEBUG)
|
|
|
238 |
fh = logging.FileHandler(filePath)
|
|
|
239 |
fh.setLevel(logging.INFO)
|
|
|
240 |
frmt = logging.Formatter('%(asctime)s - %(name)s - %(message)s')
|
|
|
241 |
fh.setFormatter(frmt)
|
|
|
242 |
lgr.addHandler(fh)
|
|
|
243 |
return lgr
|
| 15868 |
kshitij.so |
244 |
|
|
|
245 |
def removePriceFormatting(price_string):
|
|
|
246 |
return price_string.strip().replace('Rs.', '').replace('Rs', '').replace(',', '').replace(' ', '').replace(' ', '').split('.')[0]
|
| 15906 |
kshitij.so |
247 |
|
| 15950 |
kshitij.so |
248 |
def transformUrl(url,source_id):
|
| 15906 |
kshitij.so |
249 |
if source_id == 5:
|
|
|
250 |
finalUrl = urlparse.urlparse(url)
|
|
|
251 |
return finalUrl._replace(netloc=finalUrl.netloc.replace(finalUrl.hostname, 'm.shopclues.com')).geturl()
|
| 15950 |
kshitij.so |
252 |
elif source_id ==1:
|
|
|
253 |
return url
|
|
|
254 |
elif source_id == 2:
|
|
|
255 |
finalUrl = urlparse.urlparse(url)
|
|
|
256 |
return finalUrl._replace(netloc=finalUrl.netloc.replace(finalUrl.hostname, socket.gethostbyname(finalUrl.hostname))).geturl()
|
| 17013 |
manish.sha |
257 |
elif source_id == 7:
|
|
|
258 |
productId = url.split('product:')[1].split('/')[0]
|
|
|
259 |
finalUrl = 'http://m.homeshop18.com/product.mobi?productId='+str(productId)
|
|
|
260 |
return finalUrl
|
| 15906 |
kshitij.so |
261 |
|
|
|
262 |
|
| 16421 |
amit.gupta |
263 |
|
|
|
264 |
|
|
|
265 |
def find_between( s, first, last ):
|
|
|
266 |
try:
|
|
|
267 |
start = s.find( first ) + len( first )
|
|
|
268 |
end = s.rfind( last, start )
|
|
|
269 |
if start ==-1 or end ==-1:
|
|
|
270 |
return ""
|
|
|
271 |
return s[start:end]
|
|
|
272 |
except ValueError:
|
|
|
273 |
return ""
|
| 15950 |
kshitij.so |
274 |
|
| 15906 |
kshitij.so |
275 |
if __name__ == '__main__':
|
| 15950 |
kshitij.so |
276 |
print transformUrl("http://www.flipkart.com/redmi-2/p/itme8ygtcfax6w39",2)
|
| 17233 |
amit.gupta |
277 |
|
|
|
278 |
def sendmail(email, message, title, *varargs):
|
|
|
279 |
if email == "":
|
|
|
280 |
return
|
|
|
281 |
mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
|
|
282 |
mailServer.ehlo()
|
|
|
283 |
mailServer.starttls()
|
|
|
284 |
mailServer.ehlo()
|
| 15906 |
kshitij.so |
285 |
|
| 17233 |
amit.gupta |
286 |
# Create the container (outer) email message.
|
|
|
287 |
msg = MIMEMultipart()
|
|
|
288 |
msg['Subject'] = title
|
|
|
289 |
msg.preamble = title
|
|
|
290 |
html_msg = MIMEText(message, 'html')
|
|
|
291 |
msg.attach(html_msg)
|
| 15906 |
kshitij.so |
292 |
|
| 17233 |
amit.gupta |
293 |
#snapdeal more to be added here
|
|
|
294 |
for fileName in varargs:
|
|
|
295 |
snapdeal = MIMEBase('application', 'vnd.ms-excel')
|
|
|
296 |
snapdeal.set_payload(file(fileName).read())
|
|
|
297 |
encoders.encode_base64(snapdeal)
|
|
|
298 |
snapdeal.add_header('Content-Disposition', 'attachment;filename=' + fileName)
|
|
|
299 |
msg.attach(snapdeal)
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
MAILTO = email
|
|
|
303 |
mailServer.login(SENDER, PASSWORD)
|
|
|
304 |
mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
|
|
|
305 |
|
|
|
306 |
|
| 16561 |
amit.gupta |
307 |
def readSSh(fileName):
|
|
|
308 |
try:
|
|
|
309 |
str1 = open(fileName).read()
|
|
|
310 |
return str1
|
|
|
311 |
except:
|
|
|
312 |
ssh_client = SSHClient()
|
|
|
313 |
str1 = ""
|
|
|
314 |
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
|
315 |
ssh_client.connect('dtr', 22, 'root', 'ecip$dtrMay2014')
|
|
|
316 |
sftp_client = ssh_client.open_sftp()
|
|
|
317 |
try:
|
|
|
318 |
if not os.path.exists(os.path.dirname(fileName)):
|
|
|
319 |
os.makedirs(os.path.dirname(fileName))
|
|
|
320 |
sftp_client.get(fileName, fileName)
|
|
|
321 |
try:
|
|
|
322 |
str1 = open(fileName).read()
|
|
|
323 |
return str1
|
|
|
324 |
finally:
|
|
|
325 |
pass
|
|
|
326 |
except:
|
|
|
327 |
"could not read"
|
|
|
328 |
return str1
|
| 18134 |
kshitij.so |
329 |
|
| 18092 |
manas |
330 |
def encryptMessage(plaintext_to_encrypt1):
|
|
|
331 |
hasher = MD5.new()
|
|
|
332 |
hasher.update(_password)
|
|
|
333 |
hasher.update(_salt)
|
|
|
334 |
result = hasher.digest()
|
|
|
335 |
for i in range(1, _iterations):
|
|
|
336 |
hasher = MD5.new()
|
|
|
337 |
hasher.update(result)
|
|
|
338 |
result = hasher.digest()
|
|
|
339 |
|
|
|
340 |
padding = 8 - len(plaintext_to_encrypt1) % 8
|
|
|
341 |
plaintext_to_encrypt1 += chr(padding) * padding
|
|
|
342 |
encoder = DES.new(result[:8], DES.MODE_CBC, result[8:16])
|
|
|
343 |
encrypted = encoder.encrypt(plaintext_to_encrypt1)
|
|
|
344 |
|
|
|
345 |
check1 = encrypted.encode('base64')
|
|
|
346 |
return check1
|
|
|
347 |
|
|
|
348 |
def decryptMessage(encryptedData):
|
|
|
349 |
padding = 8 - len(encryptedData) % 8
|
|
|
350 |
encryptedData += chr(padding) * padding
|
|
|
351 |
hasher = MD5.new()
|
|
|
352 |
hasher.update(_password)
|
|
|
353 |
hasher.update(_salt)
|
|
|
354 |
result = hasher.digest()
|
|
|
355 |
for i in range(1, _iterations):
|
|
|
356 |
hasher = MD5.new()
|
|
|
357 |
hasher.update(result)
|
|
|
358 |
result = hasher.digest()
|
|
|
359 |
|
|
|
360 |
encoder2 = DES.new(result[:8], DES.MODE_CBC, result[8:16])
|
|
|
361 |
decodeString = encoder2.decrypt(encryptedData.decode('base64'))
|
| 18094 |
manas |
362 |
return ''.join(e for e in decodeString if e.isalnum() or e is '/' or e is ':' or e is ',' or e is '.' or e is '=' or e is '?' or e is '_')
|
| 18092 |
manas |
363 |
|
|
|
364 |
def num_encode(n):
|
|
|
365 |
if n < 0:
|
|
|
366 |
return SIGN_CHARACTER + num_encode(-n)
|
|
|
367 |
s = []
|
|
|
368 |
while True:
|
|
|
369 |
n, r = divmod(n, BASE)
|
|
|
370 |
s.append(ALPHABET[r])
|
|
|
371 |
if n == 0: break
|
|
|
372 |
return ''.join(reversed(s))
|
|
|
373 |
|
|
|
374 |
def num_decode(s):
|
|
|
375 |
if s[0] == SIGN_CHARACTER:
|
|
|
376 |
return -num_decode(s[1:])
|
|
|
377 |
n = 0
|
|
|
378 |
for c in s:
|
|
|
379 |
n = n * BASE + ALPHABET_REVERSE[c]
|
|
|
380 |
return n
|
| 18156 |
amit.gupta |
381 |
|
|
|
382 |
def todict(obj, classkey=None):
|
|
|
383 |
if isinstance(obj, dict):
|
|
|
384 |
data = {}
|
|
|
385 |
for (k, v) in obj.items():
|
|
|
386 |
data[k] = todict(v, classkey)
|
|
|
387 |
return data
|
|
|
388 |
elif hasattr(obj, "_ast"):
|
|
|
389 |
return todict(obj._ast())
|
|
|
390 |
elif hasattr(obj, "__iter__"):
|
|
|
391 |
return [todict(v, classkey) for v in obj]
|
|
|
392 |
elif hasattr(obj, "__dict__"):
|
|
|
393 |
data = dict([(key, todict(value, classkey))
|
|
|
394 |
for key, value in obj.__dict__.iteritems()
|
|
|
395 |
if not callable(value) and not key.startswith('_')])
|
|
|
396 |
if classkey is not None and hasattr(obj, "__class__"):
|
|
|
397 |
data[classkey] = obj.__class__.__name__
|
|
|
398 |
return data
|
|
|
399 |
else:
|
| 18440 |
amit.gupta |
400 |
return obj
|
|
|
401 |
|
|
|
402 |
def getSkuData(storeId, identifier):
|
|
|
403 |
if storeId in (1,2,4,5,6):
|
|
|
404 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier, 'source_id':storeId})
|
|
|
405 |
elif storeId == 3:
|
|
|
406 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier, 'source_id':storeId})
|
|
|
407 |
return skuData
|