Tout nouveau sur le blog du développement Python !
J’ai donc essayer d’interagir avec l’API Webservice de PrestaShop pour dans un certain futur le connecter avec PrestaShop!
J’ai donc utilise une bibliothèque Python “Prestapyt” afin de me connecter 😉
Personnellement je commence en Python donc soyez gentil si je ne gère pas encore les exceptions 🙂
from prestapyt import PrestaShopWebServiceDict , PrestaShopWebServiceDict from pprint import pprint prestashop = PrestaShopWebServiceDict( 'http://localhost:8888/api', 'G4UZ2FBPSJUZE1TJCC94AJEF64VAKMFI', ) prestashop.debug = False #pprint(prestashop.get('')) #pprint(prestashop.head('')) #pprint(prestashop.get('addresses', 2)) print "" print "GET PRODUCT 1" print "=============" product_data = prestashop.get('products', 1) print 'Name : {}' .format(product_data['product']['name']['language']['value']) print 'Price : {}' .format(product_data['product']['price']) print 'Weight : {}' .format(product_data['product']['weight']) print 'Manufacturer_name : {}' .format(product_data['product']['manufacturer_name']['value']) print "" print "" print "GET ALL PRODUCTS" print "================" products_data= prestashop.get('products') print "================" for product_data in products_data['products']['product']: id = product_data['attrs']['id'] if id<'9': print "" print "GET PRODUCT {}" .format(product_data['attrs']['id']) print "=============" product_data = prestashop.get('products', id) print 'Name : {}' .format(product_data['product']['name']['language']['value']) print 'Price : {}' .format(product_data['product']['price']) print 'Weight : {}' .format(product_data['product']['weight']) print 'Manufacturer_name : {}' .format(product_data['product']['manufacturer_name']['value']) print "" print "" print "UPDATE ONE EMPLOYEES" print "====================" employee_data = prestashop.get('employees', 1) #print employee_data employee_data['employee']['lastname'] = 'TOTO' #print employee_data prestashop.edit('employees', 1, employee_data)
Et voilà !