| Line 1... |
Line 1... |
| 1 |
'''
|
1 |
'''
|
| 2 |
Created on Jan 15, 2015
|
2 |
Created on Jan 15, 2015
|
| 3 |
|
3 |
|
| 4 |
@author: amit
|
4 |
@author: amit
|
| 5 |
'''
|
5 |
'''
|
| - |
|
6 |
from BeautifulSoup import BeautifulSoup
|
| 6 |
from dtr import main
|
7 |
from dtr import main
|
| 7 |
import importlib
|
8 |
from dtr.dao import AffiliateInfo, Order, SubOrder
|
| 8 |
from dtr.main import getBrowserObject, getStore, ParseException
|
9 |
from dtr.main import getBrowserObject, getStore, ParseException, ungzipResponse, \
|
| 9 |
from dtr.main import sourceMap
|
10 |
Store as MStore, sourceMap
|
| - |
|
11 |
from pprint import pprint
|
| 10 |
from pymongo.mongo_client import MongoClient
|
12 |
from pymongo.mongo_client import MongoClient
|
| - |
|
13 |
import hashlib
|
| 11 |
from BeautifulSoup import BeautifulSoup
|
14 |
import importlib
|
| - |
|
15 |
import json
|
| - |
|
16 |
import mechanize
|
| 12 |
import re
|
17 |
import re
|
| 13 |
from dtr.dao import AffiliateInfo, Order, SubOrder
|
- |
|
| 14 |
import urllib
|
18 |
import urllib
|
| 15 |
|
19 |
|
| 16 |
from pprint import pprint
|
- |
|
| 17 |
USERNAME='saholic1@gmail.com'
|
20 |
USERNAME='saholic1@gmail.com'
|
| 18 |
PASSWORD='spice@2020'
|
21 |
PASSWORD='spice@2020'
|
| 19 |
ORDER_TRACK_URL='https://m.flipkart.com/order_details'
|
22 |
ORDER_TRACK_URL='https://m.flipkart.com/order_details'
|
| 20 |
AFFILIATE_URL='https://www.flipkart.com/affiliate/login'
|
23 |
AFFILIATE_URL='https://www.flipkart.com/affiliate/login'
|
| - |
|
24 |
AFFILIATE_LOGIN_URL='https://www.flipkart.com/affiliate/a_login'
|
| - |
|
25 |
AFF_REPORT_URL='http://www.flipkart.com/affiliate/reports/ordersReport?order_status_filter=%s&startdate=%s&enddate=%s'
|
| - |
|
26 |
AFF_STATUS_CANCELLED='cancelled'
|
| - |
|
27 |
AFF_STATUS_APPROVED='approved'
|
| - |
|
28 |
AFF_STATUS_DISAPPROVED='disapproved'
|
| - |
|
29 |
AFF_STATUS_PENDING='pending'
|
| 21 |
|
30 |
|
| 22 |
|
31 |
|
| 23 |
class Store(main.Store):
|
32 |
class Store(main.Store):
|
| 24 |
OrderStatusMap = {
|
33 |
OrderStatusMap = {
|
| 25 |
main.Store.ORDER_PLACED : ['In Progress','N/A'],
|
34 |
main.Store.ORDER_PLACED : ['Approval', 'Processing'],
|
| 26 |
main.Store.ORDER_DELIVERED : ['Delivered'],
|
35 |
main.Store.ORDER_DELIVERED : ['Shipping'],
|
| 27 |
main.Store.ORDER_SHIPPED : ['In Transit'],
|
36 |
main.Store.ORDER_SHIPPED : ['In Transit'],
|
| 28 |
main.Store.ORDER_CANCELLED : ['Closed For Vendor Reallocation']
|
37 |
main.Store.ORDER_CANCELLED : ['']
|
| 29 |
|
38 |
|
| 30 |
}
|
39 |
}
|
| 31 |
def __init__(self,store_id):
|
40 |
def __init__(self,store_id):
|
| 32 |
client = MongoClient('mongodb://localhost:27017/')
|
41 |
client = MongoClient('mongodb://localhost:27017/')
|
| 33 |
self.db = client.dtr
|
42 |
self.db = client.dtr
|
| 34 |
super(Store, self).__init__(store_id)
|
43 |
super(Store, self).__init__(store_id)
|
| 35 |
|
44 |
|
| 36 |
def getName(self):
|
45 |
def getName(self):
|
| 37 |
return "flipkart"
|
46 |
return "flipkart"
|
| 38 |
|
47 |
|
| - |
|
48 |
def scrapeStoreOrders(self,):
|
| - |
|
49 |
orders = self._getActiveOrders()
|
| - |
|
50 |
|
| 39 |
def scrapeAffiliate(self, startDate=None, endDate=None):
|
51 |
def scrapeAffiliate(self, startDate=None, endDate=None):
|
| 40 |
br = getBrowserObject()
|
52 |
br = getBrowserObject()
|
| 41 |
br.open(AFFILIATE_URL)
|
53 |
br.open(AFFILIATE_URL)
|
| 42 |
print br.select_form(name="fk-signin")
|
54 |
response = br.response() # copy
|
| - |
|
55 |
token = re.findall('window.__FK = "(.*?)"', ungzipResponse(response), re.IGNORECASE)[0]
|
| - |
|
56 |
data = {'__FK':token,
|
| - |
|
57 |
'email':'saholic1@gmail.com',
|
| - |
|
58 |
'password':'e8aacf6fc1e3998186a4a8e56e428f66'
|
| 43 |
|
59 |
}
|
| - |
|
60 |
br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
|
| - |
|
61 |
for status in [AFF_STATUS_CANCELLED, AFF_STATUS_APPROVED, AFF_STATUS_PENDING, AFF_STATUS_DISAPPROVED]:
|
| - |
|
62 |
br.open(AFF_REPORT_URL % (status, '2015-01-02', '2015-02-01'))
|
| - |
|
63 |
page = ungzipResponse(br.response())
|
| - |
|
64 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
| 44 |
|
65 |
try:
|
| - |
|
66 |
tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
|
| - |
|
67 |
except:
|
| - |
|
68 |
continue
|
| - |
|
69 |
trElements = tableElement.findAll('tr')
|
| - |
|
70 |
trElements.pop(0)
|
| - |
|
71 |
for trElement in trElements:
|
| - |
|
72 |
tdElements = trElement.findAll('td')
|
| - |
|
73 |
productCode = re.findall(r'pid=(.*)$', tdElements[0].find('a')['href'])[0]
|
| - |
|
74 |
quantity =int(tdElements[3].text)
|
| - |
|
75 |
price = int(float(tdElements[2].text))
|
| - |
|
76 |
payOut = tdElements[6].text
|
| - |
|
77 |
subTagId = tdElements[7].text
|
| - |
|
78 |
reason = tdElements[9].text
|
| 45 |
|
79 |
|
| 46 |
def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
|
80 |
def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
|
| 47 |
br = getBrowserObject()
|
81 |
br = getBrowserObject()
|
| 48 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', orderSuccessUrl,re.IGNORECASE)[0]
|
82 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', orderSuccessUrl,re.IGNORECASE)[0]
|
| 49 |
|
83 |
|
| 50 |
response = br.open(url)
|
84 |
response = br.open(url)
|
| 51 |
page = ungzipResponse(response, br)
|
85 |
page = ungzipResponse(response)
|
| 52 |
|
86 |
|
| - |
|
87 |
merchantOrderId = re.findall('reference_id=(.*?)&', orderSuccessUrl,re.IGNORECASE)[0]
|
| - |
|
88 |
print merchantOrderId
|
| 53 |
|
89 |
|
| 54 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
90 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
| 55 |
|
91 |
|
| 56 |
sections = soup.findAll("div", {"class":"ui-app-card-body"})
|
92 |
sections = soup.findAll("div", {"class":"ui-app-card-body"})
|
| 57 |
mainOrder = soup.findAll("ul",{"class":"m-bottom p-cart"})
|
- |
|
| 58 |
sections.pop(1)
|
93 |
sections.pop(1)
|
| 59 |
|
94 |
|
| 60 |
#fetching summary of the products
|
95 |
merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl)
|
| 61 |
for data in sections:
|
96 |
for data in sections:
|
| 62 |
name = data.findAll("span")
|
97 |
name = data.findAll("span")
|
| 63 |
i=0
|
98 |
i=0
|
| 64 |
print "Summary Details of Flipkart"
|
- |
|
| 65 |
while i< len(name):
|
99 |
while i< len(name):
|
| 66 |
if "key" in str(name[i]):
|
100 |
if "key" in str(name[i]):
|
| 67 |
if "Grand Total" in str(name[i]):
|
101 |
if "Grand Total" in str(name[i]):
|
| 68 |
#Total Amount
|
102 |
#Total Amount
|
| 69 |
print "Total Amount " + name[i+1].text
|
103 |
merchantOrder.paidAmount = re.findall(r'\d+', name[i+1].text)[0]
|
| 70 |
elif "Status" in str(name[i]):
|
- |
|
| 71 |
print "Summary Status " + name[i+1].text
|
- |
|
| 72 |
elif "Order ID" in str(name[i]):
|
- |
|
| 73 |
j=i+1
|
- |
|
| 74 |
while j < i+5:
|
- |
|
| 75 |
if "value" in str(name[j]):
|
- |
|
| 76 |
print "Order ID " + str(j-i) + " " +name[j].text
|
- |
|
| 77 |
j=j+1
|
- |
|
| 78 |
else:
|
- |
|
| 79 |
break
|
- |
|
| 80 |
elif "Order Date" in str(name[i]):
|
104 |
elif "Order Date" in str(name[i]):
|
| 81 |
print "Order Date " + name[i+1].text
|
105 |
merchantOrder.placedOn = name[i+1].text
|
| 82 |
i=i+1
|
106 |
i=i+1
|
| - |
|
107 |
|
| - |
|
108 |
merchantOrder.merchantOrderId = merchantOrderId
|
| - |
|
109 |
|
| - |
|
110 |
mainOrder = soup.find("ul",{"class":"m-bottom p-cart"})
|
| - |
|
111 |
fkSubOrders = mainOrder.findAll("li")
|
| - |
|
112 |
#remove unwanted list
|
| - |
|
113 |
fkSubOrders.pop(-1)
|
| - |
|
114 |
subOrders = []
|
| 83 |
print "Details of Sub Orders"
|
115 |
merchantOrder.subOrders = subOrders
|
| - |
|
116 |
|
| 84 |
#fetching suborders details
|
117 |
#fetching suborders details
|
| 85 |
for subOrder in mainOrder:
|
118 |
for subOrder in fkSubOrders:
|
| 86 |
subOrd = subOrder.findAll("li")
|
119 |
y = subOrder.find("header").findAll("span")
|
| 87 |
|
120 |
for suborderId in y:
|
| 88 |
subOrd.pop(len(subOrd)-1)
|
121 |
if "value emp" in str(suborderId):
|
| - |
|
122 |
merchantSubOrderId = suborderId.text
|
| 89 |
for productInfo in subOrd:
|
123 |
break
|
| 90 |
y = productInfo.findAll("span")
|
124 |
orderItems = subOrder.find("ul").findAll("div", recursive=False)
|
| 91 |
for suborderId in y:
|
125 |
i=0
|
| 92 |
if "value emp" in str(suborderId):
|
126 |
for orderItem in orderItems:
|
| 93 |
#Sub Order ID
|
127 |
merchantOrder.placedOn
|
| 94 |
print "Sub Order ID" + suborderId.text
|
128 |
merchantSubOrderId = merchantSubOrderId + str(i)
|
| 95 |
g = productInfo.findAll("div",{"class":"product-image-block"})
|
129 |
divs = orderItem.findAll('div', recursive=False)
|
| 96 |
for imageUrl in g:
|
130 |
content = divs[0]
|
| 97 |
print str(imageUrl.find("img")['src'])
|
131 |
orderTracking = divs[2]
|
| 98 |
x = productInfo.findAll("div",{"class":"product-info"})
|
132 |
orderTrackingDet = divs[3]
|
| 99 |
for maik in x:
|
133 |
|
| 100 |
#Product title
|
134 |
|
| - |
|
135 |
imgUrl = content.find('img')['src']
|
| - |
|
136 |
lineDet = content.find("div",{"class":"product-info"})
|
| 101 |
print maik.find("a",{"class":"product-title"}).text
|
137 |
productTitle = lineDet.find("a",{"class":"product-title"}).text
|
| 102 |
print str(maik.find("a")['href'])
|
138 |
productUrl = str(lineDet.find("a")['href'])
|
| - |
|
139 |
|
| 103 |
start='pid='
|
140 |
start='pid='
|
| 104 |
s=str(maik.find("a")['href'])
|
141 |
s=str(lineDet.find("a")['href'])
|
| 105 |
print re.findall(re.escape(start)+"(.*)",s)[0]
|
142 |
productCode = re.findall(re.escape(start)+"(.*)",s)[0]
|
| 106 |
mname = maik.findAll("span")
|
143 |
mname = lineDet.findAll("span")
|
| 107 |
k=0
|
144 |
k=0
|
| 108 |
while k<len(mname):
|
145 |
while k<len(mname):
|
| 109 |
if "note" in str(mname[k]):
|
146 |
if "note" in str(mname[k]):
|
| 110 |
if "Color:" in str(mname[k]):
|
147 |
if "Color:" in str(mname[k]):
|
| - |
|
148 |
productTitle = productTitle + " " + mname[k+1].text
|
| 111 |
#Color
|
149 |
|
| 112 |
print "Color " + mname[k+1].text
|
150 |
elif "Qty:" in str(mname[k]):
|
| 113 |
elif "Qty:" in str(mname[k]):
|
151 |
quantity = int(mname[k+1].text)
|
| 114 |
#Quantity of sub item
|
152 |
elif "Subtotal:" in str(mname[k]):
|
| 115 |
print "Quantity "+mname[k+1].text
|
153 |
amountPaid = re.findall(r'\d+', mname[k+1].text)[0]
|
| 116 |
elif "Subtotal:" in str(mname[k]):
|
154 |
elif "Delivery:" in str(mname[k]):
|
| 117 |
#SubTotal for the item
|
155 |
#Delivery Date for sub order
|
| 118 |
print "Sub Total"+mname[k+1].text
|
156 |
print "Delivery Date " +mname[k+1].text
|
| - |
|
157 |
k=k+1
|
| - |
|
158 |
merchantsubOrder = SubOrder(productTitle, productUrl, merchantOrder.placedOn, amountPaid,MStore.ORDER_PLACED, quantity)
|
| 119 |
elif "Delivery:" in str(mname[k]):
|
159 |
merchantsubOrder.imgUrl = imgUrl
|
| 120 |
#Delivery Date for sub order
|
160 |
merchantsubOrder.productCode = productCode
|
| - |
|
161 |
|
| 121 |
print "Delivery Date " +mname[k+1].text
|
162 |
cashbackAmount = self.getCashbackAmount(subOrder.productCode, amountPaid)
|
| 122 |
if "key text-dim" in str(mname[k]):
|
163 |
cashbackStatus = Store.CB_INIT
|
| - |
|
164 |
if cashbackAmount <= 0:
|
| 123 |
if "Seller" in str(mname[k]):
|
165 |
cashbackStatus = Store.CB_NA
|
| 124 |
print "Seller URL : http://m.flipkart.com"+maik.findAll("a")[1]['href']
|
166 |
merchantsubOrder.cashBackAmount = cashbackAmount
|
| 125 |
print "Seller "+maik.findAll("a")[1].text
|
167 |
merchantsubOrder.cashBackStatus = cashbackStatus
|
| 126 |
k=k+1
|
168 |
|
| 127 |
status=-1
|
169 |
subOrders.append(merchantsubOrder)
|
| 128 |
#To track shipping details
|
170 |
#To track shipping details
|
| 129 |
n = productInfo.findAll("div",{"class":"tracking-progress grid-row cf"})
|
- |
|
| 130 |
for trackingStatus in n:
|
171 |
status=-1
|
| 131 |
tr = trackingStatus.findAll("div",{"class":"tap-bullet-area c-tab-trigger"})
|
172 |
tr = orderTracking.findAll("div",{"class":"tap-bullet-area c-tab-trigger"})
|
| 132 |
if "approveDetails-complete" in str(tr):
|
173 |
if "approveDetails-complete" in str(tr):
|
| 133 |
if "processingDetails-complete" in str(tr):
|
174 |
if "processingDetails-complete" in str(tr):
|
| 134 |
if "shippingDetails-complete" in str(tr):
|
175 |
if "shippingDetails-complete" in str(tr):
|
| 135 |
if "delivery-complete" in str(tr):
|
176 |
if "delivery-complete" in str(tr):
|
| 136 |
status = 3
|
177 |
status = MStore.ORDER_DELIVERED
|
| 137 |
else:
|
178 |
else:
|
| 138 |
status = 2
|
179 |
status = MStore.ORDER_SHIPPED
|
| 139 |
else:
|
180 |
else:
|
| 140 |
status = 1
|
181 |
status = MStore.ORDER_PLACED
|
| 141 |
else:
|
182 |
else:
|
| 142 |
status = 0
|
183 |
status = MStore.ORDER_PLACED
|
| 143 |
elif "approveDetails-ongoing" in str(tr):
|
184 |
elif str(tr) in ["approveDetails-ongoing"]:
|
| 144 |
status=0
|
185 |
status=MStore.ORDER_PLACED
|
| 145 |
if "dead" in str(tr):
|
186 |
if "dead" in str(tr):
|
| 146 |
status = 4
|
187 |
status = MStore.ORDER_CANCELLED
|
| 147 |
print "Sub Order Status " + str(status)
|
188 |
print "Sub Order Status " + str(status)
|
| 148 |
f = productInfo.findAll("div",{"class":"c-tabs-content m-top active"})
|
- |
|
| 149 |
for trackingDetailsActive in f:
|
- |
|
| 150 |
print "Sub order tracking description " + trackingDetailsActive.text
|
- |
|
| 151 |
|
189 |
|
| - |
|
190 |
trackingDetailsActive = orderTrackingDet.find("div",{"class":"c-tabs-content m-top active"})
|
| - |
|
191 |
print "Sub order tracking description " + trackingDetailsActive.text
|
| - |
|
192 |
self._saveToOrder(todict(merchantOrder))
|
| 152 |
|
193 |
|
| 153 |
def flipkartOrderTracking(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
|
194 |
def flipkartOrderTracking(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
|
| 154 |
br = getBrowserObject()
|
195 |
br = getBrowserObject()
|
| 155 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', orderSuccessUrl,re.IGNORECASE)[0]
|
196 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', orderSuccessUrl,re.IGNORECASE)[0]
|
| 156 |
|
197 |
|
| Line 196... |
Line 237... |
| 196 |
|
237 |
|
| 197 |
def _saveToOrderFlipkart(self, order):
|
238 |
def _saveToOrderFlipkart(self, order):
|
| 198 |
collection = self.db.merchantOrder
|
239 |
collection = self.db.merchantOrder
|
| 199 |
order = collection.insert(order)
|
240 |
order = collection.insert(order)
|
| 200 |
|
241 |
|
| - |
|
242 |
|
| - |
|
243 |
|
| - |
|
244 |
def hex_md5(password):
|
| - |
|
245 |
m = hashlib.md5()
|
| - |
|
246 |
print(m.digest())
|
| - |
|
247 |
|
| 201 |
def main():
|
248 |
def main():
|
| 202 |
|
249 |
|
| 203 |
store = getStore(2)
|
250 |
store = getStore(2)
|
| 204 |
store.scrapeAffiliate()
|
251 |
#store.scrapeAffiliate()
|
| - |
|
252 |
store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3019717576543723&token=14abca87835b66da4ce8fa9d7594d95f&src=or&pr=1')
|
| 205 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
|
253 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
|
| 206 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
|
254 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
|
| 207 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
255 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
| 208 |
#store.flipkartOrderTracking(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
256 |
#store.flipkartOrderTracking(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
| 209 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019365336126533&token=dbce2bd4dc4023295b436a7d3c7986c9&src=or&pr=1')
|
257 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019365336126533&token=dbce2bd4dc4023295b436a7d3c7986c9&src=or&pr=1')
|
| 210 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://dl.flipkart.com/orderresponse?reference_id=OD1019453634552336&token=e8e04871ad65b532aa53fa82bb34b901&src=or&pr=1')
|
258 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://dl.flipkart.com/orderresponse?reference_id=OD1019453634552336&token=e8e04871ad65b532aa53fa82bb34b901&src=or&pr=1')
|
| - |
|
259 |
#hex_md5('spice@2020')
|
| - |
|
260 |
|
| 211 |
|
261 |
|
| 212 |
def ungzipResponse(r,b):
|
- |
|
| 213 |
headers = r.info()
|
- |
|
| 214 |
if headers['Content-Encoding']=='gzip':
|
- |
|
| 215 |
import gzip
|
- |
|
| 216 |
print "********************"
|
- |
|
| 217 |
print "Deflating gzip response"
|
- |
|
| 218 |
print "********************"
|
- |
|
| 219 |
gz = gzip.GzipFile(fileobj=r, mode='rb')
|
- |
|
| 220 |
html = gz.read()
|
- |
|
| 221 |
gz.close()
|
- |
|
| 222 |
return html
|
- |
|
| 223 |
|
- |
|
| 224 |
if __name__ == '__main__':
|
262 |
if __name__ == '__main__':
|
| 225 |
main()
|
263 |
main()
|
| 226 |
|
264 |
|
| - |
|
265 |
|
| - |
|
266 |
|
| - |
|
267 |
|
| 227 |
def todict(obj, classkey=None):
|
268 |
def todict(obj, classkey=None):
|
| 228 |
if isinstance(obj, dict):
|
269 |
if isinstance(obj, dict):
|
| 229 |
data = {}
|
270 |
data = {}
|
| 230 |
for (k, v) in obj.items():
|
271 |
for (k, v) in obj.items():
|
| 231 |
data[k] = todict(v, classkey)
|
272 |
data[k] = todict(v, classkey)
|
| Line 240... |
Line 281... |
| 240 |
if not callable(value) and not key.startswith('_')])
|
281 |
if not callable(value) and not key.startswith('_')])
|
| 241 |
if classkey is not None and hasattr(obj, "__class__"):
|
282 |
if classkey is not None and hasattr(obj, "__class__"):
|
| 242 |
data[classkey] = obj.__class__.__name__
|
283 |
data[classkey] = obj.__class__.__name__
|
| 243 |
return data
|
284 |
return data
|
| 244 |
else:
|
285 |
else:
|
| 245 |
return obj
|
- |
|
| 246 |
|
286 |
return obj
|
| - |
|
287 |
|
| - |
|
288 |
|