iT邦幫忙

2025 iThome 鐵人賽

DAY 25
0
# views.py

# 提取年份
def extract_latest_year(source_filenames):

    max_year = 0
    year_pattern = re.compile(r'(19|20)\d{2}') 
    
    if isinstance(source_filenames, list):
        for filename in source_filenames:
            matches = year_pattern.findall(str(filename))
            for year_str in matches:
                try:
                    year = int(year_str)
                    if year > max_year:
                        max_year = year
                except ValueError:
                    pass 
    return max_year
    
# 獲取當前年份作為計算基準
CURRENT_YEAR = datetime.now().year 

for i, item in enumerate(KNOWLEDGE_BASE):
    q_id = item.get('id', i)
    
    if 'error_count' not in item:
        item['error_count'] = 0

    item['latest_appearance_year'] = extract_latest_year(item.get('來源檔案', []))
    
    item['base_trend_score'] = (q_id % 10) + 1 

上一篇
DAY24 - 弱點加強模式
下一篇
DAY26 - 視覺化知識圖譜
系列文
打造你的數位圖書館:從雜亂檔案到個人化知識庫26
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言