Last active
March 6, 2019 13:12
-
-
Save donalod/16d4b221489b14297ee51977271c9ddc to your computer and use it in GitHub Desktop.
youtube_to_twitter.rb
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
#!/usr/bin/env ruby | |
require "twitter" | |
require "yt" | |
p "Running iNOG random tweeter script at #{Time.current.to_s}" | |
$tumbler = [] | |
$plucked | |
def yt_get_urls | |
# iNOG-Playlist-Tweeter | |
# IPv4 restricted | |
# IPv6 restricted | |
Yt.configuration.api_key = "<api_key>" | |
Yt.configure do |config| | |
config.log_level = :debug | |
end | |
autotweet_list = Yt::Playlist.new id: 'PLWGYuk4mdX_9sqeR5tqgDhD48Yw7x7x3U' | |
autotweet_list_videos = autotweet_list.playlist_items | |
puts "Choice is from:" | |
autotweet_list_videos.each do |entry| | |
$tumbler.push(entry) | |
puts entry.video_id | |
end | |
plucked = plucker($tumbler) | |
puts plucked.video_id | |
message = compose(plucked) | |
return message | |
end | |
def compose(plucked) | |
id = plucked.video_id | |
if id.blank? | |
message = "Check out iNOG's previous videos at https://youtube.com/inognet?sub_confirmation=1 @inognet #inognet #neteng" | |
else | |
if id == "xtl5-3-Qyps" # RIPE76 Cristian | |
author_handle = "Cristian @cmsirbu" | |
elsif id == "zmFZdOk-3gQ" # Cisco at Dogpatch inog12 (1) | |
author_handle = "@FastrackintoIT" | |
elsif id == "jXfLAc_kXeY" # Cisco at Dogpatch inog12 (2) | |
author_handle = "@jedelman8 @networktocode" | |
elsif id == "cW3bO8XluH0" # Cisco at Dogpatch inog12 (3) | |
author_handle = "@lauralifts" | |
elsif id == "BCf4gIMovx0" # Workday inog10 (1) | |
author_handle = "@ms_multicolor" | |
elsif id == "EFTrxDIBKC4" # Workday inog10 (2) | |
author_handle = "@mierdin + @vtep42" | |
elsif id == "uj-dEjhX7qk" #Arista inogF (2) | |
author_handle = "Fran G. @hostedgraphite" | |
elsif id == "DJnmV8W--r8" #Arista inogF (1) | |
author_handle = "Patrick C." | |
elsif id == "3T0j8AzsGBo" #Arista inogF (3) | |
author_handle = "Sergei S.K. and Vlad. H @endofunctor" | |
elsif id == "9phyEJDKIaQ" #Workday | |
author_handle = "Victor Z. @vazic" | |
elsif id == "EHNRqfUw3C8" #Workday inogD | |
author_handle = "Sergey S.K + Vlad H" | |
elsif id == "p6uUXqSJPRc" #FB | |
author_handle = "@joseleitao + Daniel" | |
elsif id == "VorpkEb08GA" #FB Note: This keeps coming up regularly so temporarily asking it to re-pick | |
#$plucked = plucker($tumbler) | |
#puts "Picking again as got: "+$plucked.video_id | |
#compose(plucked) | |
author_handle = "@csillabessenyei" | |
elsif id == "X7QOiy9HAFk" #FB | |
author_handle = "@colin_whittaker" | |
elsif id == "T71H2B8QMPY" #FB | |
author_handle = "@zergless @TimMurphy123" | |
elsif id == "iVTAudJOUHI" #Workday | |
author_handle = "@argally" | |
elsif id == "fS_q7o98JKI" #Riot | |
author_handle = "@jedelman8 @joseleitao @romagn" | |
elsif id == "GyNxYPaatOY" #Amazon | |
minitumble = rand(0..3) | |
if minitumble == 0 | |
id = "GyNxYPaatOY?t=9m1s" | |
author_handle = "@barrykeegan" | |
elsif minitumble == 1 | |
id = "GyNxYPaatOY?t=15m40s" | |
author_handle = "@natural20" | |
elsif minitumble == 2 | |
id = "GyNxYPaatOY?t=27m45s" | |
author_handle = "@joseleitao @mikjimenez" | |
elsif minitumble == 3 | |
id = "GyNxYPaatOY?t=54m12s" | |
author_handle = "@colin_whittaker" | |
end | |
elsif id == "WSH6jxmqrag" # SIG | |
author_handle = "@orlamcgann @nathabeer @ehorley" | |
elsif id == "38vsEtYNVTk" # Google | |
author_handle = "@barryo79 + Laura + Costi" | |
elsif id == "ugqblh-rlGI" #Arista | |
author_handle = "@Iamjeffvader @taktv6 @pberndro + Thomas + Peter + Aaron" | |
elsif id == "9LAbgSVfmtE" #Zendesk | |
minitumble = rand(0..3) | |
if minitumble == 0 | |
id = "9LAbgSVfmtE?t=9m56s" | |
author_handle = "@networksherpa" | |
elsif minitumble == 1 | |
id = "9LAbgSVfmtE?t=26m25s" | |
author_handle = "@argally" | |
elsif minitumble == 2 | |
id = "9LAbgSVfmtE?t=48m26s" | |
author_handle = "@zendeluca" | |
elsif minitumble == 3 | |
id = "9LAbgSVfmtE?t=1h06m" | |
author_handle = "@donalcunningham" | |
end | |
#author_handle = "@networksherpa @argally @zendeluca @donalcunningham" | |
elsif id == "zQN7Uj-FSxE" #FB | |
minitumble = rand(0..4) | |
if minitumble == 0 | |
id = "zQN7Uj-FSxE?t=8m36s" | |
author_handle = "@joseleitao" | |
elsif minitumble == 1 | |
id = "zQN7Uj-FSxE?t=22m6s" | |
author_handle = "@mellowdrifter" | |
elsif minitumble == 2 | |
id = "zQN7Uj-FSxE?t=36m12s" | |
author_handle = "Pallavi R." | |
elsif minitumble == 3 | |
id = "zQN7Uj-FSxE?t=51m6s" | |
author_handle = "@cmsirbu" | |
elsif minitumble == 4 | |
id = "zQN7Uj-FSxE?t=1h04m30s" | |
author_handle = "@richard_sheehan" | |
end | |
#author_handle = "@joseleitao @mellowdrifter @cmsirbu @richard_sheehan + Pallavi" | |
end | |
author_handle ||= "" | |
message = "Video: "+$plucked.title+" https://youtu.be/"+id+" "+author_handle+" @inognet #inognet #neteng #share RT?" | |
message ||= "Check out iNOG's previous videos at https://youtube.com/inognet?sub_confirmation=1 @inognet #inognet #neteng https://inog.net/talk #share RT?" | |
puts "Chose: "+id+" at"+Time.current.to_s | |
puts message | |
end | |
return message | |
end | |
def plucker(tumbler) # takes an array and returns an entry | |
$plucked = tumbler.sample | |
return $plucked | |
end | |
def twitter_msg | |
twitterclient = Twitter::REST::Client.new do |config| | |
config.consumer_key = "<>" | |
config.consumer_secret = "<>" | |
config.access_token = "<>" | |
config.access_token_secret = "<>" | |
end | |
#sleep(rand(0..300)) | |
choose = rand(0..15) | |
#choose = 8 | |
# We can start using weighting soon.... | |
if [0,1,2,3,4,5].include?(choose) | |
twitterclient.update("#{yt_get_urls}") | |
elsif [6,7,8,9].include?(choose) | |
twitterclient.update("#{["Come share","Something to share","Got a good war story","Share what you know","Know someone who could talk"].sample} @inognet https://inog.net/talk #inognet #neteng RT or pass it on?") | |
elsif [10,11,12].include?(choose) | |
twitterclient.update("Did you know you can now donate π° to @inognet for community swag, stickers, and sunk costs π https://donate.inog.net π RTs welcome π") | |
#elsif [7,8,9,11].include?(choose) | |
# twitterclient.update("#{['Join us at iNOG::11','RT iNOG::11 ','RSVP for iNOG::11 here ->','Remember iNOG::11'].sample} https://inog.net @ YourSpace Tues 6-10pm w/ friends #neteng #edutainment #inognet") | |
#twitterclient.update("SEEKING SPONSORSHIP π» for Network Operator Tools Hackathon π§ @RIPE_NCC + you? https://inog.net/pr#seeking-sponsorship Dublin, IE 23-24 June β Grow your networks π Shares/RTs welcome! π https://twitter.com/inognet/status/984797568608669696/photo/1") | |
else | |
#twitterclient.update("π» π§β π π ") | |
twitterclient.update("#{["Could you host","Is your organisation a good fit for","Ever wondered how to host ","Know someone or an org who could host","Curious about what goes in to organising"].sample} @inognet ? https://inog.net/host #inognet #neteng RT?") | |
end | |
rescue Twitter::Error => e | |
puts "Tweets Controller : Twitter : #{ e.message }" | |
end | |
twitter_msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment