本文整理汇总了Python中melisdk.meli.Meli.get方法的典型用法代码示例。如果您正苦于以下问题:Python Meli.get方法的具体用法?Python Meli.get怎么用?Python Meli.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类melisdk.meli.Meli
的用法示例。
在下文中一共展示了Meli.get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: product_get_meli_loginstate
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def product_get_meli_loginstate( self, cr, uid, ids, field_name, attributes, context=None ):
# recoger el estado y devolver True o False (meli)
#False if logged ok
#True if need login
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
ML_state = False
if ACCESS_TOKEN=='':
ML_state = True
else:
response = meli.get("/users/me/", {'access_token':meli.access_token} )
rjson = response.json()
if 'error' in rjson:
if rjson['message']=='invalid_token' or rjson['message']=='expired_token':
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
ML_state = True
#raise osv.except_osv( _('MELI WARNING'), _('INVALID TOKEN (must login, go to Edit Company and login): error: %s, message: %s, status: %s') % ( rjson["error"], rjson["message"],rjson["status"],))
res = {}
for product in self.browse(cr,uid,ids):
res[product.id] = ML_state
return res
示例2: product_get_meli_status
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def product_get_meli_status( self, cr, uid, ids, field_name, attributes, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
warningobj = self.pool.get('warning')
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
ML_status = "unknown"
if ACCESS_TOKEN=='':
ML_status = "unknown"
else:
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
if product.meli_id:
response = meli.get("/items/"+product.meli_id, {'access_token':meli.access_token} )
rjson = response.json()
ML_status = rjson["status"]
if "error" in rjson:
ML_status = rjson["error"]
if "sub_status" in rjson:
if len(rjson["sub_status"]) and rjson["sub_status"][0]=='deleted':
product.write({ 'meli_id': '' })
res = {}
for product in self.browse(cr,uid,ids):
res[product.id] = ML_status
return res
示例3: orders_update_order
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def orders_update_order( self, cr, uid, id, context=None ):
#get with an item id
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
order_obj = self.pool.get('mercadolibre.orders')
order_items_obj = self.pool.get('mercadolibre.order_items')
order = order_obj.browse(cr, uid, id )
log_msg = 'orders_update_order: %s' % (order.order_id)
_logger.info(log_msg)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
#
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN )
response = meli.get("/orders/"+order.order_id, {'access_token':meli.access_token})
order_json = response.json()
#_logger.info( product_json )
if "error" in order_json:
_logger.error( order_json["error"] )
_logger.error( order_json["message"] )
else:
self.orders_update_order_json( cr, uid, {"id": id, "order_json": order_json } )
return {}
示例4: get_meli_state
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def get_meli_state( self, cr, uid, ids, field_name, attributes, context=None ):
# recoger el estado y devolver True o False (meli)
#False if logged ok
#True if need login
print 'company get_meli_state() '
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
warningobj = self.pool.get('warning')
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
ML_state = False
try:
response = meli.get("/items/MLA1", {'access_token':meli.access_token} )
print "response.content:", response.content
rjson = response.json()
#response = meli.get("/users/")
if "error" in rjson:
if "message" in rjson and rjson["message"]=="expired_token":
ML_state = True
if ACCESS_TOKEN=='':
ML_state = True
except requests.exceptions.ConnectionError as e:
#raise osv.except_osv( _('MELI WARNING'), _('NO INTERNET CONNECTION TO API.MERCADOLIBRE.COM: complete the Cliend Id, and Secret Key and try again'))
ML_state = True
error_msg = 'MELI WARNING: NO INTERNET CONNECTION TO API.MERCADOLIBRE.COM: complete the Cliend Id, and Secret Key and try again '
_logger.error(error_msg)
# except requests.exceptions.HTTPError as e:
# print "And you get an HTTPError:", e.message
if ML_state:
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
res = {}
for company in self.browse(cr,uid,ids):
res[company.id] = ML_state
return res
示例5: index
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def index(self):
cr, uid, context = request.cr, request.uid, request.context
company = request.registry.get('res.company').browse(cr,uid,1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
if (ACCESS_TOKEN==''):
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
return "<a href='"+meli.auth_url(redirect_URI=REDIRECT_URI)+"'>Login</a>"
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
response = meli.get("/items/MLA533830652")
return "MercadoLibre for Odoo 8 - Moldeo Interactive: %s " % response.content
示例6: product_meli_get_product
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def product_meli_get_product( self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
response = meli.get("/items/"+product.meli_id, {'access_token':meli.access_token})
#print "product_meli_get_product: " + response.content
return {}
示例7: orders_query_iterate
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def orders_query_iterate( self, cr, uid, offset=0, context=None ):
offset_next = 0
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
orders_obj = self.pool.get('mercadolibre.orders')
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
#
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN )
orders_query = "/orders/search?seller="+company.mercadolibre_seller_id+"&sort=date_desc"
if (offset):
orders_query = orders_query + "&offset="+str(offset).strip()
response = meli.get( orders_query, {'access_token':meli.access_token})
orders_json = response.json()
if "error" in orders_json:
_logger.error( orders_query )
_logger.error( orders_json["error"] )
if (orders_json["message"]=="invalid_token"):
_logger.error( orders_json["message"] )
return {}
_logger.info( orders_json )
#testing with json:
if (True==False):
with open('/home/fabricio/envOdoo8/sources/meli_oerp/orders.json') as json_data:
_logger.info( json_data )
orders_json = json.load(json_data)
_logger.info( orders_json )
if "paging" in orders_json:
if "total" in orders_json["paging"]:
if (orders_json["paging"]["total"]==0):
return {}
else:
if (orders_json["paging"]["total"]==orders_json["paging"]["limit"]):
offset_next = offset + orders_json["paging"]["limit"]
if "results" in orders_json:
for order_json in orders_json["results"]:
if order_json:
self.orders_update_order_json( cr, uid, {"id": False, "order_json": order_json} )
if (offset_next>0):
self.orders_query_iterate(cr,uid,offset_next)
return {}
示例8: product_post
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def product_post(self, cr, uid, ids, context=None):
product_ids = context['active_ids']
product_obj = self.pool.get('product.product')
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
#user_obj.company_id.meli_login()
company = user_obj.company_id
warningobj = self.pool.get('warning')
#company = self.pool.get('res.company').browse(cr,uid,1)
REDIRECT_URI = company.mercadolibre_redirect_uri
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
if ACCESS_TOKEN=='':
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",
}
for product_id in product_ids:
product = product_obj.browse(cr,uid,product_id)
if (product.meli_id):
response = meli.get("/items/%s" % product.meli_id, {'access_token':meli.access_token})
# print product.meli_category.meli_category_id
if product.meli_title==False:
# print 'Assigning title: product.meli_title: %s name: %s' % (product.meli_title, product.name)
product.meli_title = product.name
if product.meli_price==False:
# print 'Assigning price: product.meli_price: %s standard_price: %s' % (product.meli_price, product.standard_price)
product.meli_price = product.standard_price
body = {
"title": product.meli_title or '',
"description": product.meli_description or '',
"category_id": product.meli_category.meli_category_id or '0',
"listing_type_id": product.meli_listing_type or '0',
"buying_mode": product.meli_buying_mode or '',
"price": product.meli_price or '0',
"currency_id": product.meli_currency or '0',
#"condition": product.meli_condition or '',
"available_quantity": product.meli_available_quantity or '0',
"warranty": product.meli_warranty or '',
#"pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or '',
}
#print "product.meli_id before setting condigions ]"+product.meli_id+"["
if (len(product.meli_id)==0):
body["condition"] = product.meli_condition;
# print body
assign_img = False and product.meli_id
#publicando imagen cargada en OpenERP
if product.image==None:
return warningobj.info(cr, uid, title='MELI WARNING', message="Debe cargar una imagen de base en el producto.", message_html="" )
elif product.meli_imagen_id==False:
# print "try uploading image..."
resim = product.product_meli_upload_image()
if "status" in resim:
if (resim["status"]=="error" or resim["status"]=="warning"):
error_msg = 'MELI: mensaje de error: ', resim
_logger.error(error_msg)
else:
assign_img = True and product.meli_imagen_id
#modificando datos si ya existe el producto en MLA
if (product.meli_id):
body = {
"title": product.meli_title or '',
#"description": product.meli_description or '',
#"category_id": product.meli_category.meli_category_id,
#"listing_type_id": product.meli_listing_type,
#"buying_mode": product.meli_buying_mode or '',
"price": product.meli_price or '0',
#"currency_id": product.meli_currency,
#"condition": product.meli_condition or '',
"available_quantity": product.meli_available_quantity or '0',
"warranty": product.meli_warranty or '',
"pictures": [],
#"pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or '',
}
#publicando multiples imagenes
#.........这里部分代码省略.........
示例9: product_post
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def product_post(self, cr, uid, ids, context=None):
product_ids = context["active_ids"]
product_obj = self.pool.get("product.product")
user_obj = self.pool.get("res.users").browse(cr, uid, uid)
# user_obj.company_id.meli_login()
company = user_obj.company_id
warningobj = self.pool.get("warning")
# company = self.pool.get('res.company').browse(cr,uid,1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(
client_id=CLIENT_ID, client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN
)
if ACCESS_TOKEN == "":
meli = Meli(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
return {"type": "ir.actions.act_url", "url": url_login_meli, "target": "new"}
for product_id in product_ids:
product = product_obj.browse(cr, uid, product_id)
if product.meli_id:
response = meli.get("/items/%s" % product.meli_id, {"access_token": meli.access_token})
# print product.meli_category.meli_category_id
if product.meli_title == False:
# print 'Assigning title: product.meli_title: %s name: %s' % (product.meli_title, product.name)
product.meli_title = product.name
if product.meli_price == False:
# print 'Assigning price: product.meli_price: %s standard_price: %s' % (product.meli_price, product.standard_price)
product.meli_price = product.standard_price
body = {
"title": product.meli_title or "",
"description": product.meli_description or "",
"category_id": product.meli_category.meli_category_id or "0",
"listing_type_id": product.meli_listing_type or "0",
"buying_mode": product.meli_buying_mode or "",
"price": product.meli_price or "0",
"currency_id": product.meli_currency or "0",
"condition": product.meli_condition or "",
"available_quantity": product.meli_available_quantity or "0",
"warranty": product.meli_warranty or "",
# "pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or "",
}
# print body
assign_img = False and product.meli_id
# publicando imagen cargada en OpenERP
if product.image == None:
return warningobj.info(
cr,
uid,
title="MELI WARNING",
message="Debe cargar una imagen de base en el producto.",
message_html="",
)
elif product.meli_imagen_id == False:
# print "try uploading image..."
resim = product.product_meli_upload_image()
if "status" in resim:
if resim["status"] == "error" or resim["status"] == "warning":
error_msg = "MELI: mensaje de error: ", resim
_logger.error(error_msg)
else:
assign_img = True and product.meli_imagen_id
# modificando datos si ya existe el producto en MLA
if product.meli_id:
body = {
"title": product.meli_title or "",
# "description": product.meli_description or '',
# "category_id": product.meli_category.meli_category_id,
# "listing_type_id": product.meli_listing_type,
"buying_mode": product.meli_buying_mode or "",
"price": product.meli_price or "0",
# "currency_id": product.meli_currency,
"condition": product.meli_condition or "",
"available_quantity": product.meli_available_quantity or "0",
"warranty": product.meli_warranty or "",
"pictures": [],
# "pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or "",
}
# publicando multiples imagenes
multi_images_ids = {}
#.........这里部分代码省略.........
示例10: product_meli_get_products
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def product_meli_get_products( self, cr, uid, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
#product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
#url_login_oerp = "/meli_login"
results = []
response = meli.get("/users/"+company.mercadolibre_seller_id+"/items/search", {'access_token':meli.access_token,'offset': 0 })
#response = meli.get("/sites/MLA/search?seller_id="+company.mercadolibre_seller_id+"&limit=0", {'access_token':meli.access_token})
rjson = response.json()
_logger.info( rjson )
results = rjson['results']
if 'error' in rjson:
if rjson['message']=='invalid_token' or rjson['message']=='expired_token':
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",}
#download?
if (rjson['paging']['total']>rjson['paging']['limit']):
pages = rjson['paging']['total']/rjson['paging']['limit']
ioff = rjson['paging']['limit']
condition_last_off = False
while (condition_last_off!=True):
response = meli.get("/users/"+company.mercadolibre_seller_id+"/items/search", {'access_token':meli.access_token,'offset': ioff })
rjson2 = response.json()
if 'error' in rjson2:
if rjson2['message']=='invalid_token' or rjson2['message']=='expired_token':
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
condition = True
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",}
else:
results += rjson2['results']
ioff+= rjson['paging']['limit']
condition_last_off = ( ioff>=rjson['paging']['total'])
_logger.info( rjson )
_logger.info( "("+str(rjson['paging']['total'])+") products to check...")
iitem = 0
if (results):
for item_id in results:
print item_id
iitem+= 1
_logger.info( item_id + "("+str(iitem)+"/"+str(rjson['paging']['total'])+")" )
posting_id = self.pool.get('product.product').search(cr,uid,[('meli_id','=',item_id)])
response = meli.get("/items/"+item_id, {'access_token':meli.access_token})
rjson3 = response.json()
if (posting_id):
_logger.info( "Item already in database: " + str(posting_id[0]) )
#print "Item already in database: " + str(posting_id[0])
else:
idcreated = self.pool.get('product.product').create(cr,uid,{ 'name': rjson3['title'], 'meli_id': rjson3['id'] })
#idcreated = self.pool.get('product.product').create(cr,uid,{ 'name': rjson3['id'], 'description': rjson3['title'], 'meli_id': rjson3['id'] })
if (idcreated):
_logger.info( "product created: " + str(rjson3['id']) + "-" + str( rjson3['title']) )
product = product_obj.browse(cr, uid, idcreated)
product_obj.product_meli_get_product( cr, uid, [idcreated] )
return {}
示例11: product_meli_get_product
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def product_meli_get_product( self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
product_template_obj = self.pool.get('product.template')
product_template = product_template_obj.browse(cr, uid, product.product_tmpl_id.id)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
response = meli.get("/items/"+product.meli_id, {'access_token':meli.access_token})
print "product_meli_get_product: " + response.content
rjson = response.json()
des = ''
desplain = ''
vid = ''
if 'error' in rjson:
return {}
#TODO: traer la descripcion: con
#https://api.mercadolibre.com/items/{ITEM_ID}/description?access_token=$ACCESS_TOKEN
if rjson['descriptions']:
response2 = meli.get("/items/"+product.meli_id+"/description", {'access_token':meli.access_token})
rjson2 = response2.json()
des = rjson2['text']
desplain = rjson2['plain_text']
if (len(des)>0):
desplain = des
#TODO: verificar q es un video
if rjson['video_id']:
vid = ''
#TODO: traer las imagenes
#TODO:
pictures = rjson['pictures']
if pictures and len(pictures):
thumbnail_url = pictures[0]['url']
image = urllib2.urlopen(thumbnail_url).read()
image_base64 = base64.encodestring(image)
product.image_medium = image_base64
#if (len(pictures)>1):
#complete product images:
#delete all images...
#categories
mlcatid = ""
if ('category_id' in rjson):
category_id = rjson['category_id']
ml_cat_id = self.pool.get('mercadolibre.category').search(cr,uid,[('meli_category_id','=',category_id)])
if (ml_cat_id):
print "category exists!" + str(ml_cat_id)
mlcatid = ml_cat_id[0]
else:
print "Creating category: " + str(category_id)
#https://api.mercadolibre.com/categories/MLA1743
response_cat = meli.get("/categories/"+str(category_id), {'access_token':meli.access_token})
rjson_cat = response_cat.json()
print "category:" + str(rjson_cat)
fullname = ""
if ("path_from_root" in rjson_cat):
path_from_root = rjson_cat["path_from_root"]
for path in path_from_root:
fullname = fullname + "/" + path["name"]
#fullname = fullname + "/" + rjson_cat['name']
print "category fullname:" + fullname
cat_fields = {
'name': fullname,
'meli_category_id': ''+str(category_id),
}
ml_cat_id = self.pool.get('mercadolibre.category').create(cr,uid,(cat_fields))
if (ml_cat_id):
mlcatid = ml_cat_id
imagen_id = ''
if (len(rjson['pictures'])>0):
imagen_id = rjson['pictures'][0]['id']
meli_fields = {
'name': str(rjson['title']),
'meli_imagen_id': imagen_id,
'meli_post_required': True,
'meli_id': rjson['id'],
'meli_permalink': rjson['permalink'],
'meli_title': rjson['title'],
'meli_description': desplain,
# 'meli_description_banner_id': ,
'meli_category': mlcatid,
'meli_listing_type': rjson['listing_type_id'],
'meli_buying_mode':rjson['buying_mode'],
'meli_price': str(rjson['price']),
#.........这里部分代码省略.........
示例12: posting_query_questions
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import get [as 别名]
def posting_query_questions( self, cr, uid, id, context=None ):
#get with an item id
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
posting_obj = self.pool.get('mercadolibre.posting')
posting = posting_obj.browse(cr, uid, id )
log_msg = 'posting_query_questions: %s' % (posting.meli_id)
_logger.info(log_msg)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
#
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN )
response = meli.get("/items/"+posting.meli_id, {'access_token':meli.access_token})
product_json = response.json()
#_logger.info( product_json )
if "error" in product_json:
ML_status = product_json["error"]
else:
ML_status = product_json["status"]
ML_permalink = product_json["permalink"]
ML_price = product_json["price"]
posting.write( { 'meli_status': ML_status, 'meli_permalink': ML_permalink, 'meli_price': ML_price } )
response = meli.get("/questions/search?item_id="+posting.meli_id, {'access_token':meli.access_token})
questions_json = response.json()
#_logger.info( questions_json )
questions_obj = self.pool.get('mercadolibre.questions')
if 'questions' in questions_json:
questions = questions_json['questions']
_logger.info( questions )
cn = 0
for Question in questions:
cn = cn + 1
_logger.info(cn)
_logger.info(Question )
#{
# 'status': u'UNANSWERED',
# 'seller_id': 171319838,
# 'from': {
# 'answered_questions': 0,
# 'id': 171329758
# },
# 'deleted_from_listing': False,
# 'text': 'Pregunta que hago para testear el m\xf3dulo de meli_oerp en Odoo....??',
# 'answer': None,
# 'item_id': u'MLA548679961',
# 'date_created': '2015-03-04T12:04:48.000-04:00',
# 'hold': False,
# 'id': 3471012014
#}
##{
# 'status': 'ACTIVE',
# 'text': 'Ok recibiose la pregunta correctamente, ahora viendo si sale esta respuesta! Saludos\nMas saludos',
# 'date_created': '2015-03-04T13:00:53.000-04:00'
#}
question_answer = Question['answer']
question_fields = {
'posting_id': posting.id,
'question_id': Question['id'],
'date_created': Question['date_created'],
'item_id': Question['item_id'],
'seller_id': Question['seller_id'],
'text': Question['text'],
'status': Question['status'],
}
if (question_answer):
question_fields['answer_text'] = question_answer['text']
question_fields['answer_status'] = question_answer['status']
question_fields['answer_date_created'] = question_answer['date_created']
question_fetch_ids = questions_obj.search(cr,uid,[('question_id','=',question_fields['question_id'])])
if not question_fetch_ids:
question_fetch_ids = questions_obj.create(cr,uid,( question_fields ))
else:
questions_obj.write(cr,uid, question_fetch_ids[0], ( question_fields ) )
return {}