Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. import xlrd
  2. from Drivers.accounts.models import Profile, User
  3. import random
  4. rb = xlrd.open_workbook('final_base.xlsx')
  5. sheet = rb.sheet_by_index(0)
  6. data = []
  7. for rownum in range(1, sheet.nrows):
  8.     row = sheet.row_values(rownum)
  9.     dataitem = []
  10.     for c_el in row:
  11.         dataitem.append(c_el)
  12.     data.append(dataitem)
  13.  
  14.  
  15. for item in data:
  16.     password = random.randint(10000, 99999)
  17.     fullname = item[0].split(' ')
  18.     try:
  19.         user = User.objects.get(username=item[3])
  20.     except:
  21.         user = User.objects.create(username=item[3], first_name=fullname[0],
  22.                                    last_name=fullname[1], password=password,
  23.                                    email=item[3])
  24.         user.save()
  25.     Profile.objects.filter(user=user).update(passw=password, user=user, position=item[1],
  26.         investment=item[2], email=item[3], ava=item[4], holding=item[5],
  27.         company=item[6], cluster=item[7], area=item[8],total=item[9],
  28.         ebitda=item[10], teamInvestment2=item[11], teamInvestment1=item[12],
  29.         wheat_plant=item[13], rape_plant=item[14], soybean_plant=item[15],
  30.         corn_plant=item[16], sunflower_plant=item[17], wheat_plant_price=item[18],
  31.         rape_plant_price=item[19], soybean_plant_price=item[20], corn_plant_price=item[21],
  32.         sunflower_plant_price=item[22], wheat_plant_productivity=item[23],
  33.         rape_plant_productivity=item[24], soybean_plant_productivity=item[25],
  34.         corn_plant_productivity=item[26], sunflower_plant_productivity=item[27],
  35.         companyWeight=item[28])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement