about summary refs log tree commit diff stats
path: root/lib/tasks/tasks.rake
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2025-11-21 21:01:50 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2025-11-21 21:01:50 -0500
commit4a9bf38ef61b39e482458ba56cd1e6fea379b4d7 (patch)
treeed778402e454cbbb3945f453f6d1682f4701924a /lib/tasks/tasks.rake
parentc260fbba4ed7cd0e7b80d5ae1316f597f9abb827 (diff)
downloadthoughts-4a9bf38ef61b39e482458ba56cd1e6fea379b4d7.tar.gz
thoughts-4a9bf38ef61b39e482458ba56cd1e6fea379b4d7.tar.bz2
thoughts-4a9bf38ef61b39e482458ba56cd1e6fea379b4d7.zip
Added "listening to" box in sidebar
Diffstat (limited to 'lib/tasks/tasks.rake')
-rw-r--r--lib/tasks/tasks.rake21
1 files changed, 21 insertions, 0 deletions
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 @@
1require 'net/http'
2
1namespace :thoughts do 3namespace :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
10end 31end