예제 #1
0
파일: views.py 프로젝트: xiaomao361/project
def upload_excel():
    # excel_path = '/usr/local/nginx/html/zhouwei/app/static/'  # 服务器路径
    excel_path = '/Users/xiaomao/PycharmProjects/zhouwei/app/static/'  # localhost 路径
    excel = request.files['excel']
    excel_name = secure_filename(excel.filename)
    excel.save(os.path.join(excel_path, excel_name))
    from excel import open_excel
    data = open_excel(file='/Users/xiaomao/PycharmProjects/zhouwei/app/static/%s' % excel_name)
    table = data.sheets()[0]
    nrows = table.nrows
    # ncols = table.ncols
    datas = []
    for i in range(nrows):
        rs = table.row_values(i)
        datas.append(rs)
    for email_list in datas:
        email_db = ZwMySQL()
        name = email_list[0]
        email = email_list[1]
        belong = email_list[2]
        try:
            email_db.add_email(name, email, belong, '')
            flash('add success')
        except Exception as e:
            flash('add %s error' % email)
            app.logger.error("add %s error %s" % (email, e))
    return render_template('upload_excel.html',
                           url='upload_email',
                           user='******',
                           per_act='active',
                           datas=datas,
                           person_no=len(datas))
예제 #2
0
파일: views.py 프로젝트: xiaomao361/project
def add_email():
    name = request.form.get('name')
    email = request.form.get('email')
    belong = request.form.get('belong')
    type = request.form.get('type')
    email_db = ZwMySQL()
    email_db.add_email(name, email, belong, type)
    return redirect(url_for('periodical'))