Converts a Python list of facets into a comma-separated string that can be understood by the Shodan API.
(facets)
| 11 | |
| 12 | |
| 13 | def create_facet_string(facets): |
| 14 | """Converts a Python list of facets into a comma-separated string that can be understood by |
| 15 | the Shodan API. |
| 16 | """ |
| 17 | facet_str = '' |
| 18 | for facet in facets: |
| 19 | if isinstance(facet, basestring): |
| 20 | facet_str += facet |
| 21 | else: |
| 22 | facet_str += '{}:{}'.format(facet[0], facet[1]) |
| 23 | facet_str += ',' |
| 24 | return facet_str[:-1] |
| 25 | |
| 26 | |
| 27 | def api_request(key, function, params=None, data=None, base_url='https://api.shodan.io', |