# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from three69.apps.core.models import ScrappedDocument
from django.db.utils import IntegrityError


#TODO:
#csv filename to be passed as an argument

import csv

class Command(BaseCommand):
    def handle(self, *args, **options):
        f = open('supermamaforumcomment.csv', "r")
        data = csv.reader(f)
        counter = 0
        for row in data:
            counter +=1
            obj = ScrappedDocument()
            obj.publishing_date = row[0]
            obj.source_id = '3'#row[1]
            obj.item_id = row[2]
            obj.item_link = row[3]
            try:
                obj.unique_id = int("%s%s" % ('3', row[2]))
            except:
                pass
            obj.author = row[4]
            obj.content = row[5]
            obj.subject_title = row[6]
            try:
                obj.save()
            except IntegrityError:
                pass