deedy5 / duckduckgo_search

Search for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine. Downloading files and images to a local hard drive.
MIT License
927 stars 117 forks source link

Added option to get raw DuckDuckGo maps results. #173

Closed mtulla-xtillion closed 5 months ago

mtulla-xtillion commented 5 months ago

Currently, when using DDGS.maps() or AsyncDDGS.maps(), the raw map results from DuckDuckGo are restructured according to the MapsResult model and then returned to the user as a dictionary. I added a raw_results boolean parameter to the AsyncDDGS.maps() method that allows for the raw map results to be returned. The parameter defaults to False so as to keep the library backwards compatible.

I am currently working on a use case where I need to access ratings, reviews, and other information that is provided in the raw DDG results, but not in the structured results currently being returned by the library. Instead of changing the MapsResult model, I think it would be best to allow the user to get the raw results (which is what a few other AsyncDDGS methods already return) and structure them as they wish.

Testing is in place to make sure the default use of the maps method (with raw_results set to False) returns results that satisfy the MapsResult model.

deedy5 commented 5 months ago

...I need to access ratings, reviews, and other information that is provided in the raw DDG results... What fields do you need?

mtulla-xtillion commented 5 months ago

For the project I'm working on, I would need to access the following fields.

However, exactly what fields I need might change. There's also some categories currently being returned that I don't really need. That's why I think it's a good feature to return the whole raw result and let the end user decide how use/structure it.

Below is an example of one of these raw results for reference.

{   'address': 'Palace House 3 Cathedral Street, Bread Ahead Bakery School, London, GB SE1 9DE',
    'address_lines': [   'Palace House 3 Cathedral Street',
                         'Bread Ahead Bakery School',
                         'London, GB SE1 9DE'],
    'boosted': 0,
    'city': 'London',
    'closed': 0,
    'coordinates': {'latitude': 51.5062253, 'longitude': -0.0903899},
    'country_code': None,
    'data_providers': {   'address': 'tripadvisor',
                          'hours': 'tripadvisor',
                          'phone': 'tripadvisor',
                          'url': 'apple'},
    'ddg_category': 'Lessons and workshops',
    'display_phone': '+44 20 7407 7853',
    'distance': 0,
    'embed': None,
    'engine': 'Tripadvisor',
    'exact_match': 0,
    'facebook_id': '',
    'hotel_id': None,
    'hours': {   'Fri': '09:00:00–21:30:00',
                 'Mon': '09:00:00–21:30:00',
                 'Sat': '09:00:00–20:00:00',
                 'Sun': '09:00:00–17:00:00',
                 'Thu': '09:00:00–21:30:00',
                 'Tue': '09:00:00–21:30:00',
                 'Wed': '09:00:00–21:30:00',
                 'closes_soon': 0,
                 'is_open': 1,
                 'opens_soon': 0,
                 'state_switch_time': '21:30'},
    'id': '6659413',
    'id_words': [],
    'image': 'http://media-cdn.tripadvisor.com/media/photo-s/2a/e5/34/ae/caption.jpg',
    'instagram_id': '',
    'menu': '',
    'name': 'Bread Ahead Bakery School',
    'neighborhood': [],
    'phone': '+442074077853',
    'photoURL': 'https://www.tripadvisor.com/Attraction_Review-g186338-d6659413-Reviews-Bread_Ahead_Bakery_School-London_England.html?m=63959',
    'popular_hours': {},
    'price': 0,
    'provider': None,
    'provider_meta': {   'apple': {   'manage_url': 'https://register.apple.com/placesonmaps/',
                                      'name': 'Apple Maps',
                                      'place_id': '835948176347872904'},
                         'tripadvisor': {   'manage_url': 'https://www.tripadvisor.com/ManageListing-g186338-d6659413',
                                            'name': 'Tripadvisor',
                                            'place_id': '6659413'}},
    'provider_url': None,
    'rating': 4,
    'returned_categories': [['Lessons & Workshops', 'Lessons & Workshops']],
    'review_detail': [   {   'excerpt': 'All in all I had a very enjoyable '
                                        'day. Manuel’s teaching was superb. We '
                                        'baked stollen and pork pies as well '
                                        'as cinnamon biscuits and Parmesan '
                                        'sable. We made chutney as a group and '
                                        'mulled wine. We were...',
                             'id': '928078702',
                             'rating': 5,
                             'time_created': 1701406800,
                             'user': {   'id': 'Elizabethjane7861',
                                         'image_url': 'http://media-cdn.tripadvisor.com/media/photo-t/1a/f6/ed/00/default-avatar-2020-4.jpg',
                                         'name': 'Elizabethjane7861'}},
                         {   'excerpt': 'Wonderful day on the Christmas Hamper '
                                        'workshop- working in teams to make '
                                        'chutney, jam and mulled wine was a '
                                        'great way to create a festive team '
                                        'spirit before we set to with porky '
                                        'pies, Parmesan cheese ...',
                             'id': '927559311',
                             'rating': 5,
                             'time_created': 1701061200,
                             'user': {   'id': 'michellehQ9670KD',
                                         'image_url': 'http://media-cdn.tripadvisor.com/media/photo-t/1a/f6/e4/59/default-avatar-2020-49.jpg',
                                         'name': 'michellehQ9670KD'}},
                         {   'excerpt': 'Review of Wembley baking school. '
                                        'Bakery assistant who showed us in '
                                        'clearly needs some training so that '
                                        'she can proactively welcome clients '
                                        'rather than nervously ushering us in '
                                        'and then giving no furth...',
                             'id': '909265556',
                             'rating': 2,
                             'time_created': 1691640000,
                             'user': {   'id': 'Hamish295',
                                         'image_url': 'http://media-cdn.tripadvisor.com/media/photo-t/1a/f6/ed/00/default-avatar-2020-4.jpg',
                                         'name': 'Hamish295'}}],
    'reviews': 118,
    'thumbnails': [   'http://media-cdn.tripadvisor.com/media/photo-s/2a/e5/34/ad/caption.jpg',
                      'http://media-cdn.tripadvisor.com/media/photo-s/2a/e5/34/ac/caption.jpg',
                      'http://media-cdn.tripadvisor.com/media/photo-s/2a/e5/34/ab/caption.jpg',
                      'http://media-cdn.tripadvisor.com/media/photo-s/2a/e5/34/aa/caption.jpg'],
    'timezone': 'Europe/London',
    'twitter_id': '',
    'url': 'https://www.tripadvisor.com/Attraction_Review-g186338-d6659413-Reviews-Bread_Ahead_Bakery_School-London_England.html?m=63959',
    'website': 'https://www.breadahead.com/borough'}
deedy5 commented 5 months ago

I don't want to complicate the code, and this package doesn't have the task of collecting subjective data - ratings and reviews.