Month: March 2013

Deleting specific strings from file using Python

I had to delete/replace few words from few text files. Find and Replace feature wouldn’t come handy if there are too many files to edit.

The following python script helps us to replace specific string/phrase from the file with something else.

infile = "file.txt"
outfile = "updated_file.txt"

delete_list = ["phrase1", "phrase2"]
fin = open(infile)
fout = open(outfile, "w+")
for line in fin:
    for word in delete_list:
        line = line.replace(word, "")


Script to import HTML files into Zendesk Forums

Weeks ago, I was given with a task to import bunch of HTML files into Zendesk Forum as articles. As there were thousands of files and it’s tough to copy paste them manually. I got to know that Zendesk offers a rich set of API’s to manage Forum and it’s contents. I have created a Python script to import bunch of offline HTML files into Zendesk Forum creating Topics/articles in a Forum under Categories

We can perform either of the following features in Forum section.

  • List Forums
  • Show Forum
  • Create Forum
  • Update Forum
  • Delete Forum

Example request available in the Zendesk developers page is using curl.

curl -H "Content-Type: application/json" -v -u email:password -X POST -d '{"topic": {"forum_id": 79161, "title": "My Topic", "body":"This is some code", "topic_type": "articles", "access": "logged in users" }'

The above example had a limitation of adding HTML code into<code>, which is impossible when we had thousands of files to be uploaded. Thus I wrote a Python script tweaking the above example, so that I can refer an external file to fetch HTML contents and import it as an individual Topic.

Source can be found here..

To know more, visit for the list of possible JSON requests available in Zendesk.