cinch-url-scraper 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +38 -0
  2. data/lib/cinch/plugins/urlscraper.rb +21 -8
  3. metadata +2 -2
data/README.md CHANGED
@@ -1,3 +1,41 @@
1
1
  # Cinch Url Scraper plugin
2
2
 
3
3
  A Cinch plugin to get information about posted URLs.
4
+
5
+ ## Installation
6
+
7
+ First install the gem by running:
8
+
9
+ ```bash
10
+ gem install cinch-url-scrapper
11
+ ```
12
+
13
+ Then load it in your bot:
14
+
15
+ ```ruby
16
+ require "cinch"
17
+ require "cinch/plugins/urlscraper"
18
+
19
+ bot = Cinch::Bot.new do
20
+ configure do |c|
21
+ c.plugins.plugins = [Cinch::Plugins::UmlScraper]
22
+ end
23
+ end
24
+
25
+ bot.start
26
+ ```
27
+
28
+ ## Commands
29
+
30
+ ```irc
31
+ <url> # display url title / information
32
+ ```
33
+
34
+ ## Example
35
+
36
+ <mpapis>: git@gist.github.com:3505088.git:
37
+ <smfbot>: Title: rvm setup for projects — Gist (at gist.github.com, mpapis on 2012-08-28 15:56), Url: https://gist.github.com/3505088
38
+
39
+ ## Development
40
+
41
+ Run the `./test-run.sh` script to play with results of your changes in channel listed in `example/config.yaml`
@@ -8,7 +8,6 @@ module Cinch
8
8
  module Plugins
9
9
  class UrlScraper
10
10
  include Cinch::Plugin
11
- set :react_on, :channel
12
11
 
13
12
  listen_to :channel
14
13
  def listen(m)
@@ -19,9 +18,15 @@ module Cinch
19
18
  @agent.max_history = 0
20
19
  end
21
20
 
22
- URI.extract(m.message, ["http", "https"]) do |link|
21
+ URI.extract(m.message.gsub(/git@(gist.github.com):/,'git://\1/'), ["http", "https", "git"]).map do |link|
22
+ link=~/^(.*?)[:;,\)]?$/
23
+ $1
24
+ end.each do |link|
23
25
  # Fetch data
24
26
  begin
27
+ if git = link =~ /^git:\/\/(gist.github.com\/.*)\.git$/
28
+ link = "https://#{$1}"
29
+ end
25
30
  uri = URI.parse(link)
26
31
  page = @agent.get(link)
27
32
  rescue Mechanize::ResponseCodeError
@@ -69,12 +74,20 @@ module Cinch
69
74
  owner = page.search("//div[@class='name']/a").inner_html
70
75
 
71
76
  # Get time
72
- age = Time.parse(page.search("//span[@class='date']/abbr").text)
73
- age = age.strftime("%Y-%m-%d %H:%M")
74
-
75
- m.reply "Title: %s (at %s, %s on %s)" % [
76
- title, uri.host, owner, age
77
- ]
77
+ age = page.search("//span[@class='date']/time")
78
+ age = age.first[:datetime] rescue age.text if age
79
+ age = Time.parse(age) rescue nil
80
+ age = age.strftime("%Y-%m-%d %H:%M") if age
81
+
82
+ if git
83
+ m.reply "Title: %s (at %s, %s on %s), Url: %s" % [
84
+ title, uri.host, owner, age, link
85
+ ]
86
+ else
87
+ m.reply "Title: %s (at %s, %s on %s)" % [
88
+ title, uri.host, owner, age
89
+ ]
90
+ end
78
91
  when "pastie.org"
79
92
  # Get time
80
93
  age = Time.parse(page.search("//span[@class='typo_date']").text)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-url-scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
12
+ date: 2012-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cinch