Skip to content

Instantly share code, notes, and snippets.

@amn41
Last active February 28, 2020 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amn41/b38d9b0d9638eda7a4a9c0e1affd3e47 to your computer and use it in GitHub Desktop.
Save amn41/b38d9b0d9638eda7a4a9c0e1affd3e47 to your computer and use it in GitHub Desktop.
import json
import requests
def get_auth_token(host, user, pw):
url = f"{host}/api/auth"
payload = {"username": user, "password": pw}
response = requests.post(url, json=payload)
try:
token = response.json()["access_token"]
return token
except:
return None
def get_conversations(host, token, limit=100):
url = f"{host}/api/conversations?limit={limit}&exclude_self=true"
headers = {"Authorization": f"Bearer {token}"}
try:
data = requests.get(url, headers=headers).json()
return data
except:
return None
def calculate_conversion(convos):
n_convos = len(convos)
n_clicks = len([c for c in convos if len(c["tags"])>0])
print(f"total conversations: {n_convos}")
print(f"conversations with at least one click: {n_clicks}")
print(f"conversion: {100*n_clicks/n_convos:.1f}%")
def main():
host = "https://carbon.rasa.com"
user = "me"
pw = "pw"
max_conversations = 200
token = get_auth_token(host, user, pw)
convos = get_conversations(host, token, limit=max_conversations)
calculate_conversion(convos)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment