tgshops-integrations 4.6__py3-none-any.whl → 5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,6 +45,7 @@ class Gateway(NocodbClient):
45
45
  filter_buttons: Optional[List[str]] = [],
46
46
  config_path: Optional[Path] = None,
47
47
  special_attributes: bool = False,
48
+ config: Optional[List[str]] = []
48
49
  ):
49
50
  super().__init__(NOCODB_HOST=NOCODB_HOST, NOCODB_API_KEY=NOCODB_API_KEY, SOURCE=SOURCE)
50
51
 
@@ -53,14 +54,16 @@ class Gateway(NocodbClient):
53
54
  self.projection = []
54
55
  self.special_attributes = special_attributes
55
56
  self.filter_buttons = filter_buttons
56
-
57
57
  self.language = "EN"
58
58
 
59
59
  if config_path:
60
-
61
60
  self.load_config_from_path(config_path)
62
61
  self.config_path = config_path
63
62
 
63
+ self.load_data(SOURCE=SOURCE, config_path=config_path)
64
+
65
+
66
+
64
67
  def load_config_from_path(self, config_path: Path):
65
68
  """Loads configuration from the specified path."""
66
69
  if config_path.exists():
@@ -70,13 +73,14 @@ class Gateway(NocodbClient):
70
73
  else:
71
74
  raise FileNotFoundError(f"Configuration file not found at {config_path}")
72
75
 
73
- async def load_data(self, SOURCE: Optional[str] = None):
76
+ def load_data(self, SOURCE: Optional[str] = None, config_path: Optional[Path] = None):
74
77
  """Loads necessary data including tables, categories, and products."""
75
78
  self.SOURCE = SOURCE
76
- self.tables_list = await self.get_all_tables()
79
+ self.config_path = config_path
80
+ self.tables_list = self.init_all_tables()
77
81
 
78
82
  language = language_check(self)
79
- initialize_model_mapping(self.config_path,language=language)
83
+ initialize_model_mapping(config_path=config_path,language=language)
80
84
 
81
85
  self.products_table = self.tables_list[self.config.NOCODB_TABLES[language]["NOCODB_PRODUCTS"]]
82
86
  self.category_manager = CategoryManager(
@@ -85,7 +85,7 @@ class CategoryManager(NocodbClient):
85
85
  )
86
86
  return [parse_category_data(record) for record in records]
87
87
 
88
- async def update_categories(self, external_products: List[ProductModel],with_properties: bool = False) -> None:
88
+ async def update_categories(self, external_products: List[ProductModel],with_properties: bool = False) -> dict:
89
89
  self.categories = await self.get_product_categories(table_id=self.categories_table, table_name=self.config.NOCODB_PRODUCTS[self.language]['PRODUCT_NAME_FIELD'])
90
90
  categories_list = list(self.categories.keys())
91
91
  properties_to_create = []
@@ -95,20 +95,11 @@ class CategoryManager(NocodbClient):
95
95
  for product in external_products:
96
96
  for num, product_property in enumerate(product.product_properties[:len(self.filter_buttons)]):
97
97
  if product_property not in categories_list:
98
- # TODO: Needs restructuring
99
- # parent_id = (
100
- # self.categories[self.filter_buttons[num]]
101
- # if self.filter_buttons
102
- # else self.categories[product.category_I_name[0]]
103
- # )
104
-
105
98
  properties_to_create.append([product_property, parent_id])
106
99
  categories_list.append(product_property)
107
100
 
108
101
  else:
109
102
  for product in external_products:
110
- # for item in product.categories_structure.values():
111
- # if item not in categories_list:
112
103
  for product_property in product.product_properties:
113
104
  if product_property not in categories_list:
114
105
  properties_to_create.append([product_property, parent_id])
@@ -130,7 +121,8 @@ class CategoryManager(NocodbClient):
130
121
  new_id += 1
131
122
 
132
123
  self.categories = await self.get_product_categories(table_id=self.categories_table, table_name=self.config.NOCODB_PRODUCTS[self.language]['PRODUCT_NAME_FIELD'])
133
-
124
+ return self.categories
125
+
134
126
  async def link_categories(self, parent_id: int, child_id: int):
135
127
  metadata = await self.get_table_meta(self.categories_table)
136
128
  linked_column = next((col for col in metadata['columns'] if col["title"] == "Set parent category" and col["uidt"] == "Links"), None)
@@ -163,6 +163,26 @@ class NocodbClient:
163
163
  return response.json()
164
164
  logger.error(f"Error fetching table metadata: {response.text}")
165
165
  raise Exception(response.text)
166
+
167
+ def init_all_tables(self, source: Optional[str] = None) -> Dict[str, str]:
168
+ """
169
+ Fetches all tables from the specified project source (synchronously).
170
+ """
171
+ source = source or self.SOURCE
172
+ url = f"{self.NOCODB_HOST.replace('/api/v2', '/api/v1')}/db/meta/projects/{source}/tables?includeM2M=false"
173
+
174
+ # Use a temporary synchronous HTTP client
175
+ with httpx.Client(timeout=30.0) as client:
176
+ # client.headers = {"xc-token": self.NOCODB_API_KEY}
177
+ response = client.get(url, headers={"xc-token": self.NOCODB_API_KEY})
178
+
179
+ if response.status_code == 200:
180
+ tables_info = response.json().get("list", [])
181
+ self.tables_list = {table["title"]: table["id"] for table in tables_info}
182
+ return self.tables_list
183
+
184
+ logger.error(f"Failed to fetch tables: {response.text}")
185
+ raise Exception(response.text)
166
186
 
167
187
  async def get_all_tables(self, source: Optional[str] = None) -> Dict[str, str]:
168
188
  """
@@ -11,6 +11,7 @@ from tgshops_integrations.nocodb_connector.model_mapping import (
11
11
  parse_product_data
12
12
  )
13
13
 
14
+
14
15
  class ProductManager(NocodbClient):
15
16
  def __init__(self, table_id=None, logging=False, NOCODB_HOST=None, NOCODB_API_KEY=None, SOURCE=None, config=None, language="EN"):
16
17
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tgshops-integrations
3
- Version: 4.6
3
+ Version: 5.0
4
4
  Summary: Library is intended to provide the integration of the external service or CRM system with the TelegramShops/It allows to configure the relationship between NocoDB list of the products used further to display in the shop/As a resultss the products can be synchronized and updated uppon the request.
5
5
  Home-page: https://git.the-devs.com/virtual-shops/shop-system/shop-backend-integrations/integration-library/integration-library
6
6
  Author: Dimi Latoff
@@ -1,16 +1,16 @@
1
1
  tgshops_integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  tgshops_integrations/middlewares/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- tgshops_integrations/middlewares/gateway.py,sha256=2czpeJ0oGNHxAdXysyk3jKnKKwgrJbFaN6OY3fTeSp0,6868
3
+ tgshops_integrations/middlewares/gateway.py,sha256=p3B9pamEqNG9vz9m5o9xhWsB7NwVkuLOY1OenYcUdaQ,7032
4
4
  tgshops_integrations/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  tgshops_integrations/models/categories.py,sha256=EG6C8g5dOfXB2MH-vtqH13aqB7_VyOobY2FHpDb-fsY,977
6
6
  tgshops_integrations/models/products.py,sha256=4XC6fyC91TAWj5oaX0A26kT_UizZIGaf4qyrVv9lPpQ,1403
7
7
  tgshops_integrations/nocodb_connector/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- tgshops_integrations/nocodb_connector/categories_management.py,sha256=jVbgkKmCDUuGj1zZyIO041m0pvQRnV0pyEZGnwDa2U4,7921
9
- tgshops_integrations/nocodb_connector/client.py,sha256=3MLTOLInxhsr4H0nt71k09ozgUyRzGV2onYZuFWQJzI,12487
8
+ tgshops_integrations/nocodb_connector/categories_management.py,sha256=f84h8CoVBOniNYmN4KdGLCsVUUJm0XiQjZ7Ty7K6SBk,7484
9
+ tgshops_integrations/nocodb_connector/client.py,sha256=8EkFv5_VpoF8LeslZIT-a2vadIDHXCSL_4fBbmVSP6Q,13403
10
10
  tgshops_integrations/nocodb_connector/model_mapping.py,sha256=rTzBH6lKbxcLTvlOSVkIriSOYjnwhqIHx0wiXPTxHwo,9540
11
- tgshops_integrations/nocodb_connector/products_management.py,sha256=ChwF6r2llfCtZU83fijLPgcO0SUGUMTQYCLIoKEQIVs,6532
11
+ tgshops_integrations/nocodb_connector/products_management.py,sha256=3RM4_8-D-5liDnYSKKJheVFn60iZv8otgXul7NQWmvY,6533
12
12
  tgshops_integrations/nocodb_connector/tables.py,sha256=ha_QXZXd93mht0fR5E1nM0wUpz1ePon-pIdO2HI67l8,356
13
- tgshops_integrations-4.6.dist-info/METADATA,sha256=nHc68LVFHrueH8i39-msz5RgrUqLRYlNTlECQV0iFtg,2844
14
- tgshops_integrations-4.6.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
15
- tgshops_integrations-4.6.dist-info/top_level.txt,sha256=HFNtxqDpzmlF4ZLnMiwhbU7pOa_YozxU2zBl0bnUmcY,21
16
- tgshops_integrations-4.6.dist-info/RECORD,,
13
+ tgshops_integrations-5.0.dist-info/METADATA,sha256=s12xdts4o9eT9y3DaN9iiOcOpbMo-MlxmfstPvR4-Zk,2844
14
+ tgshops_integrations-5.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
15
+ tgshops_integrations-5.0.dist-info/top_level.txt,sha256=HFNtxqDpzmlF4ZLnMiwhbU7pOa_YozxU2zBl0bnUmcY,21
16
+ tgshops_integrations-5.0.dist-info/RECORD,,