Browse Source

Replace Mechanize.new calls with agent, add member link to illust

master
Daniel Muckerman 8 years ago
parent
commit
2c0b0f07ff
2 changed files with 14 additions and 7 deletions
  1. +10
    -2
      slack-pixiv/commands/illust.rb
  2. +4
    -5
      slack-pixiv/commands/member.rb

+ 10
- 2
slack-pixiv/commands/illust.rb View File

@ -23,8 +23,16 @@ module SlackMathbot
ios_url = "pixiv://illusts/" + pixiv_url[/\d+/] ios_url = "pixiv://illusts/" + pixiv_url[/\d+/]
puts ios_url puts ios_url
# Scrape profile link
profile = agent.get(pixiv_url).at("div.userdata > h2.name > a").attributes['href'].to_s
puts profile
# Create iOS Members URL
ios_mem_url = "pixiv://users/" + profile[/\d+/]
puts ios_mem_url
# Scrape page title # Scrape page title
title = Mechanize.new.get(pixiv_url).title
title = agent.get(pixiv_url).title
puts title puts title
# Scrape image # Scrape image
@ -37,7 +45,7 @@ module SlackMathbot
attachments: [ attachments: [
{ {
fallback: title + " - " + pixiv_url, fallback: title + " - " + pixiv_url,
text: "<" + ios_url + "|Open in App>",
text: "<" + ios_url + "|Open Image in App> | <" + ios_mem_url + "|Open Profile in App>",
title: title, title: title,
title_link: pixiv_url, title_link: pixiv_url,
image_url: image_url, image_url: image_url,

+ 4
- 5
slack-pixiv/commands/member.rb View File

@ -8,22 +8,21 @@ module SlackMathbot
agent = Mechanize.new agent = Mechanize.new
pixiv_url = "http://www.pixiv.net/member.php" + _match[:url][0..-2] pixiv_url = "http://www.pixiv.net/member.php" + _match[:url][0..-2]
puts pixiv_url.split("?id=")[-1]
# Scrape page title # Scrape page title
title = Mechanize.new.get(pixiv_url).title
title = agent.get(pixiv_url).title
puts title puts title
# Scrape username # Scrape username
username = Mechanize.new.get(pixiv_url).at(".name").text
username = agent.get(pixiv_url).at(".name").text
puts username puts username
# Scrape profile comment # Scrape profile comment
profile_comment = Mechanize.new.get(pixiv_url).at(".profile-comment").text.split("br { display : none;}")[-1]
profile_comment = agent.get(pixiv_url).at(".profile-comment").text.split("br { display : none;}")[-1]
puts profile_comment puts profile_comment
# Scrape works count # Scrape works count
#works = Mechanize.new.get(pixiv_url).at(".count")
works = agent.get(pixiv_url).links_with(:class => /int/) works = agent.get(pixiv_url).links_with(:class => /int/)
puts works puts works

Loading…
Cancel
Save