def connect(self): """ Connects to the API and the GDR DB """ # GDR connection self.i_log.add("Connexion à la BDD GDR") if self.gdr_db.connect(self.dsn): self.i_log.add("Connexion réussie") else: self.i_log.add("Connexion échouée") # Api connection self.i_log.add("Connexion à l'API") self.api = PrestaShopWebServiceDict(self.ip, self.key) try: self.api.get('') self.i_log.add("Connexion réussie") # PrestaShopAuthentificationError inherits of PrestaShopWebServiceError except PrestaShopAuthenticationError as PSAuthErr: self.i_log.add(f"Authentification échouée : {PSAuthErr}") except PrestaShopWebServiceError as PSWebServiceErr: self.i_log.add(f"Connexion échouée : {PSWebServiceErr}")
def connect(token: str): try: ps = PrestaShopWebServiceDict('https://caneva937.com/api', token) return ps except: print("[E] Errore collegamento a prestashop") exit(1)
def search(self, filters=None): api = PrestaShopWebServiceDict(self.prestashop.api_url, self.prestashop.webservice_key) res = api.get(self._prestashop_model, options=filters) methods = res[self._prestashop_model][self._export_node_name] if isinstance(methods, dict): return [methods] return methods
def search(self, filters=None): result = super(SaleOrderAdapter, self).search(filters=filters) shops = self.env['prestashop.shop'].search([('backend_id', '=', self.backend_record.id)]) for shop in shops: if not shop.default_url: continue api = PrestaShopWebServiceDict('%s/api' % shop.default_url, self.prestashop.webservice_key) result += api.search(self._prestashop_model, filters) return result
def connect(self): # Add parameter to debug # https://github.com/akretion/prestapyt/blob/master/prestapyt/prestapyt.py#L81 _logger.info( "Connect to %s with apikey %s in debug mode %s and \ timeout %s", self.prestashop.api_url, self.prestashop.webservice_key, str(self.prestashop.api_debug), str(self.prestashop.api_timeout)) return PrestaShopWebServiceDict( self.prestashop.api_url, self.prestashop.webservice_key, self.prestashop.api_debug, None, {'timeout': self.prestashop.api_timeout})
def export_quantity_url(self, url, key, filters, quantity): api = PrestaShopWebServiceDict(url, key) response = api.search(self._prestashop_model, filters) for stock_id in response: res = api.get(self._prestashop_model, stock_id) first_key = res.keys()[0] stock = res[first_key] stock['quantity'] = int(quantity) try: api.edit(self._prestashop_model, {self._export_node_name: stock}) except ElementTree.ParseError: pass
def __init__(self, environment): """ :param environment: current environment (backend, session, ...) :type environment: :py:class:`connector.connector.ConnectorEnvironment` """ super(PrestaShopCRUDAdapter, self).__init__(environment) self.prestashop = PrestaShopLocation( self.backend_record.location.encode(), self.backend_record.webservice_key) self.client = PrestaShopWebServiceDict( self.prestashop.api_url, self.prestashop.webservice_key, )
def export_quantity(self, filters, quantity): self.export_quantity_url( filters, quantity, ) shops = self.env['prestashop.shop'].search([ ('backend_id', '=', self.backend_record.id), ('default_url', '!=', False), ]) for shop in shops: url = '%s/api' % shop.default_url key = self.backend_record.webservice_key client = PrestaShopWebServiceDict(url, key) self.export_quantity_url(filters, quantity, client=client)
def main(): prestashop = PrestaShopWebServiceDict( 'http://efilmy.best/api', 'AZ2A2PZC183CQIEHI8KR3SC48E8CTA7T', ) while 1: print("1 Create Category Tree") print("2 Add features") print("3 Add products") print("4 Exit") x = input() if x == '1': create_category_tree(prestashop) elif x == '2': create_feature_tree(prestashop) elif x == '3': add_products(prestashop) elif x == '4': break
def external_connection(self, cr, uid, id, debug=False, logger=False, context=None): if isinstance(id, list): id = id[0] referential = self.browse(cr, uid, id, context=context) prestashop = PrestaShopWebServiceDict('%s/api' % referential.location, referential.apipass, debug=referential.debug) try: prestashop.head('') except PrestaShopAuthenticationError, e: if config['debug_mode']: raise raise osv.except_osv( _("Connection Error"), _("Could not connect to the PrestaShop webservice\nCheck the webservice URL and password\nHTTP error code: %s" % e.error_code))
def connect(self): return PrestaShopWebServiceDict(self.prestashop.api_url, self.prestashop.webservice_key)
'available_later': { 'language': { 'attrs': { 'id': '1' }, 'value': '' } }, 'id_default_combination': '' }) prestashop.add('products', data_schema) add_image(prod_id, prestashop, product[4].encode('utf8')) add_sizes(prestashop, product[6], prod_id) change_quantity(prod_id, prestashop) add_features(prestashop, product, prod_id) prod_id += 1 if __name__ == '__main__': api = PrestaShopWebServiceDict('http://localhost/prestashop/api', 'FXZ7H2NRVH24PB2HH9NGTDD7C92KSFHE') df = pd.read_csv('categories.csv', header=None, encoding='utf8') df = [list(row) for row in df.values] import_categories(df, api) df = pd.read_csv('products.csv', header=None, encoding='utf8', sep=';') df = [list(row) for row in df.values] import_products(df, api)
# without shipping info, color f.write( u'{0}\t"{1}"\t"{2}"\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\n' .format(id, title, description, link, image_link, avail, price, currency, gpc, brand, age_group, gender, condition)) return if __name__ == '__main__': try: basedir = sys.argv[1] except IndexError: basedir = '.' config = ConfigParser() config.read(basedir + '/config.ini') file = codecs.open( "{0}/{1}-{2}.tsv".format(config.get('report', 'folder_name'), config.get('report', 'file_name'), config.get('report', 'lang')), "w", "utf-8-sig") ps = PrestaShopWebServiceDict(config.get('ps', 'api_url'), config.get('ps', 'token')) get_fb_catalog(ps, file, config) file.close()
#Woocomerce EXPORT api_url = 'http://woocomercedomain.com/wp-json/wc/v1/products' api_key = 'ck_xxxx' api_secret = 'cs_xxxxxx' products = get_woocomerce_products(api_url, api_key, api_secret) # pprint(products) # PRESTASHOP IMPORT # For production PS ps_token = 'XXXX' protocol_url = 'https://' ps_url_api = 'yourdomain.com/api' prestashop = PrestaShopWebServiceDict('{}{}'.format(protocol_url, ps_url_api), ps_token) seller_id = 4 # Particular Knowband Marketplace seller id # Todo: insert the right categories matching from a table category_id = 43 # Art and culture id_shop = 1 # Prestashop shop general id for p in products: url_img = '' if 'images' in p: for im in p['images']: if im['src']: url_img = im['src'] # pprint(p)