Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save predictioniogists/7092086 to your computer and use it in GitHub Desktop.
Save predictioniogists/7092086 to your computer and use it in GitHub Desktop.
import predictionio
# In the beginning of your application, you need to instantiate the PredictionIO client object.
# You need this client object to import data into PredictionIO and retrieve prediction results.
# Add this line to the place where you do initialization:
cient = predictionio.Client("your App Key")
# Then add the following lines to your codes which handle the corresponding application logic:
# When a new user registers:
try:
client.create_user("the new user ID")
except Exception as e:
log_error(e) # handle error here. You may log the error for debugging or retry importing
# When a new project is added:
try:
client.create_item("the new project ID", ("project category 1",)) # may add more than one category
except Exception as e:
log_error(e) # handle error here. You may log the error for debugging or retry importing
# When a user logs in:
try:
client.identify("the logged-in user ID")
except Exception as e:
log_error(e) # handle error here. You may log the error for debugging or retry importing
# When the logged-in user clicks or views a project:
try:
client.record_action_on_item("view", "the viewed project ID")
except Exception as e:
log_error(e) # handle error here. You may log the error for debugging or retry importing
# When the logged-in user funds a project:
# use built-in action "conversion" to represent the "fund" action
try:
client.record_action_on_item("conversion", "the funded project ID")
except Exception as e:
log_error(e) # handle error here. You may log the error for debugging or retry importing
@mpritham
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment