我正在使用不会访问互联网的导轨为非营利组织开发学习应用程序。所有资产必须在当地安置。该应用程序包含数千个图像,实际上只是URL。我对开发世界很新,但发现很难找到解决这个问题的方法。
大多数数据库内容都使用自定义rake和cron任务进行播种。我们正在使用Dribbble API来提取大部分内容,包括图片。看看网址,看起来Dribbble正在使用S3来存放他们的图片。也许这是解决方案的一部分。 (例如网址:https://d13yacurqjgara.cloudfront.net/users/4521/screenshots/2742352/nest_notifications.jpg)。
我知道这个话题对于那些人来说一定很容易,但我确实没有经验或成功找到解决方案。非常感谢帮助和建议!
根据请求,这是rake任务的副本:
namespace :dribbble do
desc "TODO"
task get_recent: :environment do
url="https://api.dribbble.com/v1/shots/?access_token=XXX"
response = HTTParty.get(url)
recent_shots = JSON.parse(response.body)
recent_shots.each do |s|
users_dribbbleid = s['user']['id']
shots_dribbbleid = s['user']['id']
existing_user = User.where(designer_id: users_dribbbleid)
#IS THERE AN EXISTING USER IN THE DATABASE? IF NO, THEN...
if existing_user.empty?
newuser = User.create(
designer_id: s['user']['id'],
designer_full_name: s['user']['name'],
designer_username: s['user']['username'],
designer_home_url: s['user']['html_url'],
designer_avatar_url: s['user']['avatar_url'],
designer_bio: s['user']['bio'],
designer_location: s['user']['location'],
designer_bk_count: s['user']['buckets_count'],
designer_comments_received_count: s['user']['comments_received_count'],
designer_follower_count: s['user']['followers_count'],
designer_is_following_count: s['user']['followings_count'],
designer_made_likes_count: s['user']['likes_count'],
designer_received_likes_count: s['user']['likes_received_count'],
designer_project_count: s['user']['projects_count'],
designer_rebounds_received_count: s['user']['rebounds_received_count'],
designer_added_shots_count: s['user']['shots_count'],
designer_list_of_followers_url: s['user']['followers_url'],
designer_following_list_url: s['user']['following_url'],
designer_list_of_shots_url: s['shots_url']
)
newshot = Shot.create(
dribbble_id: s["id"],
title: s["title"],
description: s["description"],
width: s["width"],
height: s["height"],
images_hidpi: s["images"]["hidpi"],
images_normal: s["images"]["normal"],
images_teaser: s["images"]["teaser"],
viewcount: s["views_count"],
likes_count: s['likes_count'],
comments_count: s['comments_count'],
attachments_count: s['attachments_count'],
rebounds_count: s['rebounds_count'],
buckets_count: s['buckets_count'],
html_url: s['html_url'],
attachments_url: s["attatchments_url"],
buckets_url: s['buckets_url'],
comments_url: s['comments_url'],
likes_url: s['likes_url'],
projects_url: s['projects_url'],
animated: s['animated'],
tags: s['tags'],
user_id: newuser.id
)
commentresponse = HTTParty.get(s['comments_url']+"?access_token=XXX")
comments = JSON.parse(commentresponse.body)
comments.each do |c|
comments_dribbbleid = c["id"]
existing_comment = Comment.where(comment_id: comments_dribbbleid)
if existing_comment.empty?
newcomment = Comment.create(
comment_id: c["id"].to_s,
comment_created_at: c["created_at"],
body: c["body"],
user_avatar_url: c["user"]["avatar_url"],
user_id: c["user"]["id"],
user_name: c['user']['name'],
shot_id: newshot.id
)
end
end
#IF THERE IS AN EXISTING USER ALREADY, THEN CHECK IF THERE IS AN EXISTING SHOT. IF THERE IS NOT AN EXISTING SHOT, THEN...
else
existing_user = User.where(designer_id: users_dribbbleid)
existing_shot = Shot.where(user_id: existing_user[0].id)
if existing_shot.empty?
newshot = Shot.create(
dribbble_id: s["id"],
title: s["title"],
description: s["description"],
width: s["width"],
height: s["height"],
images_hidpi: s["images"]["hidpi"],
images_normal: s["images"]["normal"],
images_teaser: s["images"]["teaser"],
viewcount: s["views_count"],
likes_count: s['likes_count'],
comments_count: s['comments_count'],
attachments_count: s['attachments_count'],
rebounds_count: s['rebounds_count'],
buckets_count: s['buckets_count'],
html_url: s['html_url'],
attachments_url: s["attatchments_url"],
buckets_url: s['buckets_url'],
comments_url: s['comments_url'],
likes_url: s['likes_url'],
projects_url: s['projects_url'],
animated: s['animated'],
tags: s['tags'],
user_id: existing_user[0].id
)
commentresponse = HTTParty.get(s['comments_url']+"?access_token=XXX")
comments = JSON.parse(commentresponse.body)
comments.each do |c|
comments_dribbbleid = c["id"]
existing_comment = Comment.where(comment_id: comments_dribbbleid)
if existing_comment.empty?
newcomment = Comment.create(
comment_id: c["id"].to_s,
comment_created_at: c["created_at"],
body: c["body"],
user_avatar_url: c["user"]["avatar_url"],
user_id: c["user"]["id"],
user_name: c['user']['name'],
shot_id: newshot.id
)
end
end
end
end
end
端 端
`