Skip to content

Instantly share code, notes, and snippets.

@relyks
Created August 3, 2017 04:11
Show Gist options
  • Save relyks/71fcda52d2434f945c23715f0d212378 to your computer and use it in GitHub Desktop.
Save relyks/71fcda52d2434f945c23715f0d212378 to your computer and use it in GitHub Desktop.
require 'twitter'
require 'google_maps_service'
require 'open-uri'
require 'twilio'
require 'scanf'
require 'pp'
account_sid = 'ACd7b75f36a9974788063bd92e4c4c6273'
auth_token = '1f976d928060ae1a8ba29a1b8656e4f1'
twilio_client = Twilio::REST::Client.new(account_sid, auth_token)
gmaps_client = GoogleMapsService::Client.new(key: 'AIzaSyB2bCNX2m55W4IcIJ4regy5zFVUuS-F_es')
twitter_client = Twitter::REST::Client.new do |config|
config.consumer_key = 'bqWneAF7YdIWvr7JAAVHtn5B6'
config.consumer_secret = 'cRMVBw4l1aPUJDRnhlv1HeX5eXN7s8kH3fmC6IhiztfEeBSIy3'
config.access_token = '12449062-fyi74JdRnsnqjadXtvxnETUcsfSTjPlnAH4QV7xMm'
config.access_token_secret = 'liq4BsiGtpONuIVqLFO8fPxgxHYfEtwqLZwbIR68BJ89A'
end
def internet_connection?
begin
true if open("http://www.google.com/")
rescue
false
end
end
previously_seen_tweets = Array.new
has_made_notification = false
begin
loop do
tweets = twitter_client.search("from:UnownBot New York", result_type: 'recent')
.take(10)
.to_a
tweets.each do |tweet|
unless previously_seen_tweets.include?(tweet.id)
pp tweet.text
previously_seen_tweets.push(tweet)
time_parts = tweet.text[/\d+m \d+s/].scanf("%d%s %d%s")
despawn_minutes = time_parts[0]
despawn_seconds = time_parts[2]
sufficient_time_to_get_unown = tweet.created_at + despawn_seconds + (despawn_minutes * 60) > Time.now + (20 * 60)
if sufficient_time_to_get_unown and not has_made_notification
destinations = [tweet.text[/-?\d+.\d+,-?\d+.\d+/]]
origins = case Time.new.strftime("%H:%M")
when '10:00'..'18:35'
['135 E 57th St., New York, NY 10022']
when '18:36'.."23:59"
['333 E 56th St., New York, NY 10022']
end
matrix = gmaps_client.distance_matrix(origins, destinations, mode: 'bicycling', units: 'imperial')
travel_time_in_minutes = matrix[:rows].first[:elements].first[:duration][:value] / 60.0
if travel_time_in_minutes < 16.0
`notify-send -u critical "Unown Alert" "GO GET HIM"`
twilio_client.calls.create(
:from => '+12018627794',
:to => '+12012144708',
:url => 'https://skyler.neocities.org/say_message.xml')
has_made_notification = true
end
end
end
end
sleep 60
end
rescue Twitter::Error
sleep 180
retry
rescue
tries = 1
loop do
sleep 60 * tries
if internet_connection?
break
else
tries += 1
end
end
retry
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment