Last active
December 10, 2015 19:29
-
-
Save clicube/4481586 to your computer and use it in GitHub Desktop.
shuron_bot (for mac)
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 | |
require 'mini_exiftool' | |
require 'twitter' | |
require_relative 'simplestore' | |
# https://gist.github.com/4482749 | |
require_relative 'networksetup' | |
# https://gist.github.com/4481049 | |
store = SimpleStore.new(File.dirname(__FILE__)+"/store.yaml") | |
fname = store['filename'] || raise("filename is not set") | |
puts "filename: #{fname}" | |
notifytarget_str = store.has_key?('notifytarget') ? "@#{store['notifytarget']} " : "" | |
def set_twitter(store) | |
Twitter.configure do |t| | |
t.consumer_key = store['ckey'] | |
t.consumer_secret = store['csecret'] | |
t.oauth_token = store['atoken'] | |
t.oauth_token_secret = store['asecret'] | |
if (p = NetworkSetup.secureweb_proxy("Wi-Fi")).enabled? | |
t.proxy = "http://#{p.server}:#{p.port}" | |
end | |
end | |
end | |
lastmtime = nil | |
loop do | |
sleep 5 | |
next unless File.exist?(fname) | |
if (mtime = File.mtime(fname)) != lastmtime | |
if (page = MiniExiftool.new(fname)['PageCount']) && page > 0 | |
puts "modified: page=#{page}" | |
if page != (lastpage = store['lastpage']||0) | |
text = "#{page} (#{sprintf('%+d',page-lastpage)})" | |
set_twitter store | |
begin | |
Twitter.update(text) | |
puts "updated: #{text}" | |
store['lastpage'] = page | |
store['lastnotify'] = Time.now.to_i | |
store['lastupdate'] = Time.now.to_i | |
store.save | |
rescue Exception;end | |
elsif (notifyinterval = store['notifyinterval']||0) > 0 | |
lastupdate = store['lastupdate'] || mtime | |
lastnotify = store['lastnotify'] || mtime | |
if (Time.now - [lastupdate.to_i,lastnotify.to_i].max).to_i > notifyinterval*3600 | |
text = "#{notifytarget_str}もう#{(Time.now-lastupdate).to_i/3600}時間以上ずっとページ数増えてないよ???" | |
set_twitter store | |
begin | |
Twitter.update(text) | |
puts "updated: #{text}" | |
rescue Exception;end | |
store['lastnotify'] = Time.now.to_i | |
store.save | |
end | |
end | |
end | |
lastmtime = mtime | |
end | |
end |
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
filename: /Users/nyan/Dropbox/Documents/univ/修論/master.pdf | |
# notifyinterval: 3 # default: no notify | |
# notifytarget: your_twitter_id | |
ckey: C_KEY | |
csecret: C_SECRET | |
atoken: A_TOKEN | |
asecret: T_TOKEN_SECRET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment