Skip to content

Instantly share code, notes, and snippets.

@liling
Created May 12, 2012 09:13
Show Gist options
  • Select an option

  • Save liling/2665413 to your computer and use it in GitHub Desktop.

Select an option

Save liling/2665413 to your computer and use it in GitHub Desktop.
北理工程序设计竞赛:2012年报名名单转换为Moodle导入名单
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import csv, subprocess
tableReader = csv.reader(open('lx.csv', 'rb'), delimiter=',', quotechar='"')
tableWriter = csv.writer(open('mdl-lx.csv', 'wb'))
tableWriter.writerow(['username','password','lastname','firstname','email','description','course1'])
o_username = None
for row in tableReader:
num = row[0]
code = row[1]
name = row[2]
loc = row[3]
if num != '':
# output
if o_username:
tableWriter.writerow([o_username, o_password, o_lastname, o_firstname, o_email, o_description, 'CPC-2012-FORMAL'])
o_username = 'cpc-2012-' + code.lower()
o_firstname = name
o_lastname = '【%s%s-%s】' % (loc, num, code.lower())
o_password = subprocess.check_output(['pwgen', '-1']).strip()
o_email = o_username + '@nomail.com'
o_description = '%s,%s,%s(%s)' % (row[4], row[5], row[6], row[7])
else:
o_description = o_description + ';%s,%s,%s(%s)' % (row[4], row[5], row[6], row[7])
tableWriter.writerow([o_username, o_password, o_lastname, o_firstname, o_email, o_description, 'CPC-2012-FORMAL'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment