Skip to content

Commit 8d293b1

Browse files
authored
Merge pull request #108 from rosette-api/RCB-601-events-example
RCB-601: /events example
2 parents 1cb3713 + 4a35e54 commit 8d293b1

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

examples/events.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Example code to call Rosette API to get entities from a piece of text.
4+
"""
5+
6+
import argparse
7+
import json
8+
import os
9+
10+
from rosette.api import API, DocumentParameters, RosetteException
11+
12+
13+
def run(key, alt_url='https://api.rosette.com/rest/v1/'):
14+
""" Run the example """
15+
# Create an API instance
16+
api = API(user_key=key, service_url=alt_url)
17+
18+
events_text_data = "I am looking for flights to Super Bowl 2022 in Inglewood, LA."
19+
params = DocumentParameters()
20+
params["content"] = events_text_data
21+
22+
try:
23+
return api.events(params)
24+
except RosetteException as exception:
25+
print(exception)
26+
27+
PARSER = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
28+
description='Calls the ' +
29+
os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
30+
PARSER.add_argument('-k', '--key', help='Rosette API Key', required=True)
31+
PARSER.add_argument('-u', '--url', help="Alternative API URL",
32+
default='https://api.rosette.com/rest/v1/')
33+
34+
if __name__ == '__main__':
35+
ARGS = PARSER.parse_args()
36+
RESULT = run(ARGS.key, ARGS.url)
37+
print(RESULT)

0 commit comments

Comments
 (0)