Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
 def get(self, name):
             phq = Client(access_token="")
             retJ = []
             if name == '':
                     name = "eminem"
             for event in phq.events.search(q=name, limit=5, sort='rank', category='concerts'):
                     try:
                             cood = event.location
                             local = (rg.search([cood[1],cood[0]]))[0]['name']
                     except IndexError as e:
                             cood = [0,0]
                             local = 'USA'
              #    this = stateplane.identify(cood[0], cood[1])
                     resp = {
                             "eTitle" : event.title,
                             "eDate" : event.start.strftime('%Y-%m-%d'),
                             "eCountry" : event.country,
                             "eRank" : event.rank,
                             "eLocation" : local,
                             }
                     #     print (event.scope, event.description, event.start.strftime
             # ('%Y-%m-%d'), event.category, event.country, event.rank, event.location, event.labels, event.title)
             #    print(event.rank, event.category, event.title, event.start.strftime('%Y-%m-%d'))
                     retJ.append(resp)
             return retJ, 200
Exemple #4
0
 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)
Exemple #5
0
def hazards():
    global hazardskey
    phq = Client(access_token=hazardskey)
    keeps = [
        'scope', 'start', 'active', 'timezone', 'title', 'description',
        'country', 'labels', 'location'
    ]
    params = request.args
    # token = 'VCAUrlQIK04kDFk6AE6_hvR-922LbO8gtrPaUCWN'
    # url = 'https://api.predicthq.com/v1/events/?category=disasters&offset=10&state=active'

    # if 'country' in params : url += f'&country={params["country"]}'
    # if 'from_date' in params : url += f'%start.gt={params["from_date"]}'
    #
    # # response = requests.get(url , headers = { 'Authorization' : f'Bearer {token}' })
    # result = response.json()['results']
    # result = sorted(result , key = lambda r : r['rank'])
    final_result = []
    for j in phq.events.search(category='disasters',
                               state='active',
                               country=params.get('country')):
        obj = {k: v for k, v in j.items() if k in keeps}
        final_result.append(obj)
    return jsonify(final_result)
Exemple #6
0
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
    # attendance for the event and if your subscription includes the feature in
    # your API plan.
Exemple #7
0
from predicthq import Client
import reverse_geocoder as rg

phq = Client(access_token="")

retJ = []

name = "post malone"

for event in phq.events.search(q=name,
                               limit=5,
                               sort='rank',
                               category='concerts'):

    try:
        cood = event.location
        local = (rg.search([cood[1], cood[0]]))[0]['name']
    except IndexError as e:
        cood = [0, 0]
        local = 'USA'
#    this = stateplane.identify(cood[0], cood[1])

    resp = {
        "eTitle": event.title,
        "eDate": event.start.strftime('%Y-%m-%d'),
        "eCountry": event.country,
        "eRank": event.rank,
        "eLocation": local,
    }
    #     print (event.scope, event.description, event.start.strftime
    # ('%Y-%m-%d'), event.category, event.country, event.rank, event.location, event.labels, event.title)
Exemple #8
0
 def __init__(self):
     self.phq = Client(access_token="NHcF5B9PiMCeCrhWENWuRB9SDtSxSB")
Exemple #9
0
 def wrapper(*args, **kwargs):
     return f(client=Client(*client_args, **client_kwargs), *args, **kwargs)
Exemple #10
0
ACCESS_TOKEN = "oxBn3ImPUNkyqpNkukXF4vFQwTDFQD"
endpoint_url = "https://api.predicthq.com"
MAPBOX_ACCESS_TOKEN = 'pk.eyJ1IjoiZWxpemFiZXRoYmxhbmQiLCJhIjoiY2p5M3lxcG5wMDBhbTNobWt6cWo2NHBlNCJ9.vQVHhQNS7bUalBDv8u_iXw'
MAPBOX_STYLE_URL = "mapbox://styles/elizabethbland/cjy3z4qkc357y1cp96obggltm"
predicthq = "predicthq-0.2.0-py2.py3-none-any.whl"

offset = 0
results = []
# search_id='xryjn0ZQzzaDa'

__author__ = 'ebland'

df = pd.read_csv(r'predicthq.csv')
df.drop_duplicates(inplace=True)

phq = Client(access_token='oxBn3ImPUNkyqpNkukXF4vFQwTDFQD')

response = requests.get(url='https://api.predicthq.com/v1/events/',
                        headers={
                            'Authorization':
                            'Bearer oxBn3ImPUNkyqpNkukXF4vFQwTDFQD',
                            'Accept': 'application/json'
                        },
                        params={'id': 'xryjn0ZQzzaDa'})
print(response.json())

for event in phq.events.search(q='storm',
                               rank_level=[1, 2, 3, 4, 5],
                               country='US'):
    print(event.labels, event.id, event.category, event.country,
          event.description, event.rank, event.start,