-
-
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(): | |
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=' # メンバーアイテムの解説を抽出する正規表現パターン。 | |
# with open('C:/Program Files (x86)/LibreOffice 4/sdk/docs/idl/ref/a02217.html', 'r') as f: # com.sun.star.uno.XComponentContext メソッドを持つ。 | |
# with open('C:/Program Files (x86)/LibreOffice 4/sdk/docs/idl/ref/a03524.html', 'r') as f: # com.sun.star.awt.XToolkit メソッドを持つ。 | |
with open('C:/Program Files (x86)/LibreOffice 4/sdk/docs/idl/ref/a00795.html', 'r') as f: # com.sun.star.Text.GenericTextDocument サービス属性を持つ。 | |
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は省略してドットでつなぐ。 | |
print(idl) | |
idl_html = re.findall(reg_idl_html, line)[0] # 同じ行からhtmlファイル名を抽出。 | |
print(idl_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() # 次の行を読み込む。 | |
while line: | |
if any(['<img src="closed.png" alt="-"/>' in line, '</tbody>' in line]): # 継承したものの項やテーブルの終了にきたとき。 | |
break # while文を抜ける。 | |
memItem = re.findall(reg_memItem, line) # 正規表現でメンバーアイテム名を抽出する。 | |
if memItem: # メンバーアイテム名が抽出できたとき。 | |
memItem, memItem_html = idl + "::" + memItem[0][1], idl_html + memItem[0][0] # メンバーアイテム名をそのhtmlファイル名を取得。 | |
print(memItem) | |
print(memItem_html) | |
mdesc = re.findall(reg_mdesc, f.readline())[0] # メンバーアイテム名を得た次行からメンバーアイテムの解説を取得。 | |
print(mdesc) | |
line = f.readline() # 次の行を読み込む。 | |
if '<a name="details" id="details">' in line: # 「Detailed Description」まできたときはwhile文を出る。 | |
break | |
line = f.readline() # 次の行を読み込む。 | |
if __name__ == "__main__": | |
libreoffice57() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment