Spaces:
Build error
Build error
File size: 9,467 Bytes
9f36753 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"\n"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import csv\n",
"\n",
"def get_products(stores_ids, province):\n",
" url = \"https://d3e6htiiul5ek9.cloudfront.net/prod/productos\"\n",
" params = {\n",
" \"string\": \"stevia\",\n",
" \"array_sucursales\":stores_ids,\n",
" \"offset\": 0,\n",
" \"limit\": 50,\n",
" \"sort\": \"-cant_sucursales_disponible\"\n",
" }\n",
"\n",
" headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0\",\n",
" \"Accept\": \"application/json, text/plain, */*\",\n",
" \"Accept-Language\": \"en-US,en;q=0.5\",\n",
" \"Accept-Encoding\": \"gzip, deflate, br, zstd\",\n",
" \"Origin\": \"https://www.preciosclaros.gob.ar\",\n",
" \"Connection\": \"keep-alive\",\n",
" \"Referer\": \"https://www.preciosclaros.gob.ar/\",\n",
" \"Sec-Fetch-Dest\": \"empty\",\n",
" \"Sec-Fetch-Mode\": \"cors\",\n",
" \"Sec-Fetch-Site\": \"cross-site\",\n",
" \"TE\": \"trailers\"\n",
" }\n",
"\n",
" response = requests.get(url, params=params, headers=headers)\n",
"\n",
" productos = response.json()[\"productos\"]\n",
"\n",
" with open(\"Products.csv\", \"a\", newline=\"\", encoding='UTF-8') as file:\n",
" #check if it's empty\n",
" writer = csv.writer(file)\n",
" if file.tell() == 0:\n",
"\n",
" writer.writerow(list(productos[0].keys()) + [\"provincia\"])\n",
" for producto in productos:\n",
" writer.writerow(list(producto.values()) + [province])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import csv\n",
"\n",
"def get_specific_products(stores, id):\n",
" url = \"https://d3e6htiiul5ek9.cloudfront.net/prod/producto\"\n",
" params = {\n",
" \"limit\": 30,\n",
" \"id_producto\": id,\n",
" \"array_sucursales\": stores\n",
"}\n",
"\n",
" headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0\",\n",
" \"Accept\": \"application/json, text/plain, */*\",\n",
" \"Accept-Language\": \"en-US,en;q=0.5\",\n",
" \"Accept-Encoding\": \"gzip, deflate, br, zstd\",\n",
" \"Origin\": \"https://www.preciosclaros.gob.ar\",\n",
" \"Connection\": \"keep-alive\",\n",
" \"Referer\": \"https://www.preciosclaros.gob.ar/\",\n",
" \"Sec-Fetch-Dest\": \"empty\",\n",
" \"Sec-Fetch-Mode\": \"cors\",\n",
" \"Sec-Fetch-Site\": \"cross-site\",\n",
" \"TE\": \"trailers\"\n",
" }\n",
"\n",
" response = requests.get(url, params=params, headers=headers)\n",
"\n",
" response = response.json()\n",
" producto = response['producto']\n",
" with open(\"Store-Products.csv\", \"a\", newline=\"\", encoding='UTF-8') as file:\n",
" #check if it's empty\n",
" writer = csv.writer(file)\n",
" if file.tell() == 0:\n",
" writer.writerow(['id_producto','marca_producto', 'nombre_producto','presentacion_producto','id_sucursal', 'precio_lista','promocion','promocion_descripcion'])\n",
" for sucursal in response['sucursales']:\n",
" if \"message\" not in sucursal:\n",
" precios = sucursal['preciosProducto']\n",
" precio_lista = precios['precioLista']\n",
" if'promo1' in precios:\n",
" promocion = precios['promo1']['precio']\n",
" descripcion_promocion = precios['promo1']['descripcion']\n",
" else:\n",
" promocion=None\n",
" descripcion_promocion=None\n",
"\n",
" writer.writerow([producto['id'], producto['marca'], producto['nombre'], producto['presentacion'], str(sucursal['comercioId'])+'-'+str(sucursal['banderaId'])+'-'+str(sucursal['id']), precio_lista, promocion, descripcion_promocion])"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"# Leer el archivo CSV\n",
"df = pd.read_csv(\"sucursales.csv\")\n",
"#obtengo todas las provincias\n",
"provinces = df['provincia'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"#Obtener los ids de sucursales de una misma marca en distintas partes del pais\n",
"for province in provinces:\n",
" stores = df[df['provincia'] == province]\n",
" ids_stores = stores['id'].tolist()\n",
" ids_stores_str = ','.join(ids_stores)\n",
" \n",
" get_products(ids_stores_str, province)\n",
" \n",
"#ids_stores tiene los ids ordenados por cada provincia\n",
"\n",
"#obtengo los productos de cada surucsal"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"#Empiezo a trabajar en el dataset de productos\n",
"import pandas as pd\n",
"df = pd.read_csv(\"Products.csv\")\n",
"\n",
"#drop \"CLIGHT\" products\"\n",
"df = df[df['marca'] != \"CLIGHT\"]\n",
"#drop \"CUARTO CRECIENTE\" products\n",
"df = df[df['marca'] != \"CUARTO CRECIENTE\"]\n",
"\n",
"df = df[df['marca'] != \"CUARTOCRECIENTE\"]\n",
"\n",
"df = df[df['marca'] != \"TRINI\"]\n",
"\n",
"df = df[df['marca'] != \"ENTRE NUTS\"]\n",
"\n",
"df = df[df['marca'] != \"VIGENTE\"]\n",
"\n",
"\n",
"\n",
"df.to_csv(\"Products.csv\", index=False)\n",
"\n",
"#remove duplicates\n",
"\n",
"df = pd.read_csv(\"Products.csv\")\n",
"\n",
"#remove columns\n",
"df = df.drop(columns=['precioMin','precioMax','cantSucursalesDisponible','provincia'])\n",
"\n",
"df = df.drop_duplicates()\n",
"\n",
"df.to_csv(\"Products_unique.csv\", index=False)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"#Obtener los ids de productos de interes\n",
"ledesma_200_u = 7799086000198\n",
"competitors_ledesma_200_u = [7794940000772, 7792129003507, 7792129003644, 7790150812785]\n",
"#recorriendo cada una de esas sucursales, y obteniendo los productos similares\n",
"ledesma_100_u = 7799086000051\n",
"competitors_ledesma_100_u = [7794940000765, 7792129003637, 7791720030509, 7790150812761]\n",
"\n",
"ledesma_50_u = 7799086000266\n",
"competitors_ledesma_50_u = [7792129003620, 7791720030493, 7794940000758, 7790150812747]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"#Recorrer cada una de las sucursales de la marca\n",
"for province in provinces:\n",
" stores = df[df['provincia'] == province]\n",
" ids_stores = stores['id'].tolist()\n",
" ids_stores_str = ','.join(ids_stores)\n",
" #ledesma 200 u\n",
" get_specific_products(ids_stores_str, ledesma_200_u)\n",
" for competitor_ledesma_200_u in competitors_ledesma_200_u:\n",
" get_specific_products(ids_stores_str, competitor_ledesma_200_u)\n",
" #ledesma 100 u\n",
" get_specific_products(ids_stores_str, ledesma_100_u)\n",
" for competitor_ledesma_100_u in competitors_ledesma_100_u:\n",
" get_specific_products(ids_stores_str, competitor_ledesma_100_u)\n",
" #ledesma 50 u\n",
" get_specific_products(ids_stores_str, ledesma_50_u)\n",
" for competitor_ledesma_50_u in competitors_ledesma_50_u:\n",
" get_specific_products(ids_stores_str, competitor_ledesma_50_u)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Almacenar los datos en un csv"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Comparar los productos"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|