irahorecka / chrono24

Chrono24 API wrapper
MIT License
12 stars 1 forks source link

Flexibility in request_attrs #3

Open MohiMad opened 4 weeks ago

MohiMad commented 4 weeks ago

Hello

Thank you for building this API. It functions properly and is well structured. I have one suggestion: make the request_attrs variable in the _search method a class of its own that can have an instance of it passed into the search method so that the search parameters in Chrono24 can be taken advantage of. Chrono24 provides for example a lot of filters that are essentially turned into request parameters. The concept is simple, but I know it's gonna take you a lot of reverse-engineering to add all the possible options manually unless you find the script that includes the parameters. But start by adding them one at a time, starting with the basic filters such as: styles=1811 for automatic watches styles=1827 for quartz watches

sellerType=PrivateSeller for private sellers sellerType=C24Direct for Chrono24 Direct sellerType=Dealer for professional dealers

I believe you're aware of the filter above, I have seen you taking it into account in the code. I also noticed that these filters are not unique and can be combined such as: sellerType=PrivateSeller&sellerType=C24Direct will give you both private and C24Direct

Two last parameters that I think are of importance are SETLANG which changes the language of the entire page and allows for multilanguage applications and SETCURR which automatically does the currency conversion.

I know this is one big suggestion but it's gonna make the API very customizable to one's own needs which is positive. Also, I have been wanting to contribute to the project and help implement this feature, if you could add to the README a brief introduction or explanation on what the various folders are and how for instance run the given tests, etc it would be appreciated.

Thank you

irahorecka commented 3 weeks ago

Thank you for your suggestions, I think they are great. I would be very happy to have you as a collaborator. As for code of conduct, I will draft one up soon, but I am pretty flexible with feature implementations. Feel free to fork the repository and work on your suggested feature. To run the tests, you can download the necessary libraries as outlined in requirements-dev.txt and run pytest -vv tests/.

Perhaps the query filters class can look something like this in a file called filters.py in chrono24/ - what do you think?

class QueryFilters:
    def __init__(self):
        self.filters = {}

    def set_case_diameters(self, *diameters):
        self.filters.update({"caseDiameter": diameters})

    def set_years(self, *years):
        self.filters.update({f"year_{i}": year for i, year in enumerate(years)})

    def join_attrs(self):
        return "&" + "&".join(f"{k.split('_')[0]}={v}" for k, v in self.filters.items())

# Example
filters = QueryFilters()
# Adding case diameter and years to filters
filters.set_case_diameters(40, 41, 42)
filters.set_years(2010, 2011, 2012)
# Generate the final URL query string
url_query = filters.join_attrs()
print(url_query)  # Outputs: &caseDiameter=(40, 41, 42)&year=2010&year=2011&year=2012