def handle(self, *args, **options):

        help = 'Imports votes from google spreadsheet to "Votes" table'

        response = urllib.urlopen(URL);
        data = json.loads(response.read())

        votes = data['feed']['entry']

        for e in votes:
            vote = Vote()
            for header, conv_func in VOTE_FIELDS:
                value = e['gsx$' + header]['$t']
                value = conv_func(value)
                if value:
                    setattr(vote, header, value)
                else:
                    print "error in header " + str(header)
                    continue
            try:
                vote.full_clean()
            except ValidationError:
                print "error in vote"
                continue
            try:
                vote.meeting.proposed_bills.add(vote.bill)
            except:
                print "error in adding bill to meeting"
                continue
            try:
                vote.meeting.voting_ministers.add(vote.minister)
            except:
                print "error in adding minister to meeting"
                continue
            if not Vote.objects.filter(bill=vote.bill, minister=vote.minister).count() == 0:
                print "Vote already exists!"
            else:
                vote.save()
                print "Vote saved!"

        print 'Done importing votes from google spreadsheet!!'
Exemple #2
0
    def handle(self, *args, **options):

        #args = '<filename>'
        help = 'Parses the CSV to votes'

        print args[0]

        if len(args) <= 0:
            raise CommandError('Please specify file name')

        if not os.path.exists(args[0]):
            raise CommandError("File %s doesn't exist" % args[0])
        #with codecs.open(args[0], 'r', 'cp1255 ') as f:
        with open(args[0], 'r') as f:
            r = csv.DictReader(f)

            for d in r:
                vote = Vote()
                for header, conv_func in VOTE_FIELDS:
                    value = d[header]
                    value = conv_func(value)
                    if value:
                        setattr(vote, header, value)
                    else:
                        print "error in header " + str(header)
                        continue
                try:
                    vote.full_clean()
                except ValidationError:
                    print "error in vote"
                    continue
                try:
                    vote.meeting.proposed_bills.add(vote.bill)
                except:
                    print "error in adding bill to meeting"
                    continue

                vote.save()

        print 'Done importing votes csv!'
Exemple #3
0
    def handle(self, *args, **options):

        help = 'Imports votes from google spreadsheet to "Votes" table'

        response = urllib.urlopen(URL)
        data = json.loads(response.read())

        votes = data['feed']['entry']

        for e in votes:
            vote = Vote()
            for header, conv_func in VOTE_FIELDS:
                value = e['gsx$' + header]['$t']
                value = conv_func(value)
                if value:
                    setattr(vote, header, value)
                else:
                    print "error in header " + str(header)
                    continue
            try:
                vote.full_clean()
            except ValidationError:
                print "error in vote"
                continue
            try:
                vote.meeting.proposed_bills.add(vote.bill)
            except:
                print "error in adding bill to meeting"
                continue
            try:
                vote.meeting.voting_ministers.add(vote.minister)
            except:
                print "error in adding minister to meeting"
                continue
            if not Vote.objects.filter(bill=vote.bill,
                                       minister=vote.minister).count() == 0:
                print "Vote already exists!"
            else:
                vote.save()
                print "Vote saved!"

        print 'Done importing votes from google spreadsheet!!'
Exemple #4
0
    def handle(self, *args, **options):

        #args = '<filename>'
        help = 'Parses the CSV to votes'

        print args[0]

        if len(args) <= 0:
            raise CommandError('Please specify file name')

        if not os.path.exists(args[0]):
            raise CommandError("File %s doesn't exist" % args[0])
        #with codecs.open(args[0], 'r', 'cp1255 ') as f:
        with open(args[0], 'r') as f:
            r = csv.DictReader(f)

            for d in r:
                vote = Vote()
                for header, conv_func in VOTE_FIELDS:
                    value = d[header]
                    value = conv_func(value)
                    if value:
                        setattr(vote, header, value)
                    else:
                        print "error in header " + str(header)
                        continue
                try:
                    vote.full_clean()
                except ValidationError:
                    print "error in vote"
                    continue
                try:
                    vote.meeting.proposed_bills.add(vote.bill)
                except:
                    print "error in adding bill to meeting"
                    continue

                vote.save()

        print 'Done importing votes csv!'