CoolFace
Apppublic

mydatascraper/competitor_compare

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
compare.cpython-313.pyc59 linesDownload Raw Back to __pycache__
1�

2�Q2j0��J�SSKJrJr SSKJrJr SSKJr SSKJ	r	J3r4Jr \"SS/S9r\"5r
\RS\	S	9\"S5SSS
S9\"SSS94S\S\\\4Sjj5r\R#S\S	9\"S54S\6S\\\4Sjj5r\RS5S5rg)�)�	APIRouter�Query)�Optional�List)�ComparisonService)�ComparisonResponse�MultiCompareRequest�MultiCompareResponsez/api/v1zPrice Comparison)�prefix�tagsz/compare)�response_model.zNProduct name to search (e.g., 'whole milk', 'cheerios 18oz', 'pampers size 3')���)�description�7min_length�8max_lengthNz<Filter to specific retailers: walmart, aldi, target, wegmans)r�product�	retailersc��H# �[RX5IShv�N$N7f)u�9## Compare grocery prices in real-time10 11Searches Walmart, Aldi, Target, and Wegmans simultaneously12for the given product and returns a price comparison.13 14### How it works151. Sends search query to all 4 retailer websites concurrently162. Parses product listings from each site173. Finds the best matching product per retailer184. Ranks by price and returns comparison19 20### Fallback Strategy21For each retailer, tries 3 methods in order:22- **httpx** → Fast async HTTP (tries API endpoints first)23- **cloudscraper** → Handles Cloudflare/bot protection24- **playwright** → Full headless browser (last resort)25 26### Example Queries27- `whole milk`28- `cheerios`29- `boneless chicken breast`30- `pampers diapers size 3`31- `tide pods`32- `banana`33N)�comparison_service�compare)rrs  �OC:\Users\sundrani.raza\PycharmProjects\grocery-price-api\app\routers\compare.py�compare_pricesrs���N$�+�+�G�?�?�?�?�s�"� �"z/compare/batch�requestc��f# �URSSn[RX!5IShv�N$N7f)a�34## Compare multiple products at once35 36Submit a list of product names and get comparison37results for each across all retailers.38 39### Example Request40```json41{42    "products": [43        "whole milk",44        "cheerios",45        "bananas",46        "ground beef"47    ]48}49```50 51**Note:** Each product triggers concurrent searches across all retailers.52More products = longer response time. Limit: 10 products per request.53N�54)�productsr�
multi_compare)rrrs   r�compare_multiple_productsr9s0���6�����$�H�#�1�1�(�F�F�F�F�s�(1�/�1z55/retailersc	��N# �SSSSSS.SSS	SSS.S56SSSSS.S
SSSSS./SSS.$7f)z.List all supported retailers and their status.�walmart�Walmartzhttps://www.walmart.comzFull - PA stores�active)�id�name�website�coverage�status�aldi�ALDIzhttps://www.aldi.us�target�Targetzhttps://www.target.com�wegmans�Wegmanszhttps://shop.wegmans.com�zxPhase 2 will add: Sam's Club, Costco, Lidl, Trader Joe's, Whole Foods, Giant Eagle, Giant/Martin's, Weis, ShopRite, Acme)r�total�note�r2�r�list_retailersr4Xsx��� �!�4�.�"�
���0�.�"�
�� �3�.�"�
� �!�5�.�"�
�-57�<�Q�A"�"�s�#%)�fastapirr�typingrr�app.services.comparison_servicer�app.schemasrr	r58�routerr�get�strr�postrr4r2r3r�<module>r=s��$�!�=���59�)�+=�*>�	?��&�(�����J�'9��:���d���	�&+��R�&�&@�
�&@���S�	�"�&@�;�&@�R���
�.B��C�&+�4�[�G�
 �G���S�	�"�G�D�G�<���L��$��$r3