This repository has been archived by the owner on Jul 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
slideshare_user.rb
41 lines (36 loc) · 1.54 KB
/
slideshare_user.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby
require 'net/http'
# Slideshare User Info
#
# This job scrapes two numbers from a slideshare user account:
# `slideshare_user_slides_count`: Number of slideshare presentations shared
# `slideshare_user_followers_count`: Number of followers of the account
# Config
# ------
# user name of the slideshare account
slideshare_username = ENV['SLIDESHARE_USERNAME'] || 'ephigenia1'
SCHEDULER.every '2m', :first_in => 0 do |job|
http = Net::HTTP.new("www.slideshare.net")
response = http.request(Net::HTTP::Get.new("/#{slideshare_username}"))
# check response code
if response.code != "200"
puts "slideshare communication error (status-code: #{response.code})\n#{response.body}"
else
# capture slideshare user followers count using regexp on the source
slideshare_user_followers_count = /(\d+) Follower/.match(response.body)
slideshare_user_followers_count = slideshare_user_followers_count[1].to_i
if defined?(send_event)
send_event('slideshare_user_followers_count', current: slideshare_user_followers_count)
else
print "slideshare followers: #{slideshare_user_followers_count}\n"
end
# capture slideshare slides count using regexp on the source
slideshare_user_slides_count = /(\d+) SlideShares/.match(response.body)
slideshare_user_slides_count = slideshare_user_slides_count[1].to_i
if defined?(send_event)
send_event('slideshare_user_slides_count', current: slideshare_user_slides_count)
else
print "slideshare followers: #{slideshare_user_slides_count}\n"
end
end
end