Created
April 6, 2021 23:15
-
-
Save alecbw/9258dce03afeef1b05e90202f0ff2dd9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import os | |
| from pprint import pprint | |
| def make_sourcestack_query(endpoint, params_dict): | |
| querystrings = "?" | |
| for k,v in params_dict.items(): | |
| querystrings += k + "=" + str(v) + "&" | |
| querystrings = querystrings.rstrip("&") | |
| response = requests.get( | |
| "https://sourcestack-api.com/" + endpoint + querystrings, | |
| headers={ | |
| "x-api-key": os.environ["SOURCESTACK_KEY"] | |
| }) | |
| return response | |
| ################################################ | |
| if __name__ == "__main__": | |
| response = make_sourcestack_query( | |
| "jobs", | |
| { | |
| "limit":"5", | |
| "count_only":"False", | |
| # "fields": "alexa_rank, url", | |
| "filters": [ | |
| {"field": "job_location", "operator": "IN", "value": ["SF", "SFBA", "San Francisco", "Bay Area"]}, | |
| {"field": "job_name", "operator": "CONTAINS", "value": "strat"} | |
| ] | |
| } | |
| ) | |
| pprint({ | |
| "1. Status_Code": response.status_code, | |
| "2. Message": response.json().get('message'), | |
| "3. Entry_Count": response.json().get('entry_count'), | |
| "4. Credits_Remaining": response.headers.get("X-SOURCESTACK-CREDITS-REMAINING"), | |
| "5. Request ID": response.headers.get("X-SOURCESTACK-REQUEST-ID"), | |
| "6. Data": response.json().get('data'), | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment