医院要用的,内容写完了,接下来就剩下写个模板了。

from flask import Flask
import os

# 资料文件夹目录
dir = '/home/plum/Develop/redleaf/data/'

# 创建全部文件列表
def make_file_list(dir):
    filenamelist = []
    for roots, dirs, files in os.walk(dir):
        filenamelist = files
    return filenamelist

# 搜索年份
def make_year_search(year, filelist):
    includefilelist = []
    for i in filelist:
        if year == i[0:4]:
            includefilelist.append(i)
    return includefilelist

def make_month_search(month, filelist):
    includefilelist = []
    if len(month) < 2:
       month = '0' + month 
    for i in filelist:
        if month == i[4:6]:
            includefilelist.append(i)
    return includefilelist

def make_day_search(day, filelist):
    includefilelist = []
    if len(day) < 2:
        day = '0' + day
    for i in filelist:
        if day == i[6:8]:
            includefilelist.append(i)
    return includefilelist


def make_name_search(name, filelist):
    includefilelist = []
    for i in filelist:
        if name == i.split('-')[1][0:-4]:
            includefilelist.append(i)
    return includefilelist

data = make_file_list(dir)

app = Flask(__name__)

@app.route('/')
def index_hello():
    return '这里是首页请使用URL搜索'

@app.route('/list/<year>/<month>/')
def getyear(year, month):
    print (year)
    print (month)
    data2 = make_year_search(year, data)
    details = make_month_search(month, data2) 
    print(details)
    return 'ok' 

@app.route('/name/<name>/')
def getname(name):
    print(name)
    details = make_name_search(name, data)
    print(details)
    return 'ok'

if __name__ == '__main__':
    app.debug = True
    app.run()