-
-
Save p--q/32bfa5c789aa50cd7a24 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
def libreoffice57(): | |
dic_idl_html = dict() # キー:idl、値:idlのhtmlファイル名、の辞書。 | |
dic_memItem_html = dict() # キー:メンバーアイテム、値:メンバーアイテムのhtml、の辞書。 | |
dic_memItem_mdesc = dict() # キー:メンバーアイテム、値:メンバーアイテムの解説、の辞書。 | |
import re #正規表現モジュールのインポート。 | |
reg_idl = r'html">(\w+?)</a>' # 参照しているhtmlファイルのIDLを抽出する正規表現パターン。 | |
reg_idl_html = r'href="(\S+?.html)">\w+?</a></li>\s*?</ul>' # 参照しているhtmlファイル名を抽出する正規表現パターン。 | |
reg_mdesc = r'<td class="mdescRight">(.+?)<a href=' # メンバーアイテムの解説を抽出する正規表現パターン。 | |
import fileinput | |
with fileinput.input(files=('C:/_LibreOffice_test/IDL/a02217.html', 'C:/_LibreOffice_test/IDL/a00795.html', 'C:/_LibreOffice_test/IDL/a03524.html')) as f: # 複数ファイルの読み込み。 | |
line = f.readline() # 1行ずつファイルを読み込む。 | |
while line: # 行がある間実行。 | |
if '<div id="nav-path" class="navpath">' in line: # パンくずリストのdivタグの行があったとき。 | |
line = f.readline() # 次の行を読み込む。 | |
while line: | |
idl = re.findall(reg_idl, line) # 正規表現でIDLのフルネームを抽出する。 | |
if idl: # IDLのフルネームが得られたとき。 | |
idl = "." + ".".join(idl[3:]) # com.sun.starは省略してドットでつなぐ。 | |
idl_html = re.findall(reg_idl_html, line)[0] # 同じ行からhtmlファイル名を抽出。 | |
break # while文を抜ける。 | |
line = f.readline() # 次の行を読み込む。 | |
if any(['<a name="pub-methods">' in line, '<a name="pub-attribs">' in line]): # 「Public Member Functions」または「Public Attributes」のとき。 | |
if idl_html: # パンくずリストからhtmlファイル名が得られているとき。 | |
reg_memItem = r'{0}(#\w+?)">(\w+?)</a>'.format(idl_html) # メンバーアイテム名を抽出する正規表現パターン。 | |
line = f.readline() # 次の行を読み込む。 | |
flag = False # メンバーアイテムがあるかどうかのフラグをリセット。 | |
while line: | |
if any(['<img src="closed.png" alt="-"/>' in line, '</tbody>' in line]): break # 継承したものの項やテーブルの終了にきたときwhile文を抜ける。 | |
memItem = re.findall(reg_memItem, line) # 正規表現でメンバーアイテム名を抽出する。 | |
if memItem: # メンバーアイテム名が抽出できたとき。 | |
flag = True # フラグを立てる。 | |
memItem, memItem_html = idl + "::" + memItem[0][1], idl_html + memItem[0][0] # メンバーアイテム名をそのhtmlファイル名と取得。 | |
dic_memItem_html[memItem] = memItem_html | |
mdesc = re.findall(reg_mdesc, f.readline()) # メンバーアイテム名を得た次行からメンバーアイテムの解説を取得。 | |
if mdesc: dic_memItem_mdesc[memItem] = mdesc[0] # 解説が抽出できたとき辞書に収納。 | |
line = f.readline() # 次の行を読み込む。 | |
if flag: dic_idl_html[idl] = idl_html # メンバーアイテムがあるもののみ出力する。 | |
if '<a name="details" id="details">' in line: # 「Detailed Description」まできたとき | |
f.nextfile() # 次のファイルにいく。 | |
idl_html = "" # IDLのhtmlファイル名をリセット。 | |
line = f.readline() # 次の行を読み込む。 | |
print(dic_idl_html) | |
print(dic_memItem_html) | |
print(dic_memItem_mdesc) | |
if __name__ == "__main__": | |
libreoffice57() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment