FC2ブログ 記事データバックアップ&キーワード検索スクリプト
年始に「FC2ブログ バックアップデータ検索プログラム作成」を書いていたので、掲載しておこうかと。
【2021/07/18 追記】
※2021/06/末よりhCaptchaが入り以下の「【記事データバックアップスクリプト】」は動かないものとなりました…
理由はこちら。
【事の始まり】
本ブログには画面左のところに、FC2ブログ公式のキーワード検索プラグインを仕込んでいるのですが(これは若干利便性を上げる改造をしてある)、実は以前から「あれっ?確かこの単語で記事を書いたの見つからないな…」というのが分かっており、騙し騙し使っていたり、「確実に検索するなら、公式のデータバックアップサービスで落としたテキストファイルをgrepした方が早いな…」という感じで運用していました。
ただし、バックアップのファイルフォーマット仕様の場合、「単純なgrepだと色々と調べる際に分かりづらかったり」、「期間検索」や「その結果からカウントしたい」といった事がサクッとできないので、「どーせなら自作してしまうか…」と、キーワード検索スクリプト作ってみたのが事の始まりです。
また、キーワード検索スクリプトを作ったあとに、ついでに「いままでブラウザからFC2ブログの管理画面に行って、そこからバックアップサービスの画面に遷移し、更にそこから全記事をダウンロードという事を手動でやっていた」事をスクリプトで実施するかな…とスクリプトを作ってみました。(ただし、セキュリティ面、環境面で色々と制約あり)
開発言語はPythonです。
【2021/07/18 追記】
※2021/06/末よりhCaptchaが入り以下の「【記事データバックアップスクリプト】」は動かないものとなりました…
理由はこちら。
【事の始まり】
本ブログには画面左のところに、FC2ブログ公式のキーワード検索プラグインを仕込んでいるのですが(これは若干利便性を上げる改造をしてある)、実は以前から「あれっ?確かこの単語で記事を書いたの見つからないな…」というのが分かっており、騙し騙し使っていたり、「確実に検索するなら、公式のデータバックアップサービスで落としたテキストファイルをgrepした方が早いな…」という感じで運用していました。
ただし、バックアップのファイルフォーマット仕様の場合、「単純なgrepだと色々と調べる際に分かりづらかったり」、「期間検索」や「その結果からカウントしたい」といった事がサクッとできないので、「どーせなら自作してしまうか…」と、キーワード検索スクリプト作ってみたのが事の始まりです。
また、キーワード検索スクリプトを作ったあとに、ついでに「いままでブラウザからFC2ブログの管理画面に行って、そこからバックアップサービスの画面に遷移し、更にそこから全記事をダウンロードという事を手動でやっていた」事をスクリプトで実施するかな…とスクリプトを作ってみました。(ただし、セキュリティ面、環境面で色々と制約あり)
開発言語はPythonです。
【記事データバックアップスクリプト】
開発順序は逆でしたが、作業的には検索を行う元データを取得する必要があるので、まずはこちらから。
[機能]
FC2ID(のブログ管理画面)にログインして、記事データバックアップサービスからバックアップデータをダウンロードします。
[動作環境]
(1) Linux Ubuntu系 64bit (とりあえず大分古いLinux Mint 18.1 Serenaで確認)
(2) Python 3.6.8 (これも大分古い)
(3) Chromium 87.0.4280.66
(4) Chronium WebDriver 87.0.4280.88
(5) Pythonライブラリ:selenium (pipにてインストール)
[制約]
(1) ブラウザをChromium限定としています。
(FirefoxやEdgeは嫌いなので今回は見捨てる。
ただEdgeは今となってはChroniumだけど)
(2) FC2IDの二段階認証には対応していません。(当然ですが)
二段階認証が発生する状態の場合は事前にブラウザを使って
管理画面に一度ログインしておくと、出なくなると思います。
(発動条件はFC2ID事務局が独自に定めている模様)
(3) Linuxをベースとしているので、Windows上などで動かしたい場合は
ソースを変更してください。
[使い方 (コマンドライン)]
[ソースファイル (fc2-blog-get-backup-data.py)]
ソースはスクリプトということで、ログイン情報はソースに埋め込んであり、ソース内「# ログイン情報」の以下の3点をユーザに合ったものを記述します。
(1) FC2IDログインID(メールアドレス or ブログID)
(2) FC2IDログインパスワード
(3) バックアップデータファイル名「<ブログID>.txt」
【キーワード検索スクリプト】
こちらが本丸です。
[機能]
FC2ブログデータバックアップファイルから記事内のキーワードを検索します。
期間指定ができます。
OR条件で検索キーワードが指定できます。
キーワードを色付き(赤色)で表示できます。
[動作環境]
[Linux]
(1) Linux Ubuntu系 64bit (とりあえず大分古いLinux Mint 18.1 Serenaで確認)
(2) Python 3.6.8 (これも大分古い)
[Windows 10]
(1) Windows 10 20H2 64bit
(2) WSL Ubuntu Version1
(3) Python 3.9.1
[制約]
(1) キーワード検索に正規表現は使えません。(少し改造すれば行けると思います)
(2) キーワード色付き表示指定時にignore case(大文字小文字の区別なし)を行うと
色付き箇所は実際のデータの文字列ではなく、指定キーワードにて表示されます。
(3) 記事内に記述してある特殊文字(ハートなど)やHTMLコードは記事内の
データとして指定する必要があります。(当たり前といえば当たり前)
(4) (3)同様に「~」のようないわゆる「WAVE DASH問題」のようなものは正しく
指定する必要があります。
[使い方 (コマンドライン)]
[ソースファイル (fc2-blog-analyzer.py)]
◇ ◇ ◇
FC2ブログで記事をキチンと管理していたり、記事に対してあれこれ思い出したりして観覧をし直す人専用という物凄くニッチなものですが、私の利便性と腕がなまらないように頭の体操で作ったものなので、結構いい加減という感じです。
開発順序は逆でしたが、作業的には検索を行う元データを取得する必要があるので、まずはこちらから。
[機能]
FC2ID(のブログ管理画面)にログインして、記事データバックアップサービスからバックアップデータをダウンロードします。
[動作環境]
(1) Linux Ubuntu系 64bit (とりあえず大分古いLinux Mint 18.1 Serenaで確認)
(2) Python 3.6.8 (これも大分古い)
(3) Chromium 87.0.4280.66
(4) Chronium WebDriver 87.0.4280.88
(5) Pythonライブラリ:selenium (pipにてインストール)
[制約]
(1) ブラウザをChromium限定としています。
(FirefoxやEdgeは嫌いなので今回は見捨てる。
ただEdgeは今となってはChroniumだけど)
(2) FC2IDの二段階認証には対応していません。(当然ですが)
二段階認証が発生する状態の場合は事前にブラウザを使って
管理画面に一度ログインしておくと、出なくなると思います。
(発動条件はFC2ID事務局が独自に定めている模様)
(3) Linuxをベースとしているので、Windows上などで動かしたい場合は
ソースを変更してください。
[使い方 (コマンドライン)]
引数に「-h」でusageが表示されます。 ~/bin $ fc2-blog-get-backup-data.py -h usage: fc2-blog-get-backup-data.py [-h] [-p OUTPUT_PATH] [-t] FC2ブログ バックアップデータ取得 optional arguments: -h, --help show this help message and exit -p OUTPUT_PATH, --output-path OUTPUT_PATH 出力先パス -t, --time-stamp ファイル名の末尾に生成時刻を付与する。 正常終了すると、カレントディレクリ(-p未指定時)に「<ブログID>.txt」の テキストファイルが出力されます。 例) $ python fc2-blog-get-backup-data.py -p ~/databackup/ -t ログイン画面遷移開始。 ログイン画面遷移成功。 管理画面遷移開始。 管理画面遷移成功。 ファイル保存監視開始。 ダウンロード完了。 [出力ファイル] ~/databackup/hoge-2021-01-16_23-59-59.txt |
[ソースファイル (fc2-blog-get-backup-data.py)]
ソースはスクリプトということで、ログイン情報はソースに埋め込んであり、ソース内「# ログイン情報」の以下の3点をユーザに合ったものを記述します。
(1) FC2IDログインID(メールアドレス or ブログID)
(2) FC2IDログインパスワード
(3) バックアップデータファイル名「<ブログID>.txt」
ダウンロードが成功したら、このファイルをFC2ブログデータバックアップファイルとしてキーワード検索スクリプトにかけます。
#!/bin/sh
# coding: utf-8
""":"
exec python "$0" "$@"
"""
__doc__ = """The above defines the script's __doc__ string. You can fix it by like this."""
# おまじない終わり
# OS 関連
import os
# シェル系
import shutil
# 時間関連
import time
import datetime
# コマンドライン解析関連
import argparse
# ファイル列挙関連
import glob
# Selenium WebDriver (事前にドライバを入れておかないと動かない)
from selenium import webdriver
# 今回は Chrome(Chromium)
from selenium.webdriver.chrome.options import Options
# ログイン情報
USER_NAME = '<FC2IDログインID>'
PASSWORD = '<パスワード>'
BACKUP_FILE = '<ブログID>.txt'
# パラメータ設定
parser = argparse.ArgumentParser(description='FC2ブログ バックアップデータ取得')
parser.add_argument('-p', '--output-path', help='出力先パス')
parser.add_argument('-t', '--time-stamp', action='store_true', help='ファイル名の末尾に生成時刻を付与する。')
args = parser.parse_args()
CHROME_BIN = '/usr/bin/chromium-browser'
WEB_DRIVER = os.path.expanduser('/usr/bin/chromedriver')
options = Options()
options.set_headless()
options.binary_location = CHROME_BIN
#options.add_argument('--window-size=1280,3000') # スクリーンショット向け
# ドライバインスタンスを作成
driver = webdriver.Chrome(WEB_DRIVER, chrome_options=options)
# バックアップファイルを削除(エラーは無視)
try:
os.remove(BACKUP_FILE)
except:
pass
# ログインページ(2021/01 現在)
print('ログイン画面遷移開始。')
driver.get('https://fc2.com/ja/login.php?ref=blog')
time.sleep(3) # とりあえず少し待つ
if 'https://fc2.com/ja/login.php?ref=blog' != driver.current_url:
print('ログイン画面に遷移できませんでした。[' + driver.current_url + ']')
exit(1)
print('ログイン画面遷移成功。')
login_username = driver.find_element_by_id('id')
login_username.clear()
login_username.send_keys(USER_NAME)
login_password = driver.find_element_by_id('pass')
login_password.clear()
login_password.send_keys(PASSWORD)
login_password.submit()
time.sleep(3)
#driver.save_screenshot("ss1.png") # スクリーンショット
# バックアップデータ全て取得
print('管理画面遷移開始。')
driver.get('https://admin.blog.fc2.com/control.php?mode=control&process=backup&type=all')
time.sleep(3)
if not 'https://admin.blog.fc2.com' in driver.current_url:
print('管理画面に遷移できませんでした。[' + driver.current_url + ']')
exit(1)
print('管理画面遷移成功。')
#driver.save_screenshot("ss2.png")
print('ファイル保存監視開始。')
# ファイル保存完了の監視
# OS, ブラウザによって中間ファイルの保存方法が違うので、
# 今回は Linux mint & Chronium の方法を取る
file_size_last = -1
file_size_now = 0
retry = 0
while True:
files = glob.glob(BACKUP_FILE + '*')
if len(files) == 0:
retry += 1
if retry == 10:
print('対象のファイルが作成されていません。[' + BACKUP_FILE + ']')
exit(1)
time.sleep(2)
continue
# まだダウンロード中
if not BACKUP_FILE in files:
time.sleep(2)
continue
try:
file_size_now = os.path.getsize(BACKUP_FILE)
except:
# ファイルダウンロードにしばらく時間がかかるかもことを考慮してリトライ
retry += 1
if retry == 10:
print('ファイルサイズ取得に失敗しました。')
exit(1)
continue
# しばらくサイズが変化してなければダウンロード完了とする
if file_size_last == file_size_now:
break
file_size_last = file_size_now
if file_size_now == 0:
retry += 1
if retry == 10:
print('ファイルがダウンロードできていないので中止します')
exit(1)
else:
retry = 0
print('ダウンロード完了。')
# 出力先を指定していたら移動
if args.output_path:
# ファイルと拡張子を分離
file_name, file_ext = os.path.splitext(BACKUP_FILE)
# ファイルを移動
try:
if args.time_stamp:
dest_path = args.output_path + '/' + file_name + '-' + \
datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + file_ext
else:
dest_path = args.output_path + '/' + BACKUP_FILE
shutil.move(BACKUP_FILE, dest_path)
except:
print('ファイルの移動に失敗しました。[' + dest_path + ']')
【キーワード検索スクリプト】
こちらが本丸です。
[機能]
FC2ブログデータバックアップファイルから記事内のキーワードを検索します。
期間指定ができます。
OR条件で検索キーワードが指定できます。
キーワードを色付き(赤色)で表示できます。
[動作環境]
[Linux]
(1) Linux Ubuntu系 64bit (とりあえず大分古いLinux Mint 18.1 Serenaで確認)
(2) Python 3.6.8 (これも大分古い)
[Windows 10]
(1) Windows 10 20H2 64bit
(2) WSL Ubuntu Version1
(3) Python 3.9.1
[制約]
(1) キーワード検索に正規表現は使えません。(少し改造すれば行けると思います)
(2) キーワード色付き表示指定時にignore case(大文字小文字の区別なし)を行うと
色付き箇所は実際のデータの文字列ではなく、指定キーワードにて表示されます。
(3) 記事内に記述してある特殊文字(ハートなど)やHTMLコードは記事内の
データとして指定する必要があります。(当たり前といえば当たり前)
(4) (3)同様に「~」のようないわゆる「WAVE DASH問題」のようなものは正しく
指定する必要があります。
[使い方 (コマンドライン)]
引数に「-h」でusageが表示されます。 ~ $ fc2-blog-analyzer.py -h usage: fc2-blog-analyzer.py [-h] [-s START_DATE] [-e END_DATE] [-i] [-c] src_file [search_words [search_words ...]] FC2ブログ バックアップデータ解析 positional arguments: src_file バックアップデータ search_words 検索キーワード optional arguments: -h, --help show this help message and exit -s START_DATE, --start-date START_DATE 開始日付(未指定時は2000/1/1 00:00:00) -e END_DATE, --end-date END_DATE 終了日付(未指定時は現時点) -i, --ignore-case 大文字小文字の区別なし -c, --color キーワード色付き (1) 検索キーワードを指定しない場合は期間に該当する記事が全て表示されます。 (注意:期間を指定しないと前記事が表示されます) (2) 指定期間内の記事にて検索キーワードがヒットすると、記事の情報が記事ヘッダとして 表示されます。また、検索キーワードがコメント場合、記事ヘッダ同様にコメントヘッダが 表示されます。 (3) 記事ヘッダは「記事を書いた人:」「記事タイトル:」「記事カテゴリ:」「記事日付:」が 表示されます。 (4) コメントヘッダは「コメント発言者:」「コメント発言者 タイトル:」「コメント発言者 URL:」 「コメント発言者 EMAIL:」「コメント発言者 日付:」が表示されます。 例) ~ $ fc2-blog-analyzer.py ~/databackup/記事.txt hitomi -i -c -------- 記事を書いた人: OKI 記事タイトル: 私のおさえているマナーについて 記事カテゴリ: お知らせ/このブログの事/私の事 記事日付: 2012-03-21 03:10:35 -------- 仁見 鈴香 (ひとみ りんか:hitomi rinka) hitomi Rinka、Rinka hitomi 有木 瞳 (ゆうき ひとみ:yuuki hitomi) hitomi YUUKI、YUUKI hitomi 例) 他のコマンドとの組み合わせ応用 ~ $ fc2-blog-analyzer.py ~/databackup/記事.txt '謎のパイセン' -s 2020/1/1 -e 2020/12/31| \ grep 'コメント発言者: 謎のパイセン'|wc -l 48 謎のパイセンさんが2020年中に48件コメントを書いてきている事が分かる。 |
[ソースファイル (fc2-blog-analyzer.py)]
#!/bin/sh
# coding: utf-8
""":"
exec python "$0" "$@"
"""
__doc__ = """The above defines the script's __doc__ string. You can fix it by like this."""
# おまじない終わり
# OS 関連
import os
# システム関連
import sys
# コマンドライン解析関連
import argparse
# 日付関連
import datetime
# 正規表現関連
import re
# 指定日付範囲を確認
def is_date_range(date, start_date, end_date):
if date is None:
return False
if start_date > date:
return False
if end_date < date:
return False
return True
# 検索ヒットチェック
def is_hit_words(text, words, ignore_case):
hit = False
if ignore_case:
i_text = text.lower()
hit = [True for i in words if i.lower() in i_text]
# 大文字小文字の区別あり
else:
hit = [True for i in words if i in text]
return hit
# ヘッダを表示
def print_header(header):
print('--------')
print('記事を書いた人: ' + header[1][1])
print('記事タイトル: ' + header[2][1])
print('記事カテゴリ: ' + header[3][1])
print('記事日付: ' + str(header[4][1]))
print('--------')
# コメントヘッダを表示
def print_comment_header(header):
print('--------')
print('コメント発言者: ' + header[1][1])
print('コメント発言者 タイトル: ' + header[2][1])
print('コメント発言者 URL: ' + header[3][1])
print('コメント発言者 EMAIL: ' + header[4][1])
print('コメント発言者 日付: ' + str(header[6][1]))
print('--------')
# キーワードを色付して作成
def make_highlight_keyword(text, keywords, ignore_case, flag):
if flag == False:
return text
for key in keywords:
# 大文字小文字区別しない
if ignore_case:
# 元の文章を壊してはいけないので、考慮しながら置換を行う
# result_text += '\033[31m' + text[index2:index2 + key_len] + '\033[0m'
pattern = re.compile(key, re.IGNORECASE)
text = pattern.sub('\033[31m' + key + '\033[0m', text)
# 大文字小文字区別する
else:
text = text.replace(key, '\033[31m' + key + '\033[0m')
return text
# パラメータ設定
parser = argparse.ArgumentParser(description='FC2ブログ バックアップデータ解析')
parser.add_argument('src_file', help='バックアップデータ')
parser.add_argument('search_words', nargs='*', help='検索キーワード')
parser.add_argument('-s', '--start-date', help='開始日付')
parser.add_argument('-e', '--end-date', help='終了日付')
parser.add_argument('-i', '--ignore-case', action='store_true', help='大文字小文字の区別なし')
parser.add_argument('-c', '--color', action='store_true', help='キーワード色付き')
args = parser.parse_args()
#----
# 日付引数解析
#----
start_date = datetime.datetime.strptime('2000/1/1 0:0:0', "%Y/%m/%d %H:%M:%S")
end_date = datetime.datetime.now().replace(microsecond=0)
if args.start_date:
try:
start_date = datetime.datetime.strptime(args.start_date, "%Y/%m/%d %H:%M:%S")
except ValueError:
try:
start_date = datetime.datetime.strptime(args.start_date, "%Y/%m/%d")
except ValueError:
print('時刻フォーマットが不正です。(\'yyyy/mm/dd\' or \'yyyy/mm/dd HH:MM:SS\')')
exit(1)
start_date.replace(microsecond=0)
if args.end_date:
try:
end_date = datetime.datetime.strptime(args.end_date, "%Y/%m/%d %H:%M:%S")
except ValueError:
try:
end_date = datetime.datetime.strptime(args.end_date + ' 23:59:59', "%Y/%m/%d %H:%M:%S")
except ValueError:
print('時刻フォーマットが不正です。(\'yyyy/mm/dd\' or \'yyyy/mm/dd HH:MM:SS\')')
exit(1)
end_date.replace(microsecond=0)
if start_date > end_date:
print('日付指定が終了日より開始日の方が未来になっています。')
exit(1)
#print('-------------')
#print('src-file : ', args.src_file)
#print('search_words: ', args.search_words)
#print('start-date : ', start_date)
#print('end-date : ', end_date)
#print('color : ', args.color)
#print('-------------')
#----
# ファイルを開いて全レコードを読む
#----
with open(args.src_file, 'r') as f:
# 記事カウンタ
article_count = 1
# 記事セパレータ
article_sep = '--------'
# 記事内の項目セパレータ
separator = '-----'
# 記事内の項目セパレータフラグ
flag_sep = False
# 記事ヘッダ情報
article_header = {}
# 記事日付
article_date = None
# コメントヘッダ情報
comment_header = {}
# モード(HEADER, BODY, BODY_EXTEND, EXCERPT, KEYWORDS, COMMENT
mode_type = 'HEADER'
# コメントヘッダ解析
#flag_comment_header = False
# 対象記事内の検索ヒットカウント
search_hit_count = 0
search_hit_comment_count = 0
for line in f:
record = line.rstrip('\n')
# 次の記事に来たら記事内の判定情報をリセット
if record == article_sep:
#print('ARTICLE END', article_count)
article_count += 1
mode_type = 'HEADER'
article_date = None
#flag_comment_header = False
search_hit_count = 0
search_hit_comment_count = 0
continue
# ヘッダ解析
if mode_type == 'HEADER':
if record.startswith('AUTHOR: '):
article_header[1] = ('AUTHOR', record[record.find(': ') + 2:])
continue
if record.startswith('TITLE: '):
article_header[2] = ('TITLE', record[record.find(': ') + 2:])
continue
if record.startswith('CATEGORY: '):
article_header[3] = ('CATEGORY', record[record.find(': ') + 2:])
continue
if record.startswith('DATE: '):
article_header[4] = ('DATE', datetime.datetime.strptime(record[len('DATE: '):], "%m/%d/%Y %H:%M:%S"))
article_date = datetime.datetime.strptime(record[len('DATE: '):], "%m/%d/%Y %H:%M:%S")
continue
# コメント解析
if mode_type == 'COMMENT':
#if flag_comment_header:
if record.startswith('AUTHOR: '):
comment_header[1] = ('AUTHOR', record[record.find(': ') + 2:])
continue
elif record.startswith('TITLE: '):
comment_header[2] = ('TITLE', record[record.find(': ') + 2:])
continue
elif record.startswith('URL: '):
comment_header[3] = ('URL', record[record.find(': ') + 2:])
continue
elif record.startswith('EMAIL: '):
comment_header[4] = ('EMAIL', record[record.find(': ') + 2:])
continue
elif record.startswith('IP: '):
comment_header[5] = ('IP', record[record.find(': ') + 2:])
continue
elif record.startswith('DATE: '):
comment_header[6] = ('DATE', datetime.datetime.strptime(record[len('DATE: '):], "%m/%d/%Y %H:%M:%S"))
continue
elif record.startswith('SECRET: '):
comment_header[7] = ('SECRET', record[record.find(': ') + 2:])
continue
elif record.startswith('PASS: '):
comment_header[8] = ('PASS', record[record.find(': ') + 2:])
continue
# コメントヘッダ終わり
else:
#flag_comment_header = False
# コメントヘッダモード終了の時はヘッダの内容を検索してみる
hit_count = 0
for i in range(1, 5):
if is_hit_words(comment_header[i][1], args.search_words, args.ignore_case):
comment_header[i] = (comment_header[i][0], make_highlight_keyword(comment_header[i][1], args.search_words, args.ignore_case, args.color))
hit_count += 1
# 検索ヒット初回で且つヘッダ内にヒットがあった場合はヘッダを表示
if is_date_range(comment_header[6][1], start_date, end_date):
if (search_hit_comment_count == 0) and (hit_count > 0):
search_hit_comment_count += 1
print_comment_header(comment_header)
# セパレータチェック
if record == separator:
# ヘッダモード終了の時はヘッダの内容を検索してみる
hit_count = 0
for i in range(1, 4):
if is_hit_words(article_header[i][1], args.search_words, args.ignore_case):
article_header[i] = (article_header[i][0], make_highlight_keyword(article_header[i][1], args.search_words, args.ignore_case, args.color))
hit_count += 1
# 検索ヒット初回で且つヘッダ内にヒットがあった場合はヘッダを表示
if (search_hit_count == 0) and (hit_count > 0):
search_hit_count += 1
print_header(article_header)
# なにかしらのモードは終わり
mode_type = ''
# コメントの検索カウント初期化(BODY の方は総合カウントなので記事が終わるまで初期化なし)
search_hit_comment_count = 0
# セパレータ ON
flag_sep = True
continue
# セパレータ直下の各モードを確認
if flag_sep:
if record == 'BODY:':
mode_type = 'BODY'
if record == 'EXTENDED BODY:':
mode_type = 'BODY_EXTEND'
if record == 'KEYWORDS:':
mode_type = 'KEYWORDS'
if record == 'COMMENT:':
mode_type = 'COMMENT'
flag_comment_header = True
search_hit_comment_count = 0
# モードの解析が済んだらセパレータを OFF
flag_sep = False
continue
# 空行はスキップ
if not record:
continue
# 日付チェック
# まだ日付解析が終わってない場合はスキップ
if not is_date_range(article_date, start_date, end_date):
continue
# 検索キーワードが設定されていない場合は記事全部
if len(args.search_words) == 0:
# 初めて検索キーワードが発見された場合ヘッダを表示
if search_hit_count == 0:
print_header(article_header)
# コメントモード時の初回ヒットの場合コメントヘッダを表示
if mode_type == 'COMMENT':
if search_hit_comment_count == 0:
print_comment_header(comment_header)
search_hit_comment_count += 1
search_hit_count += 1
print(record)
continue
# キーワード検索
if is_hit_words(record, args.search_words, args.ignore_case):
# 初めて検索キーワードが発見された場合ヘッダを表示
if search_hit_count == 0:
print_header(article_header)
# コメントモード時の初回ヒットの場合コメントヘッダを表示
if mode_type == 'COMMENT':
if is_date_range(comment_header[6][1], start_date, end_date):
if search_hit_comment_count == 0:
print_comment_header(comment_header)
search_hit_comment_count += 1
search_hit_count += 1
print(make_highlight_keyword(record, args.search_words, args.ignore_case, args.color))
FC2ブログで記事をキチンと管理していたり、記事に対してあれこれ思い出したりして観覧をし直す人専用という物凄くニッチなものですが、私の利便性と腕がなまらないように頭の体操で作ったものなので、結構いい加減という感じです。
コメント
コメントの投稿