<commit_before>#!/usr/bin/python
#coding: utf-8

import sys
import os
import csv
from django.core.management import setup_environ

try:
    from scielomanager import settings
except ImportError:
    BASE_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    from sys import path
    path.append(BASE_PATH)
    import settings

setup_environ(settings)

from django.contrib.auth.models import User
from scielomanager.journalmanager import models
from django.db.utils import IntegrityError

'''
    CSV format
    0 = ID
    1 = Nome
    2 = Login
    3 = Email
    4 = collection
    Format example: "antonietayanez","<EMAIL>","yanez","Chile"
    IMPORT: CAN NOT EXIST SPACES BETWEEN COMMA ON CSV FILE.
'''

try:
    filename = sys.argv[1]
except IndexError:
    sys.exit("Please, informe the CSV file!!!")

try:
    with open(filename, 'rb') as f:
        reader = csv.reader(f, delimiter=',', quotechar='"')
        for row in reader:
            try:
                user = User.objects.create_user(username=row[0], email=row[1], password=row[2])
                user_collection = models.UserCollections(user=user, 
                                    collection=models.Collection.objects.get(name=row[3]))
                user_collection.save()
                user.save()
                print "Create User ID: " + str(user.id) + ", Name: " + row[0]
            except (IndexError, IntegrityError) as e:
                sys.exit('Error in the file format %s, line %d: %s' % (filename, reader.line_num, e))
except IOError:
    print "CSV file not found."<commit_msg>Ajuste no script de importação de users<commit_after>#!/usr/bin/python
#coding: utf-8

import sys
import os
import csv
from django.core.management import setup_environ

try:
    from scielomanager import settings
except ImportError:
    BASE_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    from sys import path
    path.append(BASE_PATH)
    import settings

setup_environ(settings)

from django.contrib.auth.models import User
from scielomanager.journalmanager import models
from django.db.utils import IntegrityError

'''
    CSV format
    1 = Nome
    2 = Login
    3 = Email
    4 = collection
    Format example: "antonietayanez","<EMAIL>","yanez","Chile"
    IMPORT: CAN NOT EXIST SPACES BETWEEN COMMA ON CSV FILE.
'''

try:
    filename = sys.argv[1]
except IndexError:
    sys.exit("Please, informe the CSV file!!!")

try:
    with open(filename, 'rb') as f:
        reader = csv.reader(f, delimiter=',', quotechar='"')
        for row in reader:
            try:
                if not User.objects.filter(username=row[0]):
                    user = User.objects.create_user(username=row[0], email=row[1], password=row[2])
                    user_collection = models.UserCollections(user=user,
                                        collection=models.Collection.objects.get(name=row[3]))
                    user_collection.save()
                    user.save()
                    print "Create User ID: " + str(user.id) + ", Name: " + row[0]
            except (IndexError, IntegrityError) as e:
                sys.exit('Error in the file format %s, line %d: %s' % (filename, reader.line_num, e))
except IOError:
    print "CSV file not found."
{'fraction_non_alphanumeric': 0.11511450381679389, 'fraction_numerical': 0.00732824427480916, 'mean_word_length': 2.576419213973799, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5877024', 'n_tokens_mistral': 1019, 'n_tokens_neox': 992, 'n_words': 270}