juliomalegria / python-craigslist

Simple Craigslist wrapper
MIT No Attribution
387 stars 165 forks source link

Add bicycle filters #79

Closed carrollpaul closed 4 years ago

carrollpaul commented 4 years ago

I added a filter for bicycle type and included it in the show_filters method.

juliomalegria commented 4 years ago

Hey @carrollpaul. Thanks for collaborating! However, show_filters already has the abstract functionality to get all filters for any "section specific filters".

You can test this by running:

>>> from craigslist import CraigslistForSale                                                                                                                                                          

>>> CraigslistForSale.show_filters(category='bia')  # 'bia' is the category for "bikes"
Base filters:
* query = ...
* search_titles = True/False
* has_image = True/False
* posted_today = True/False
* bundle_duplicates = True/False
* search_distance = ...
* zip_code = ...
Section specific filters:
* min_price = ...
* max_price = ...
* make = ...
* model = ...
* min_year = ...
* max_year = ...
* min_miles = ...
* max_miles = ...
* min_engine_displacement = ...
* max_engine_displacement = ...
* language = 'af', 'ca', 'da', 'de', 'en', 'es', 'fi', 'fr', 'it', 'nl', 'no', 'pt', 'sv', 'tl', 'tr', 'zh', 'ar', 'ja', 'ko', 'ru', 'vi'
* bicycle_type = 'bmx', 'cargo/pedicab', 'cruiser', 'cyclocross', 'folding', 'gravel', 'hybrid/comfort', 'kids', 'mountain', 'recumbent/trike', 'road', 'tandem', 'track', 'unicycle', 'other'
* bicycle_frame_material = 'alloy', 'aluminum', 'carbon fiber', 'composite', 'scandium', 'steel', 'titanium', 'other/unknown'
* bicycle_wheel_size = '10 in', '12 in', '14 in', '16 in', '18 in', '20 in', '24 in', '25 in', '26 in', '26.5 in', '27 in', '27.5 in', '28 in', '29 in', '650B', '650C', '700C', 'other/unknown'
* bicycle_suspension = 'none (rigid)', 'suspension fork (hardtail)', 'frame and fork (full suspension)', 'other/unknown'
* bicycle_brake_type = 'caliper', 'cantilever', 'coaster', 'disc (hydraulic)', 'disc (mechanical)', 'drum', 'gyro/bmx', 'hydraulic rim brakes', 'none', 'u-brakes', 'v-brakes', 'other/unknown'
* bicycle_handlebar_type = 'aero', 'bmx', 'bullhorn', 'cruiser', 'downhill', 'drop', 'flat', 'riser', 'triathlon', 'other/unknown'
* bicycle_electric_assist = 'none', 'pedal assist', 'throttle', 'other'
* condition = 'new', 'like new', 'excellent', 'good', 'fair', 'salvage'

As you can see, bicycle_type is already included in the filters. You can use this filter by doing something like:

from craigslist import CraigslistForSale                                                                                                                                                          
cl_fs = CraigslistForSale(site='sfbay', area='sby', category='bia', filters={'bicycle_type': ['bmx']})

for result in cl_fs.get_results(): 
    print(result) 

{'id': '7170283850', 'repost_of': None, 'name': 'Bike Boys - 20inch', 'url': 'https://sfbay.craigslist.org/sby/bik/d/san-jose-bike-boys-20inch/7170283850.html', 'datetime': '2020-08-02 11:29', 'last_updated': '2020-08-02 11:29', 'price': '$25', 'where': 'willow glen / cambrian', 'has_image': True, 'geotag': None, 'deleted': False}
{'id': '7166542766', 'repost_of': '7126527103', 'name': 'Scwinn Gladiator Scooter', 'url': 'https://sfbay.craigslist.org/sby/bik/d/campbell-scwinn-gladiator-scooter/7166542766.html', 'datetime': '2020-08-02 10:26', 'last_updated': '2020-08-02 10:26', 'price': '$75', 'where': 'campbell', 'has_image': True, 'geotag': None, 'deleted': False}
# ...