add a few more category methods
This commit is contained in:
parent
e53bd9ae65
commit
9a688fc5c6
1 changed files with 29 additions and 0 deletions
|
@ -36,6 +36,10 @@ class WikiBot
|
|||
def url_no_redirect (title)
|
||||
return @wiki + "index.php?title=" + url_encode(title) + "&redirect=no"
|
||||
end
|
||||
|
||||
def url_page (title)
|
||||
return @wiki + "index.php?title=" + url_encode(title)
|
||||
end
|
||||
|
||||
def url_raw (title)
|
||||
return @wiki + "index.php?title=" + url_encode(title) + "&action=raw"
|
||||
|
@ -197,6 +201,31 @@ class WikiBot
|
|||
return articles
|
||||
end
|
||||
|
||||
def get_categories(title)
|
||||
|
||||
if is_redirect?(title)
|
||||
return []
|
||||
end
|
||||
|
||||
categories = []
|
||||
categories_html = @client.get_content(url_page(title)).scan(/<div id="catlinks">(.*?)<\/div>/)[0][0]
|
||||
categories_html.scan(/title="(.*?)"/) do |m|
|
||||
category = CGI.unescapeHTML(m[0])
|
||||
categories.push(category)
|
||||
end
|
||||
|
||||
return categories[1..-1]
|
||||
end
|
||||
|
||||
def is_in_category?(title, category)
|
||||
|
||||
if is_redirect?(title)
|
||||
return false
|
||||
end
|
||||
|
||||
get_categories(title).member?(category)
|
||||
end
|
||||
|
||||
end # class WikiBot
|
||||
|
||||
end # module MediaWikiBot
|
||||
|
|
Reference in a new issue