Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Commit

Permalink
dumpComments script now cleans up the comments better, handles Unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmiller committed Feb 14, 2018
1 parent 7bb7ea9 commit 0a84833
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ django-email-templates
python-ldap
MySQL-python
django-tools
unicodecsv

14 changes: 9 additions & 5 deletions scripts/dumpComments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python2.7
import sys, os, django, csv
import sys, os, django, codecs
import unicodecsv as csv

# set up Django
sys.path.insert(0, "/var/django")
Expand Down Expand Up @@ -33,8 +34,11 @@
print "can't find submission #", args.submission
sys.exit(-1)

fields = ["author__username", "text", "start", "end", "created"]
writer = csv.DictWriter(sys.stdout, fields)
writer = csv.DictWriter(sys.stdout, ["username", "created", "text"])
writer.writeheader()
for comment in Comment.objects.filter(chunk__file__submission=submission).values(*fields):
writer.writerow(comment)
lastTextAndUsername = None
for comment in Comment.objects.filter(chunk__file__submission=submission).order_by("author__username","created").select_related("author"):
textAndUsername = [comment.text, comment.author.username]
if textAndUsername != lastTextAndUsername:
writer.writerow({"username": comment.author.username, "created": comment.created, "text": comment.text})
lastTextAndUsername = textAndUsername

0 comments on commit 0a84833

Please sign in to comment.