Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def wrapper(*args, **kwargs):
class_name, func_name = re.sub(r'([A-Z]+)', r'_\1', args[0].__class__.__name__).lower().strip('_'), f.__name__
fixtures = load_reqresp_fixture(req_resp or "{}/{}".format(class_name, func_name))
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
for fixture in fixtures:
if 'url_re' in fixture:
url_re = fixture.pop('url_re')
fixture['url'] = re.compile(Client.build_url(url_re))
else:
fixture['url'] = Client.build_url(fixture['url'])
if "content_type" in fixture and fixture['content_type'] == "application/json":
fixture['body'] = json.dumps(fixture['body'])
rsps.add(**fixture)
return f(responses=rsps, *args, **kwargs)
return wrapper
def wrapper(*args, **kwargs):
return f(client=Client(*client_args, **client_kwargs), *args, **kwargs)
return wrapper
def setUp(self):
self.client = predicthq.Client()
def test_construct_with_access_token(self):
client = predicthq.Client(access_token='token123')
self.assertEqual(client.access_token, 'token123')
def wrapper(*args, **kwargs):
with mock.patch.object(Client, 'request', return_value=request_returns, side_effect=request_raises):
return f(client=Client(*client_args, **client_kwargs), *args, **kwargs)
return wrapper
from predicthq import Client
# Please copy paste your access token here
# or read our Quickstart documentation if you don't have a token yet
# https://docs.predicthq.com/guides/quickstart/
ACCESS_TOKEN = 'abc123'
phq = Client(access_token=ACCESS_TOKEN)
# The PredictHQ Aggregate Event Impact endpoint can be used to find the correlation between your demand and the events data.
# We always aggregate on the date but you can use different impact_rank values to specify how we calculate the impact.
# You will need a Premium Plan to access this endpoint and Aviation Rank subscription for Aviation Rank impact.
# You can either aggregate on PHQ Rank by passing impact_rank param as 'rank'.
# https://docs.predicthq.com/resources/events/#param-impact-rank
for impact_day in phq.events.impact(active__gte='2015-12-24', active__lte='2015-12-26', impact_rank='rank'):
print(impact_day.date, impact_day.impact, impact_day.rank_levels, impact_day.rank_levels_impact, impact_day.categories, impact_day.categories_impact)
# or aggregate on Aviation Rank by passing impact_rank param as 'aviation_rank'.
# https://docs.predicthq.com/resources/events/#param-impact-rank
for impact_day in phq.events.impact(active__gte='2015-12-24', active__lte='2015-12-26', impact_rank='aviation_rank'):
print(impact_day.date, impact_day.impact, impact_day.aviation_rank_levels, impact_day.aviation_rank_levels_impact, impact_day.categories, impact_day.categories_impact)
from predicthq import Client
# Please copy paste your access token here
# or read our Quickstart documentation if you don't have a token yet
# https://docs.predicthq.com/guides/quickstart/
ACCESS_TOKEN = 'abc123'
phq = Client(access_token=ACCESS_TOKEN)
# The PredictHQ API offers two ways to filter by rank.
# You can either filter by rank value
# https://docs.predicthq.com/resources/events/#param-rank
for event in phq.events.search(rank={'gte': 60, 'lt': 80}):
print(event.rank, event.category, event.title, event.start.strftime('%Y-%m-%d'))
# or filter by rank level
# https://docs.predicthq.com/resources/events/#param-rank_level
# 1 - Minor (rank between 0 and 20)
# 2 - Moderate (rank between 21 and 40)
# 3 - Important (rank between 41 and 60)
# 4 - Significant (rank between 61 and 80)
from predicthq import Client
# Please copy paste your access token here
# or read our Quickstart documentation if you don't have a token yet
# https://docs.predicthq.com/guides/quickstart/
ACCESS_TOKEN = 'abc123'
phq = Client(access_token=ACCESS_TOKEN)
# The events endpoint supports three types of search by location:
# - by area
# - by fuzzy location search around
# - by geoname place ID (see places endpoint for more details)
# The within parameter allows you to search for events within
# a specified area. It expects a string in the form
# {radius}{unit}@{latitude},{longitude}
# where the radius unit can be one of: m, km, ft, mi.
# https://docs.predicthq.com/resources/events/#param-within
# Please note that the the within parameter uses the lat, lon order
# but the location field in the event response uses the lon, lat GeoJSON order.
for event in phq.events.search(within='10km@-36.844480,174.768368'):
from predicthq import Client
# Please copy paste your access token here
# or read our Quickstart documentation if you don't have a token yet
# https://docs.predicthq.com/guides/quickstart/
ACCESS_TOKEN = 'abc123'
phq = Client(access_token=ACCESS_TOKEN)
# One of PredictHQ's data-enriching features is to provide predicted attendance
# numbers events. This is a paid feature and is extremely useful for demand
# intelligence and prediction. Predicted attendance is available as
# phq_attendance.
# You can filter by phq_attendance when searching.
# See https://docs.predicthq.com/resources/events/#param-phq_attendance
for event in phq.events.search(phq_attendance={'gte': 5000}):
print(event.phq_attendance, event.category, event.title, event.start.strftime('%Y-%m-%d'))
# The phq_attendance field will only contain a value if there is a predicted