Skip to content

Instantly share code, notes, and snippets.

@LuckyKoala
Last active December 17, 2017 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuckyKoala/286cbceb3fcee9a079eb2e232377be62 to your computer and use it in GitHub Desktop.
Save LuckyKoala/286cbceb3fcee9a079eb2e232377be62 to your computer and use it in GitHub Desktop.
Query and print as markdown text.Website: http://twodam.net/movie/
#!/usr/bin/env python
#-*- coding:utf-8 -*-
'''
连接数据库,查询表信息,生成markdown文档内容
'''
from __future__ import print_function
import mysql.connector
import getpass
password = getpass.getpass()
conn = mysql.connector \
.connect(user='root',password=password, \
database='luckykoala',use_unicode=True)
cursor = conn.cursor()
cursor.execute('select id, chinese_name, foreign_name from movie')
values = cursor.fetchall()
print('========================')
print('|序号|中文名|外文名|')
print('|:---:|:---:|:---:|')
for t in values:
'''
Hardcode for three column table
'''
print('|%s|__%s__|_%s_|'% (t[0], t[1], t[2]))
print('========================')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment