def check_users(self): start_time = time.time() emails = [] cursor = connection.cursor() cursor.execute("SELECT * FROM smf_members;") rows = cursor.fetchall() for row in rows: try: user = User.objects.get(username=row[1]) except User.DoesNotExist: try: print "User %s does not exist. Creating" % row[1] user = User.objects.create_user(row[1], row[12]) user.set_unusable_password() user.save() profile = Profile() profile.user = user profile.personal_text = row[13] profile.location = row[18] profile.old_user_id = row[0] profile.website = row[17] profile.title = row[32] profile.save() except Exception, e: print "Could not create user %s, %s" % (row[1], str(e))
def convert_users(self): start_time = time.time() emails = [] users = User.objects.values('email') for user in users: emails.append(user["email"]) print emails cursor = connection.cursor() cursor.execute("SELECT * FROM smf_members;") rows = cursor.fetchall() for row in rows: old_id = row[0] username = row[1] date_registered = row[2] post_count = row[3] last_login = row[6] email = row[12] personal_text = row[13] gender = row[14] website = row[17] location = row[18] if email in emails: user = User.objects.get(email=row[12]) profile, created = Profile.objects.get_or_create(user=user) if created: profile.save() else: try: user = User.objects.create_user(row[1], row[12]) user.set_unusable_password() user.save() profile = Profile() profile.user = user profile.personal_text = row[13] profile.location = row[18] profile.old_user_id = row[0] profile.website = row[17] profile.title = row[32] profile.save() except Exception, e: with open("conversion_errors.log", "a") as myfile: myfile.write("%s \r\n %s\r\n\r\n" % (row[1], str(e)))