Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # encoding: utf-8
- import datetime
- import MySQLdb
- from django.core.management import setup_environ
- import settings
- setup_environ(settings)
- from django.db.utils import IntegrityError
- from django.contrib.auth.models import User
- from profiles.models import *
- def format_unixtime(datestring):
- dt = datetime.datetime.fromtimestamp(float(datestring))
- return dt
- def check_value(user_value):
- if user_value:
- decoded_data = user_value.decode('latin-1')
- return decoded_data[:30]
- else:
- return ''
- con = MySQLdb.connect(user='root', db='mydb', passwd='pass', host='localhost')
- cursor = con.cursor()
- # setting the statement
- cursor.execute ("Select * from user")
- # get all rows
- rows = cursor.fetchall()
- # print all rows
- for row in rows:
- try:
- if row[44] == 'y':
- print(check_value(row[3]))
- user = User(
- id = row[0],
- username = check_value(row[1]),
- first_name = unicode(check_value(row[2])),
- last_name = unicode(check_value(row[3])),
- email =row[6],
- password = row[5],
- is_staff = 0,
- is_active = 1,
- is_superuser = 0,
- last_login = format_unixtime(row[46]),
- date_joined = format_unixtime(row[43])
- )
- user.save(force_insert=True)
- print('User created')
- else:
- print('user not activated')
- except IntegrityError as detail:
- print('Error', detail)
- # close cursor
- cursor.close()
- #close connection
- con.close()
Add Comment
Please, Sign In to add comment