diff --git a/local.rb b/local.rb index 3c38f6c..8d11d3a 100644 --- a/local.rb +++ b/local.rb @@ -28,7 +28,6 @@ require 'sanitize' auth_token = ENV['API_KEY'] instance_url = ENV['INSTANCE_URL'] bird_api_url = ENV['BIRD_API_URL'] -save_locally = ENV['SAVE_LOCALLY'] path_to_data = ENV['PATH_TO_DATA'] current_time = Time.now @@ -37,6 +36,10 @@ month = current_time.month.to_s.rjust(2, '0') day = current_time.day.to_s.rjust(2, '0') time = current_time.strftime("%H%M") +folder_path = "#{path_to_data}/#{year}/#{month}/#{day}" +FileUtils.mkpath(folder_path) +puts "Folder created at: #{folder_path}" + conn = Faraday.new(url: bird_api_url) do |faraday| faraday.adapter Faraday.default_adapter end @@ -49,10 +52,6 @@ user, url, thumb, license, desc, license_url, user_url = data.values_at('user', uri = URI.parse(url) filename = File.basename(uri.path) -folder_path = "#{path_to_data}/json/#{year}/#{month}/#{day}/#{time}" - -FileUtils.mkpath(folder_path) -puts "Folder created at: #{folder_path}" File.open("#{folder_path}/#{filename}.json", 'w') do |file| file.write(data.to_json) @@ -63,10 +62,6 @@ desc_sanitised = Sanitize.clean(desc) status = "#{desc}\n\n**Attribution and license**: #{user} (#{license})\n**Source**: #{url}" puts "Status for post: #{status}" -folder_path = "#{path_to_data}/imgs/#{year}/#{month}/#{day}/#{time}" -FileUtils.mkpath(folder_path) -puts "Folder created at: #{folder_path}" - image = "#{folder_path}/#{filename}" URI.open(url) do |picture|