diff options
| -rw-r--r-- | app/assets/stylesheets/main/layout.scss | 11 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 10 | ||||
| -rw-r--r-- | app/models/scrobble.rb | 2 | ||||
| -rw-r--r-- | app/views/admin/streams/edit.html.haml | 2 | ||||
| -rw-r--r-- | app/views/admin/streams/index.html.haml | 4 | ||||
| -rw-r--r-- | app/views/blogs/_blog.html.haml | 2 | ||||
| -rw-r--r-- | app/views/layouts/application.html.haml | 10 | ||||
| -rw-r--r-- | app/views/layouts/quotes.html.haml | 4 | ||||
| -rw-r--r-- | config/credentials.yml.enc | 2 | ||||
| -rw-r--r-- | config/credentials/production.yml.enc | 2 | ||||
| -rw-r--r-- | config/mail.yml | 8 | ||||
| -rw-r--r-- | config/schedule.rb | 4 | ||||
| -rw-r--r-- | db/migrate/20251122012500_create_scrobbles.rb | 12 | ||||
| -rw-r--r-- | db/schema.rb | 11 | ||||
| -rw-r--r-- | lib/tasks/tasks.rake | 21 | ||||
| -rw-r--r-- | public/robots.txt | 6 | ||||
| -rw-r--r-- | test/fixtures/scrobbles.yml | 13 | ||||
| -rw-r--r-- | test/models/scrobble_test.rb | 7 |
18 files changed, 118 insertions, 13 deletions
| diff --git a/app/assets/stylesheets/main/layout.scss b/app/assets/stylesheets/main/layout.scss index ef31ada..d5fe7a7 100644 --- a/app/assets/stylesheets/main/layout.scss +++ b/app/assets/stylesheets/main/layout.scss | |||
| @@ -228,3 +228,14 @@ h2.centered { | |||
| 228 | text-decoration: none; | 228 | text-decoration: none; |
| 229 | } | 229 | } |
| 230 | } | 230 | } |
| 231 | |||
| 232 | #scrobble-box { | ||
| 233 | img { | ||
| 234 | margin: 0 auto; | ||
| 235 | display: block; | ||
| 236 | } | ||
| 237 | |||
| 238 | p { | ||
| 239 | text-align: center; | ||
| 240 | } | ||
| 241 | } | ||
| diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0174cae..ad46fb9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb | |||
| @@ -1,9 +1,19 @@ | |||
| 1 | class ApplicationController < ActionController::Base | 1 | class ApplicationController < ActionController::Base |
| 2 | protect_from_forgery with: :exception | 2 | protect_from_forgery with: :exception |
| 3 | before_action :choose_random_song | ||
| 3 | 4 | ||
| 4 | private | 5 | private |
| 5 | 6 | ||
| 6 | def after_sign_out_path_for(resource) | 7 | def after_sign_out_path_for(resource) |
| 7 | new_session_path(resource) | 8 | new_session_path(resource) |
| 8 | end | 9 | end |
| 10 | |||
| 11 | def choose_random_song | ||
| 12 | ids = Scrobble.ids | ||
| 13 | if ids.empty? | ||
| 14 | @random_song = nil | ||
| 15 | else | ||
| 16 | @random_song = Scrobble.find(ids.sample) | ||
| 17 | end | ||
| 18 | end | ||
| 9 | end | 19 | end |
| diff --git a/app/models/scrobble.rb b/app/models/scrobble.rb new file mode 100644 index 0000000..f527612 --- /dev/null +++ b/app/models/scrobble.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | class Scrobble < ApplicationRecord | ||
| 2 | end | ||
| diff --git a/app/views/admin/streams/edit.html.haml b/app/views/admin/streams/edit.html.haml index 8d910fe..8c250e2 100644 --- a/app/views/admin/streams/edit.html.haml +++ b/app/views/admin/streams/edit.html.haml | |||
| @@ -1,3 +1,3 @@ | |||
| 1 | - title "Editing #{@stream.title}" | 1 | - title "Editing #{@stream.title}" |
| 2 | = form_for @stream, url: admin_stream_url(@stream), html: { id: "entry-form" } do |f| | 2 | = form_for @stream, url: admin_stream_url(@stream.id), html: { id: "entry-form" } do |f| |
| 3 | = render partial: "form", locals: { f: f } | 3 | = render partial: "form", locals: { f: f } |
| diff --git a/app/views/admin/streams/index.html.haml b/app/views/admin/streams/index.html.haml index 6903fd1..a2a25d7 100644 --- a/app/views/admin/streams/index.html.haml +++ b/app/views/admin/streams/index.html.haml | |||
| @@ -10,5 +10,5 @@ | |||
| 10 | %td= stream.created_at.strftime("%B %d, %Y, %l:%M%P") | 10 | %td= stream.created_at.strftime("%B %d, %Y, %l:%M%P") |
| 11 | %td | 11 | %td |
| 12 | %ul.admin-actions | 12 | %ul.admin-actions |
| 13 | %li= link_to "Edit", edit_admin_stream_url(stream) | 13 | %li= link_to "Edit", edit_admin_stream_url(stream.id) |
| 14 | %li= link_to "Add Update", new_admin_stream_update_url(stream) | 14 | %li= link_to "Add Update", new_admin_stream_update_url(stream.id) |
| diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index 878b1a2..34b343f 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml | |||
| @@ -24,5 +24,5 @@ | |||
| 24 | %time.dt-published{ datetime: blog.visible_date.strftime("%Y-%m-%dT%H:%M:%SZ%z") }= blog.visible_date.strftime("%B #{blog.visible_date.day.ordinalize}, %Y at %-I:%M:%S%P") | 24 | %time.dt-published{ datetime: blog.visible_date.strftime("%Y-%m-%dT%H:%M:%SZ%z") }= blog.visible_date.strftime("%B #{blog.visible_date.day.ordinalize}, %Y at %-I:%M:%S%P") |
| 25 | .post-vote{ id: "blog-vote-section-#{blog.id}" } | 25 | .post-vote{ id: "blog-vote-section-#{blog.id}" } |
| 26 | %span.vote-link{ id: "blog-upvote-link-#{blog.id}" }= link_to_unless (not blog.published or blog.already_upvoted?(request.remote_ip)), "👍", upvote_blog_path(blog), remote: true, rel: "nofollow", class: "blog-upvote-link", method: :post | 26 | %span.vote-link{ id: "blog-upvote-link-#{blog.id}" }= link_to_unless (not blog.published or blog.already_upvoted?(request.remote_ip)), "👍", upvote_blog_path(blog), remote: true, rel: "nofollow", class: "blog-upvote-link", method: :post |
| 27 | %span.post-rating{ id: "blog-rating-#{blog.id}" }= blog.upvotes - blog.downvotes | 27 | %span.post-rating{ id: "blog-rating-#{blog.id}" }= blog.upvotes |
| 28 | %span.vote-link{ id: "blog-downvote-link-#{blog.id}" }= link_to_unless (not blog.published or blog.already_downvoted?(request.remote_ip)), "👎", downvote_blog_path(blog), remote: true, rel: "nofollow", class: "blog-downvote-link", method: :post | 28 | %span.vote-link{ id: "blog-downvote-link-#{blog.id}" }= link_to_unless (not blog.published or blog.already_downvoted?(request.remote_ip)), "👎", downvote_blog_path(blog), remote: true, rel: "nofollow", class: "blog-downvote-link", method: :post |
| diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1d0bea3..6bc7041 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml | |||
| @@ -73,6 +73,16 @@ | |||
| 73 | %li | 73 | %li |
| 74 | = image_tag "feed.png" | 74 | = image_tag "feed.png" |
| 75 | = link_to "Atom feed", blogs_url(format: :atom) | 75 | = link_to "Atom feed", blogs_url(format: :atom) |
| 76 | - unless @random_song.nil? | ||
| 77 | .sidebar-module#scrobble-box | ||
| 78 | .bubble.rounded | ||
| 79 | %h2 Listening to | ||
| 80 | = image_tag @random_song.image, width: "174px" | ||
| 81 | %p | ||
| 82 | %strong= @random_song.title | ||
| 83 | by | ||
| 84 | = @random_song.artist | ||
| 85 | %p= @random_song.album | ||
| 76 | .sidebar-module | 86 | .sidebar-module |
| 77 | .bubble.rounded | 87 | .bubble.rounded |
| 78 | %h2 Meta | 88 | %h2 Meta |
| diff --git a/app/views/layouts/quotes.html.haml b/app/views/layouts/quotes.html.haml index 4b21000..040fdfe 100644 --- a/app/views/layouts/quotes.html.haml +++ b/app/views/layouts/quotes.html.haml | |||
| @@ -21,12 +21,12 @@ | |||
| 21 | %li= link_to_unless_current "Home", quotes_url | 21 | %li= link_to_unless_current "Home", quotes_url |
| 22 | %li= link_to_unless_current "Latest", latest_quotes_url | 22 | %li= link_to_unless_current "Latest", latest_quotes_url |
| 23 | %li= link_to_unless_current "Top", top_quotes_url | 23 | %li= link_to_unless_current "Top", top_quotes_url |
| 24 | %li= link_to "Random", random_quotes_url | 24 | %li{"data-turbolinks" => "false"}= link_to "Random", random_quotes_url |
| 25 | - if user_signed_in? | 25 | - if user_signed_in? |
| 26 | %li= link_to_unless_current "Submit", new_quote_url | 26 | %li= link_to_unless_current "Submit", new_quote_url |
| 27 | %li= link_to_unless_current "Tags", tags_quotes_url | 27 | %li= link_to_unless_current "Tags", tags_quotes_url |
| 28 | %li= link_to_unless_current "Search", search_form_quotes_url | 28 | %li= link_to_unless_current "Search", search_form_quotes_url |
| 29 | %li= link_to_unless_current "Stats", stats_quotes_url | 29 | %li{"data-turbolinks" => "false"}= link_to_unless_current "Stats", stats_quotes_url |
| 30 | %li= link_to_unless_current "Feed", latest_quotes_url(:atom) | 30 | %li= link_to_unless_current "Feed", latest_quotes_url(:atom) |
| 31 | - if user_signed_in? | 31 | - if user_signed_in? |
| 32 | %li= link_to_unless_current "Admin", admin_url | 32 | %li= link_to_unless_current "Admin", admin_url |
| diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index cd9cac5..e08912f 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc | |||
| @@ -1 +1 @@ | |||
| TMbFARKxiuopoIWE/n0a8KMCh28dFjTGFpfXoXHUQmDlVhA40doz/aLWCYDE00djC70eM4BwXZmaDFC7tly1miU0OymvYijYKNb5Kv9bu2rihSprleyjnBrCF4qykWpDh8XfzXGfiDegSuZzw5RUGKkEU+EGJNIPTnPKAm2MSSnPStVFt1gGxGuYRd0pXCgFUW/USVYnbJEPv6DOxqh3HmKmneP29fcx1V+N/RccyzHsjL2S5lej5s8Q4oAy+SZ4+xLK9Pdh6nA3dZ82fNTLffqmnFxEovuW5n6Cjt0Ka2MZRvYg6sBNDvUVvQSw4u1BRXx7JOHcIWiKdykF/uHdrSwmIPepwd+zs/HCxrthdMSry+yrLwJpZ67JiMA/VKIMYzgLy8yk2JEblBXq3FGo44TWwumIkfTn4H/6UZNb4jGJ4dH+LAFiE7il2X3BbvBb4EkYB3xbu+zqvnohOzuVKkJtjILV6RBrEFzbCijwi3PBOoX8O9fwW8B0BduSp4AhFa+dyenOkD2HjtyEMttJAPuuw3neQKhkv/4SaPaugcD4vKONSwU3F/7nB7yMVQqofVLIc2a1tJaTjWIlNIwVssZS2HS5OZFTpv1XJpCyMcLO/EAe9poqiPieE8WwpdXntRs9O/QQqPWyt2ZdHD8RMKerZjbU1wV58h4rJmmAKUkTCuo=--Jo9AwrM/hr9nWWoS--iHpkNsZwBWB0lySmzkcLdA== \ No newline at end of file | MTHDW1ZOa9otC2lb9iG3bKlhzM8WgEoJddmcsv22b7TEv+ZxlnjBvql1MGJjfo+tNl9dT4gqUOH41Q2WfRhwIokibD6cLMKl8z3VPLHdARR3HW4OzEJoLYXYB5ycLtSFmL3jq/TkMBkctRvPo7jeGGBwtEHvh1tBx6cGr/fEvzWMKYMUPiugaMN3OPExZ5VaD1sCHTMm7erwP06+8KTABwGfF6quthHctj/39RusmAWaObVsUwm70nqij+/qekJEZS3xYEuCDZlKqQvwC7Z+qJlmO8vj8CYNFq80bD9MiuEL0kiTVp22ZyMj2TY6YXy2jabkVx5c7FVytx/+kbaNdGtLYqvvuqDXodcai18OWUhR3r+tzPqcinggWmzZeJ0O54dE7Srpe3wGFH3xmgXHRa1jczmCDwlGRTqmjX7E6CBiP7u5NAKLeALvADWGocJwUi0r8r6E3/a8rpsaL97JCjL1GNCDlRSAapqHafzszDWN31yG5mLc9OUoE2RJjU7bgohrhoAPyHpetRxO7fBpZ0quNAh1awiTXVTcNUlDT+UPkQi1mvQo47G3CM9OG8hlgKtfkMMKsl9D92k/g7zIyJzLsPKqYnxHj+qcnU0939xJ0x4MnUPam1oq7OF2FtBgU/OCDxMuM//qSI2Q4+RRKRHs/NLdADxRgO3WJZ+oe2r9YBfTYTlbdOEKmCxSrQMzpB/1jq0jSTRYynn/GO0Z1Pjx0wVzH8vjVosXfh6/PaKslMdHbOM=--A5y7uJSVaL0539+f--FP9Oigql2/EdcYszZ6hj/A== \ No newline at end of file | ||
| diff --git a/config/credentials/production.yml.enc b/config/credentials/production.yml.enc index af415a7..6359cc9 100644 --- a/config/credentials/production.yml.enc +++ b/config/credentials/production.yml.enc | |||
| @@ -1 +1 @@ | |||
| V//BL1LV+HIfxWVXgfAHG5TrUakYlbjN5V3gkDi9StysvSQ0rM3Opo2/Vt0KbU4FHhjiHoGAOZRPdf08j5k3zS3i4YroBfR3HwOj7snvq2mdBleL9D1UqkBLldjdaco1MnSLSfS2yJe8F3VhtVxesz/Sh4LXoZWemsWGJLu0GfRxPDwswTvdWBgyASnKUOlFyQNypgRTWGMqCe99Z5pw8co8JqZho29Dk6Tp7UJzoim8j5YU+tfgBZ4GF81c0eT8SvBJhHHbcTm/DPUMGxvUJAT9adjQnjPq0tferHziTGl54/ROQCXqrJHKLUOH5JRqh2lAkY3EK3SvTezuYSoV0MwsOxntxC54bQYznN5Dz6/I31UbWpydPGY8P+/Sjdh4QInD51VcDeuJ/QaDSeqJFxHUWDJ0Da55rwsZFr6jmpgbqcmunXLl2B+VDH7sSQOn71IEyNikq5l/9m2dYEdXZpWFsujkyVXzg4O5WFkLtmqoe4wudN7kk8nEZffd6xPtKNpl51Ml1BpSoNMNwGAf72Xxq5/5Z9QFK7mtyPhBVYqalR0kEZPbxmeZGmedcE/fgQXlZYNw4tzBy2/24hJokMLRoX5prmOGMf+6f62wEbBozyaDU2eAMC0HCwg/rb22hDPvzs1XKu2TTEGK7iT3BvdsUHIVnHdUd//hLEeNHeI43FLxPKgyaG7Ovnn8DmNrvUuapaFHjykVsQ2GOLQ9a7GGrwObqr0w33HG/UAwhzEE8s9KwF6qMdqPCCPuYOsbj5xgTyv5X5s0oIgCinvkfAIyFV7WXwLbbE9yxc6UumXbLLTSQE2s8mZ2yL+gdE+iYkSOhz8Z3bj9agOQD5zHMu/NxzTdpNwH6rsLLXq5EfToIWNXEl9kTU8=--x7Ic40D296IOMLm6--VBDaN0LLlyO8zeyfWW+UBA== \ No newline at end of file | uzTsEcFmu5QyOod1jjNQT8pqdQ9Tq8+OuH5qOulURR+Ew3+DBAN9/kYZ0b5OBcxnNGlN3suMC6fpgev4fYoaucCufXgNVAhhl1Lch9SJ2jo/1jCIS1U6mTPmwbF1aWM/P7jJhw8535RdlzohVStrIO0Rn3ygshVFFPODSccqyIhDbiiK5j0bvErzt5fDN091SIB0pdtxzy/XBwwfcQ6EaTg170Pv1mmIyCSWD1AGyzGlRhFVYhyv3sEabsC1dfYXjyZYrpbhvfZbi46TzeNA4kPLIVfVNiW0QoJtT90UqpOLcnQKwf23WIxPemzsT9iQj0/pEci+umHG6MkH2zE1eBOlj2VdopBqVEwQEgDvqt6zQMKAbLPU1E3VM94gCxeTidwIMoFGhSXl6nlGwI9ozBXvKyFNgMiz9UKtjEXcQOG3cIBxxMEQ+sjGEu3vAMvD7OymSGSC81JCbcdOqHWH/iIh2K3IcGyibJ4ScVsUBMn7lnsMEPrQQEJ/Df0X2mplJc0i8n19H1S7SrLKSaO7FDENPC0d1dN5nnOt5nDGU2/qkiGJ+LepX/Gb3cxc0fpcnC359rB5WCTKsxBOzjqW5IapCRSa0ztZz+xeXUBN4sDRUzPun2yCqaCxe+ptzTxzT+Ej9oMKSJJncc/zUuwRmd6KbnyQ3/ISeNNIC0BLWaohaj3lP/tRkLkcBNqu/MA4pxUxs1Lwu/8gW9d4GrrxCxOSsQnDk5VzF80LCk4oq+BVrjPYY0vWzVxtj+56slIoUIBIUWRjFTbBuyr3gejPjis5NwiFMyi8emH+a9aa3Ge44YnrDSAA+JVzqHSAF8erIuiqgaTAFwprSmED8pIIV2A0/WWrPcuI5xaAv4e2bQWfzM3SujvY--rs7RvQb911E+dh50--fCsEmvYD6LcaB6ReBcHGrA== \ No newline at end of file | ||
| diff --git a/config/mail.yml b/config/mail.yml index e2d15c3..6c0435d 100644 --- a/config/mail.yml +++ b/config/mail.yml | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | production: | 1 | production: |
| 2 | smtp_settings: | 2 | smtp_settings: |
| 3 | address: "smtp.sendgrid.com" | 3 | address: "mail.smtp2go.com" |
| 4 | port: 587 | 4 | port: 2525 |
| 5 | user_name: "apikey" | 5 | user_name: "fourisland.com" |
| 6 | password: <%= Rails.application.credentials.sendgrid_api_key %> | 6 | password: <%= Rails.application.credentials.smtp2go_password %> |
| 7 | authentication: "plain" | 7 | authentication: "plain" |
| 8 | openssl_verify_mode: "none" | 8 | openssl_verify_mode: "none" |
| diff --git a/config/schedule.rb b/config/schedule.rb index e53ebf4..268dfcb 100644 --- a/config/schedule.rb +++ b/config/schedule.rb | |||
| @@ -21,3 +21,7 @@ | |||
| 21 | every 1.day, at: "6:00am" do | 21 | every 1.day, at: "6:00am" do |
| 22 | rake "thoughts:email_upvote_report" | 22 | rake "thoughts:email_upvote_report" |
| 23 | end | 23 | end |
| 24 | |||
| 25 | every 6.hours do | ||
| 26 | rake "thoughts:refresh_scrobbles" | ||
| 27 | end | ||
| diff --git a/db/migrate/20251122012500_create_scrobbles.rb b/db/migrate/20251122012500_create_scrobbles.rb new file mode 100644 index 0000000..9f00435 --- /dev/null +++ b/db/migrate/20251122012500_create_scrobbles.rb | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | class CreateScrobbles < ActiveRecord::Migration[7.1] | ||
| 2 | def change | ||
| 3 | create_table :scrobbles do |t| | ||
| 4 | t.string :title | ||
| 5 | t.string :artist | ||
| 6 | t.string :album | ||
| 7 | t.string :image | ||
| 8 | |||
| 9 | t.timestamps | ||
| 10 | end | ||
| 11 | end | ||
| 12 | end | ||
| diff --git a/db/schema.rb b/db/schema.rb index 76e9ad8..74e1976 100644 --- a/db/schema.rb +++ b/db/schema.rb | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | # | 10 | # |
| 11 | # It's strongly recommended that you check this file into your version control system. | 11 | # It's strongly recommended that you check this file into your version control system. |
| 12 | 12 | ||
| 13 | ActiveRecord::Schema[7.1].define(version: 2025_05_12_181245) do | 13 | ActiveRecord::Schema[7.1].define(version: 2025_11_22_012500) do |
| 14 | create_table "active_storage_attachments", force: :cascade do |t| | 14 | create_table "active_storage_attachments", force: :cascade do |t| |
| 15 | t.string "name", null: false | 15 | t.string "name", null: false |
| 16 | t.string "record_type", null: false | 16 | t.string "record_type", null: false |
| @@ -352,6 +352,15 @@ ActiveRecord::Schema[7.1].define(version: 2025_05_12_181245) do | |||
| 352 | t.index ["recordable_type", "recordable_id"], name: "index_records_on_recordable_type_and_recordable_id" | 352 | t.index ["recordable_type", "recordable_id"], name: "index_records_on_recordable_type_and_recordable_id" |
| 353 | end | 353 | end |
| 354 | 354 | ||
| 355 | create_table "scrobbles", force: :cascade do |t| | ||
| 356 | t.string "title" | ||
| 357 | t.string "artist" | ||
| 358 | t.string "album" | ||
| 359 | t.string "image" | ||
| 360 | t.datetime "created_at", null: false | ||
| 361 | t.datetime "updated_at", null: false | ||
| 362 | end | ||
| 363 | |||
| 355 | create_table "streams", force: :cascade do |t| | 364 | create_table "streams", force: :cascade do |t| |
| 356 | t.string "title" | 365 | t.string "title" |
| 357 | t.text "body" | 366 | t.text "body" |
| diff --git a/lib/tasks/tasks.rake b/lib/tasks/tasks.rake index fee22f4..91e196f 100644 --- a/lib/tasks/tasks.rake +++ b/lib/tasks/tasks.rake | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | require 'net/http' | ||
| 2 | |||
| 1 | namespace :thoughts do | 3 | namespace :thoughts do |
| 2 | desc "Email a review of the last day's upvotes" | 4 | desc "Email a review of the last day's upvotes" |
| 3 | task :email_upvote_report => :environment do | 5 | task :email_upvote_report => :environment do |
| @@ -7,4 +9,23 @@ namespace :thoughts do | |||
| 7 | VoteMailer.with(votes: votes).daily_report_email.deliver | 9 | VoteMailer.with(votes: votes).daily_report_email.deliver |
| 8 | end | 10 | end |
| 9 | end | 11 | end |
| 12 | |||
| 13 | desc "Refresh the recently listened tracks" | ||
| 14 | task :refresh_scrobbles => :environment do | ||
| 15 | Scrobble.destroy_all | ||
| 16 | |||
| 17 | api_key = Rails.application.credentials.lastfm_api_key | ||
| 18 | url = URI.parse("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=fefferburbia&api_key=#{api_key}&format=json") | ||
| 19 | req = Net::HTTP::Get.new(url.to_s) | ||
| 20 | res = Net::HTTP.start(url.host, url.port) {|http| | ||
| 21 | http.request(req) | ||
| 22 | } | ||
| 23 | output = JSON.parse(res.body) | ||
| 24 | |||
| 25 | items = output["recenttracks"]["track"].map {|p| [p["name"], p["artist"]["#text"], p["album"]["#text"], p["image"][2]["#text"]]}.sort.uniq | ||
| 26 | |||
| 27 | items.each do |item| | ||
| 28 | Scrobble.create!(title: item[0], artist: item[1], album: item[2], image: item[3]) | ||
| 29 | end | ||
| 30 | end | ||
| 10 | end | 31 | end |
| diff --git a/public/robots.txt b/public/robots.txt index 37b576a..d7e6b45 100644 --- a/public/robots.txt +++ b/public/robots.txt | |||
| @@ -1 +1,7 @@ | |||
| 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file | 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file |
| 2 | User-agent: PetalBot | ||
| 3 | Disallow: / | ||
| 4 | |||
| 5 | User-agent: AI2Bot | ||
| 6 | Disallow: / | ||
| 7 | |||
| diff --git a/test/fixtures/scrobbles.yml b/test/fixtures/scrobbles.yml new file mode 100644 index 0000000..9ca535d --- /dev/null +++ b/test/fixtures/scrobbles.yml | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
| 2 | |||
| 3 | one: | ||
| 4 | title: MyString | ||
| 5 | artist: MyString | ||
| 6 | album: MyString | ||
| 7 | image: MyString | ||
| 8 | |||
| 9 | two: | ||
| 10 | title: MyString | ||
| 11 | artist: MyString | ||
| 12 | album: MyString | ||
| 13 | image: MyString | ||
| diff --git a/test/models/scrobble_test.rb b/test/models/scrobble_test.rb new file mode 100644 index 0000000..48541da --- /dev/null +++ b/test/models/scrobble_test.rb | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | require "test_helper" | ||
| 2 | |||
| 3 | class ScrobbleTest < ActiveSupport::TestCase | ||
| 4 | # test "the truth" do | ||
| 5 | # assert true | ||
| 6 | # end | ||
| 7 | end | ||
