How to export all Questions and answers to csv or excel file?
I have exported dialogflow agent in to zip file and I got the two json files for each question or intent.
Is there any way to create a Question and answer pair in csv or excel file?
The zip file contains two directories intents and entities. The intents directory contains Dialogflow each intents' response and training phrases. You can observe the pattern in JSON files and write a script to make a csv file out of it.
import os
import csv
import json
all_intents = os.listdir('intents')
with open('agent.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Response", "Questions"])
for intent in all_intents:
write = []
if intent.find('_usersays_en.json') == -1:
try:
with open('intents/' + intent) as f:
data = json.load(f)
resp = ''
try:
resp = data['responses'][0]['messages'][0]['speech'][0]
except:
print(intent)
write.append(resp)
except:
print(intent)
try:
with open('intents/' + intent.replace(".json", "") + '_usersays_en.json') as f:
data = json.load(f)
for d in data:
qn = (d['data'][0]['text'])
write.append(qn)
except:
print(intent.replace(".json", "") + '_usersays_en.json')
writer.writerow(write)
Instructions to run the code: