#4 Changements + améliorations programme
This commit is contained in:
95
wcctl.py
95
wcctl.py
@ -1,10 +1,10 @@
|
||||
print(f"📦 Script lancé : __name__ = {__name__}")
|
||||
import argparse
|
||||
from woocommerce import API as WoocommerceApi
|
||||
#from api_woocommerce import AuthentificationWpApi, MediaManager, CategoryManager, ProductManager, AttributeManager, VariationsManager, TabManager, WooCommerceManager
|
||||
from api import WoocommerceApiClient
|
||||
from api_woocommerce import AuthentificationWpApi, MediaManager, CategoryManager, ProductManager, AttributeManager, VariationsManager, TabManager, WooCommerceManager
|
||||
import pprint
|
||||
import base64
|
||||
import sys
|
||||
from base64 import b64encode
|
||||
|
||||
|
||||
def import_medias_ods(args, media_manager):
|
||||
@ -48,7 +48,14 @@ def import_products_ods(args, woocommerce_manager):
|
||||
print("ℹ️ --product activé, mais aucune plage spécifiée.")
|
||||
|
||||
def main():
|
||||
#ath = AuthentificationWpApi()
|
||||
ath = AuthentificationWpApi()
|
||||
|
||||
|
||||
#ctx = ssl.create_default_context()
|
||||
#ctx.set_ciphers('@SECLEVEL=2:ECDH+AESGCM:ECDH+CHACHA20:ECDH+AES:DHE+AES:AESGCM:!aNULL:!eNULL:!aDSS:!SHA1:!AESCCM:!PSK')
|
||||
#http = urllib3.PoolManager(ssl_context=ctx)
|
||||
#credentials = b64encode(f"{args.wc_key}:{args.wc_secret}").decode("utf-8")
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(prog='wcctl', description='WooCommerce CLI controller')
|
||||
|
||||
@ -65,7 +72,6 @@ def main():
|
||||
|
||||
# 📥 Commande : import-ods
|
||||
import_parser = subparsers.add_parser('import-ods', help='Import ODS file data')
|
||||
|
||||
import_parser.add_argument('--ods-path', required=True, help='Path to the ODS file')
|
||||
|
||||
# media
|
||||
@ -95,22 +101,81 @@ def main():
|
||||
# delete all informations
|
||||
import_parser.add_argument('--delete-all', action='store_true', help='Delete media, categories, products, attributes, tabs')
|
||||
|
||||
# 📥 Commande : import-ods
|
||||
checkssl_parser = subparsers.add_parser('checkssl', help='Check ssl connectivity')
|
||||
check_parser = subparsers.add_parser('check', help='Check connectivity')
|
||||
|
||||
|
||||
|
||||
# Analyse des arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
wcapi = WoocommerceApi(
|
||||
"""wcapi = WoocommerceApi(
|
||||
url=args.wc_url,
|
||||
consumer_key=args.wc_key,
|
||||
consumer_secret=args.wc_secret,
|
||||
wp_api=True,
|
||||
version="wc/v3",
|
||||
verify_ssl=False, # Désactive la vérification SSL pour le développement
|
||||
verify_ssl=False,
|
||||
timeout=30
|
||||
)
|
||||
)"""
|
||||
|
||||
wcapi = WoocommerceApiClient(
|
||||
url=args.wc_url,
|
||||
wc_consumer_key=args.wc_key,
|
||||
wc_consumer_secret=args.wc_secret,
|
||||
wp_application_user="admin_lcdm",
|
||||
wp_application_password= "Do4p tLYF 5uje PF2M 21Zo x3OR", #"eAB4 49W6 ZRBj zIZc fH62 tv5c", #"yTW8 Mc6J FUCN tPSq bnuJ 0Sdw", #
|
||||
wp_api=True,
|
||||
version="wc/v3",
|
||||
verify_ssl=True,
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if args.command == "check":
|
||||
#wcctl-api-rw
|
||||
#class WoocommerceApiClient(API) def __init__(self, url, wc_consumer_key, wc_consumer_secret, wp_application_user, wp_application_password, verify_ssl=False, **kwargs):
|
||||
wcapi = WoocommerceApiClient(
|
||||
url=args.wc_url,
|
||||
wc_consumer_key=args.wc_key,
|
||||
wc_consumer_secret=args.wc_secret,
|
||||
wp_application_user="admin_lcdm",
|
||||
wp_application_password= "Do4p tLYF 5uje PF2M 21Zo x3OR",#"eAB4 49W6 ZRBj zIZc fH62 tv5c", #"yTW8 Mc6J FUCN tPSq bnuJ 0Sdw", #
|
||||
wp_api=True,
|
||||
version="wc/v3",
|
||||
verify_ssl=True,
|
||||
timeout=30
|
||||
)
|
||||
print("recupération d'un produit", end="")
|
||||
response = wcapi.get("products", params={"per_page": 1, "page": 1})
|
||||
print(response)
|
||||
print("OK")
|
||||
|
||||
"""wcapi = WoocommerceApi(
|
||||
url=args.wc_url,
|
||||
consumer_key="wcctl-api-rw",
|
||||
consumer_secret="NUrp R7tI oDKr FSqT hhf8 KxOT",
|
||||
wp_api=True,
|
||||
version="wp/v2",
|
||||
verify_ssl=False,
|
||||
timeout=30
|
||||
)"""
|
||||
print("recupération d'un media", end="")
|
||||
response = wcapi.get("media", params={"per_page": 100, "page": 1})
|
||||
print(response)
|
||||
print("OK")
|
||||
sys.exit(0)
|
||||
|
||||
if args.command == "checkssl":
|
||||
for i in range(10):
|
||||
response = wcapi.get("products", params={"per_page": 1, "page": 1})
|
||||
print(i)
|
||||
print(f'connection OK')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
ath = AuthentificationWpApi()
|
||||
media_manager = MediaManager(ath, filename_ods=args.ods_path)
|
||||
media_manager = MediaManager(ath, wcapi, filename_ods=args.ods_path)
|
||||
category_manager = CategoryManager(wcapi, ath, filename_ods=args.ods_path)
|
||||
product_manager = ProductManager(wcapi, ath, filename_ods=args.ods_path)
|
||||
attribute_manager = AttributeManager(wcapi, filename_ods=args.ods_path)
|
||||
@ -131,12 +196,12 @@ def main():
|
||||
#print(f"🔍 args.media = {args.media}")
|
||||
#print(f"🔍 args.media_range = {args.media_range}")
|
||||
print(f"args = {args}")
|
||||
|
||||
if args.media:
|
||||
import_medias_ods(args, media_manager)
|
||||
|
||||
if args.delete_all:
|
||||
#woocommerce_manager.delete_all_informations()
|
||||
media_manager.delete_all_images()
|
||||
woocommerce_manager.delete_all_informations()
|
||||
|
||||
if args.category:
|
||||
medias = media_manager.get_all_as_slug_dict()
|
||||
@ -162,6 +227,10 @@ if __name__ == "__main__":
|
||||
# ods_file = donnees_site_internet_missbleue_corrige.ods
|
||||
|
||||
|
||||
#python wcctl.py --wc-url="https://lescreationsdemissbleue.local" --wc-key="ck_604e9b7b5d290cce72346efade6b31cb9a1ff28e" --wc-secret="cs_563974c7e59532c1ae1d0f8bbf61f0500d6bc768" import-ods --ods-path="donnees_site_internet_missbleue_corrige.ods"
|
||||
#python wcctl.py --wc-url="https://lescreationsdemissbleue.local" --wc-key="ck_604e9b7b5d290cce72346efade6b31cb9a1ff28e" --wc-secret="cs_563974c7e59532c1ae1d0f8bbf61f0500d6bc768" import-ods --ods-path="donnees_site_internet_missbleue_version_finale.ods"
|
||||
|
||||
#python wcctl.py --wc-url="https://les-creations-de-missbleue.local" --wc-key="ck_604e9b7b5d290cce72346efade6b31cb9a1ff28e" --wc-secret="cs_563974c7e59532c1ae1d0f8bbf61f0500d6bc768" import-ods --ods-path="donnees_site_internet_missbleue_corrige.ods"
|
||||
#python wcctl.py --wc-url="https://les-creations-de-missbleue.local" --wc-key="ck_604e9b7b5d290cce72346efade6b31cb9a1ff28e" --wc-secret="cs_563974c7e59532c1ae1d0f8bbf61f0500d6bc768" import-ods --ods-path="donnees_site_internet_missbleue_version_finale.ods"
|
||||
|
||||
# python wcctl.py --wc-url="https://les-creations-de-missbleue.local" --wc-key="ck_604e9b7b5d290cce72346efade6b31cb9a1ff28e" --wc-secret="cs_563974c7e59532c1ae1d0f8bbf61f0500d6bc768" import-ods --ods-path="donnees_site_internet_missbleue_version_finale.ods" --product --product-range="111:112"
|
||||
#
|
||||
# # python wcctl.py --wc-url="https://les-creations-de-missbleue.com" --wc-key="ck_4125db027f75040ce9c7ca1bbc95b7031d1a6263" --wc-secret="cs_50d0a1de003fa8f8d0deb5f427b7769071dd4bfd" import-ods --ods-path="donnees_site_internet_missbleue_version_finale.ods"
|
||||
Reference in New Issue
Block a user