0

I try to export users from dabase to CSV file format, after that i import to google contacts. I try many ways but i google dont accept my file. this my code

@dlf.route('/download', methods=['GET'])
def download():
    return render_template('/download.html')


@dlf.route('/download', methods=['POST'])
def download_post():
    if request.form.get('submit_download'):
        try:
            conn = sqlite3.connect(db_file)
            cursor = conn.cursor()
            cursor.execute(
                "SELECT biensoxe, brands, carclass, firstname, lastname, email, phone, address, provinces FROM user")
            list_order = cursor.fetchall()
            print(list_order)
            output = io.StringIO()
            writer = csv.writer(output)
            line = [
                'first_name,last_name,email,phone,address,city']
            writer.writerow(line)
            for row in list_order:
                Name = str(row[4])
                Given_Name = str(row[0])+' ' + str(row[1])+' ' + str(row[2])
                Email = str(row[5])
                Phone_1_Value = str(row[6])
                Address_1_Street = str(row[7])
                Address_1_Region = str(row[8])
                line = [Name + ',' + Given_Name + ',' + Email + ',' + Phone_1_Value + ',' + Address_1_Street + ',' + Address_1_Region ]
                writer.writerow(line)
            output.seek(0)

            return Response(output, mimetype="csv",
                            headers={"Content-Disposition": "attachment;filename=contacts.csv"})

        except Exception as e:
            print('Phat hien ra loi', e)
        finally:
            cursor.close()
            conn.close()
        return redirect(request.referrer)

This is csv file

first_name,last_name,email,phone,address,city
Linh,29NXXX9 BMW 325,myemail@gmail.com,0999999999,None,Hà Nội

1 Answers1

1

You will need to format your CSV file with the headers that Google contacts recognizes. This does not seem to be well documented, but it is possible to find out some headers that Google will accept.

See my answer to: Google Contacts failing to import correctly

Z Yoder
  • 509
  • 4
  • 7