1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| def import_team(team_id, Users): team = open('import_team.csv', 'w', encoding='utf-8') for i in range(len(Users)): team.writelines('"%d","%d","%s","3","1","1","%s",NULL,NULL,NULL,"0"\n' % (team_id + i, i + 1, Users[i], Users[i])) team.close()
def import_user(user_id, team_id, Users): user = open('import_user.csv', 'w', encoding='utf-8') for i in range(len(Users)): user.writelines('"%d","user%02d","%s",NULL,NULL,NULL,NULL,NULL,NULL,"1","%d"\n' % (user_id + i, i + 1, Users[i], i + team_id)) user.close()
def import_userrole(user_id, Users): userrole = open('import_userrole.csv', 'w', encoding='utf-8') for i in range(len(Users)): userrole.writelines('"%d","3"\n' % (user_id + i)) userrole.close()
if __name__ == '__main__': User_id = 3 Team_id = 1 User = open('user.txt', 'r', encoding='utf-8') User = User.readlines() for j in range(len(User)): User[j] = User[j].strip('\n') import_team(Team_id, User) import_user(User_id, Team_id, User) import_userrole(User_id, User) print(User)
|