def setUp(self):
     self.forms = Typeform(TOKEN).forms
     self.responses = Typeform(TOKEN).responses
     if not MOCK:
         form = self.forms.create((dict(title="Responses's test form",
                                        workspace={'href': WORKSPACE})))
         self.formID = form.get('id')
     else:
         self.formID = 'MOCK-FORM-ID'
 def setUp(self):
     self.forms = Typeform(TOKEN).forms
     if not MOCK:
         form = self.forms.create(dict(title="Form's test form", workspace={'href': WORKSPACE}))
         self.formID = form.get('id')
     else:
         self.formID = "MOCK-FORM-ID"
Exemple #3
0
def main():

    # make sure token_env has been set
    if token_env not in os.environ:
        raise Exception(f"Environment variable '{token_env}' not set")

    # retrieve the responses
    print(f"Retreiving TypeForm results for form '{form_id}'")
    responses = Typeform(os.environ[token_env]).responses

    # retrieve the responses dictionary
    dict = fetch_responses_dict(responses, form_id, only_completed_entries)

    if output_file:
        # write the responses dictionary to an output file
        write(output_file, dict)
    else:
        # print the responses to screen
        print(json.dumps(dict, indent=2))
        print(
            "No responses were written to file, and no responses were deleted."
        )
        return  # don't want to risk deleting responses if not stored

    # if True, delete the responses
    if delete_after_retrieving:
        delete_responses_list(responses, form_id, dict)
    def __init__(self, api_key='', *args, **kwargs):
        self.api_key = api_key
        self.typeform = Typeform(api_key)

        self.forms_count = len(self.get_forms_dict()['items'])

        self.forms_name_list = self.get_forms_list(by_name=True)
        self.forms_id_list = self.get_forms_list(by_name=False)
 def __init__(self,
              typeform_pat: str,
              form_id: str,
              question_weights: List[int],
              exclude_field_groups=(0, )):
     """
     :param typeform_pat: Personal Access Token from TypeForm API
     :param form_id: TypeForm Form ID
     :param question_weights: List of weights for each
     """
     self.api_client = Typeform(typeform_pat)
     self.form_id = form_id
     self.exclude_field_groups = exclude_field_groups
     self.question_weights = question_weights
Exemple #6
0
from typeform import Typeform

typeform = Typeform(
    personal_token='xgHiVsz2fK4p4Tgg947WEcJBhvt76yfsachrz1qMxZf')
# tf2 = typeform.Client(personal_token='xgHiVsz2fK4p4Tgg947WEcJBhvt76yfsachrz1qMxZf')

#    typeform.forms.form('asfa').get()

# Fetch all questions from the form
all_forms = typeform.forms.get()
my_form = typeform.form('tqOCMu').get()

# my_form = typeform.form('fYvzZN').delete()
my_responses = typeform.form('tqOCMu').responses.get()

# Fetch all responses to the form with default options
# responses = forms.get_responses()

# Fetch responses with specific options
#responses = form.get_responses(limit=10, since=1487863154)

print("Forms:")
print(all_forms)
print("Questions:")

for question in my_form['fields']:
    print("{}".format(question['title']))

print("Responses: {}".format(len(my_responses['items'])))

for question in my_form['fields']:
Exemple #7
0
 def setUp(self):
     self.forms = Typeform(TOKEN).forms
     form = self.forms.create({
         'title': 'title'
     })
     self.formID = form.get('id')
"""
Reshape initial cultural habits responses in a pandas dataframe and save it in data/dataframe_api_responses.csv.
"""
import json
import os
import re

import pandas as pd
from typeform import Typeform

API_KEY = os.getenv("TYPEFORM_API_KEY")
FORM_ID = os.getenv("PROD_FORM_ID")

# We use the python API to retrieve data on questions
typeform = Typeform(API_KEY)
form = typeform.forms.get(FORM_ID)
fields = (pd.DataFrame(form.get("fields")).rename(columns={
    "id": "question_id"
}).drop("type", axis=1))

# We open the json of saved answers obtained from the API
with open("data/api_responses.json") as json_file:
    responses = json.load(json_file)

# number of users (list of answers for each user)
print(len(responses))

# we want one line for each user answer
dataframe = (pd.DataFrame(responses).explode("answers").dropna().assign(
    network_id=lambda df: df.metadata.apply(lambda metadata: metadata.get(
        "network_id")),
Exemple #9
0
 def fetch_typeform_form_cat(self):
     token_env = 'TYPEFORM_TOKEN'
     if token_env not in os.environ:
         raise Exception(f"Environment variable '{token_env}' not set")
     forms = Typeform(os.environ[token_env]).forms
     return forms
Exemple #10
0
from typeform import Typeform


typeform = Typeform('<typeform-api-token>')
forms = typeform.forms

fields = []


# Sample: multiple chpoice question
multiple_choice = {
      "ref": "<Reference_to_this_question>",
    "title": "<question itself>",
    "type": "multiple_choice",
    "properties": {
        "randomize": False,
        "allow_multiple_selection": False,
        "allow_other_choice": True,
        "vertical_alignment": True,
        "choices": [
          {
            "label": "<multiple choice option_1>",
            "ref": "<reference_to_option_1>"
          },
          {
            "label": "<multiple choice option_2>",
            "ref": "<reference_to_option_2>"
          },
          {
            "label": "<multiple choice option_n>",
            "ref": "<reference_to_option_n>"