- MAKE A BACKUP.
- Register a new application on Last.fm.
- Set the API Key and API Secret on line 10 and 11 of
index.js
- Install Node/NPM.
- Run
npm install
- Run
node lastfm2dayone.js
- Enjoy!
Last active
December 28, 2015 07:39
-
-
Save aliou/7465824 to your computer and use it in GitHub Desktop.
Last.fm -> Currently Playing in Day One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('underscore'); | |
var DayOne = require('dayone').DayOne; | |
var DayOneEntry = require('dayone').DayOneEntry; | |
var LastfmAPI = require('lastfmapi'); | |
var moment = require('moment'); | |
var FIVEMINUTES = 300; | |
var lfm = new LastfmAPI({ | |
'api_key' : process.env.LASTFM_KEY, | |
'secret' : process.env.LASTFM_SECRET | |
}); | |
var journal = new DayOne(); | |
journal.list({}, function(err, entries) { | |
var filteredEntries = _.filter(entries, function(entry) { | |
return (_.isEmpty(entry.music) && !_.contains(entry.tags, 'moves-import')); | |
}); | |
filteredEntries.forEach(function(entry) { | |
var date = moment(entry.creationDate).unix(); | |
var options = { | |
user: process.env.LASTFM_USER, | |
limit: 5, | |
from: date - FIVEMINUTES, | |
to: date + FIVEMINUTES | |
}; | |
lfm.user.getRecentTracks(options, function(err, tracks) { | |
if (!_.isUndefined(tracks.track)) { | |
console.log(entry.creationDate); | |
var track; | |
if (_.isArray(tracks.track)) | |
track = tracks.track[0]; | |
else | |
track = tracks.track | |
entry.music = { | |
'Album': track.album['#text'], | |
'Artist': track.artist['#text'], | |
'Track': track.name | |
}; | |
journal.save(entry, function(err) {}); | |
console.log('-------------------'); | |
} | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "lastfm2DayOne", | |
"version": "0.0.1", | |
"private": true, | |
"engines": { | |
"node": "0.10.12", | |
"npm": "1.2.x" | |
}, | |
"dependencies": { | |
"lastfmapi": "0.0.5", | |
"dayone": "https://github.com/aliou/dayone/tarball/metadata", | |
"underscore": "~1.5.2", | |
"moment": "~2.4.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment