Last active
June 2, 2017 14:52
-
-
Save maximveksler/72c02368dc6c17d6bd604139ab4181b5 to your computer and use it in GitHub Desktop.
TapeACall recordings download script
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
require 'csv' | |
require 'date' | |
require 'net/http' | |
all = CSV.read("TapeACall Recordings.csv")[1 .. -1] | |
all.each do |x| | |
csv_date = x[0] | |
csv_label = x[1] | |
csv_duration = x[2] | |
csv_link = x[3] | |
download_date = DateTime.strptime(csv_date, '%b %d %Y %I:%M:%S %p').strftime("%Y-%m-%d %H%M%S") | |
recording_id = csv_link.sub('http://tapeacall.com/', '') | |
download_resource = "download-recording?tag=" + recording_id | |
download_url = "http://www.tapeacall.com/" + download_resource | |
puts csv_link | |
begin | |
uri = URI.parse(download_url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Get.new(uri.request_uri) | |
res = http.request(request) | |
if res.code == "200" | |
puts download_url | |
local_path = "'TapeACall_TODO/#{download_date} - TapeACall - TODO - #{csv_label}'" | |
puts "FOUND Saving to #{local_path}" | |
`mkdir -p #{local_path}` | |
`wget --content-disposition -P #{local_path} '#{download_url}'` | |
end | |
rescue SocketError => e | |
puts "Exception: #{e}" | |
# do the next thing | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment