Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Using Python to edit exported .txt version of survey (and failing)

  • Lodore
  • Lodore's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 9 months ago #169399 by Lodore
Hello!

This is a slightly odd problem, but thought I'd ask for help anyway.

My task: I have a corpus of 1291 words that I want to get rated along eight different dimensions. I will get these rated in 23 batches of 53 words each. Each batch will be an independent survey. Naturally, I don't want to enter 1291 words into 23 surveys manually.

My solution is to create one survey and populate it with dummy words––e.g. EMPTYSTRING01, EMPTYSTRING01, ..., EMPTYSTRING53. I then export the survey as a tab separated values (.txt) file. This allows me to write a simple python script that searches out the dummy words and replaces them with the actual words I want, which are stored as a row in a python/pandas dataframe and saves the result. This gets done 23 times and voilà, difficult problem solved.

The challenge: Where it goes wrong is when I import the resulting files to Limesurvey. I keep getting an error of the form:

Internal Server Error
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1611-A2-en-0' for key 'PRIMARY'

The survey is still imported, but it can't be previewed and most of the groups are missing (and the ones that aren't missing can't be previewed). I'm baffled as to why a simple find-replace exercise on text should produce this result. I've used this approach before with Qualtrics and it was fine.

Any help would be most appreciated. For reference, I attach an example output file from my python script.

Thanks!
Attachments:
The topic has been locked.
  • Lodore
  • Lodore's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 9 months ago #169454 by Lodore
If anyone comes here with a similar problem, or is just curious, note that the solution is to export the survey as a .lss file, save it with a .txt extension, open it using python to perform the substitution, and save as .lss again. It's a bit of a runaround, but the labour saved is huge when you're generating a lot of survey files from a database of words.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose