change folder structure of local saving
This commit is contained in:
parent
fec31cedcc
commit
ebb59753ff
13
local.rb
13
local.rb
|
@ -28,7 +28,6 @@ require 'sanitize'
|
||||||
auth_token = ENV['API_KEY']
|
auth_token = ENV['API_KEY']
|
||||||
instance_url = ENV['INSTANCE_URL']
|
instance_url = ENV['INSTANCE_URL']
|
||||||
bird_api_url = ENV['BIRD_API_URL']
|
bird_api_url = ENV['BIRD_API_URL']
|
||||||
save_locally = ENV['SAVE_LOCALLY']
|
|
||||||
path_to_data = ENV['PATH_TO_DATA']
|
path_to_data = ENV['PATH_TO_DATA']
|
||||||
|
|
||||||
current_time = Time.now
|
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')
|
day = current_time.day.to_s.rjust(2, '0')
|
||||||
time = current_time.strftime("%H%M")
|
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|
|
conn = Faraday.new(url: bird_api_url) do |faraday|
|
||||||
faraday.adapter Faraday.default_adapter
|
faraday.adapter Faraday.default_adapter
|
||||||
end
|
end
|
||||||
|
@ -49,10 +52,6 @@ user, url, thumb, license, desc, license_url, user_url = data.values_at('user',
|
||||||
|
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
filename = File.basename(uri.path)
|
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.open("#{folder_path}/#{filename}.json", 'w') do |file|
|
||||||
file.write(data.to_json)
|
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}"
|
status = "#{desc}\n\n**Attribution and license**: #{user} (#{license})\n**Source**: #{url}"
|
||||||
puts "Status for post: #{status}"
|
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}"
|
image = "#{folder_path}/#{filename}"
|
||||||
|
|
||||||
URI.open(url) do |picture|
|
URI.open(url) do |picture|
|
||||||
|
|
Loading…
Reference in New Issue