From ebb59753ff30853e3137afa7a5046bf44ad96c23 Mon Sep 17 00:00:00 2001 From: Hexaitos Date: Thu, 14 Nov 2024 07:47:33 +0100 Subject: [PATCH] change folder structure of local saving --- local.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) 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|