Last active
December 17, 2017 16:26
-
-
Save LuckyKoala/286cbceb3fcee9a079eb2e232377be62 to your computer and use it in GitHub Desktop.
Query and print as markdown text.Website: http://twodam.net/movie/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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