Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Formating to XML. Online debug, sry for the spam

  • Loading branch information...
commit e9d8c01911bb64c55a0f071660e00f0d07cc86a5 1 parent 62d1840
@damienalexandre authored
Showing with 85 additions and 84 deletions.
  1. +85 −84 populartagbydays.js
View
169 populartagbydays.js
@@ -5,9 +5,9 @@ var recenttracks = request_instance
.query('user', inputs['user']).query('api_key', inputs['api_key'])
.query('limit', inputs['limit']).accept('application/json').get().response;
-y.log( y.xmlToJson(recenttracks).lfm.recenttracks.track );
+recenttracks = y.xmlToJson(recenttracks).lfm.recenttracks.track;
-response.object = y.xmlToJson(recenttracks).lfm.recenttracks.track;
+//response.object = y.xmlToJson(recenttracks).lfm.recenttracks.track;
//var recenttracks = {
// "results": {
@@ -124,85 +124,86 @@ response.object = y.xmlToJson(recenttracks).lfm.recenttracks.track;
//};
//
-//var days_array = new Object();
-//
-////var ws_toptags = y.rest("http://ws.audioscrobbler.com/2.0/?method=track.gettoptags");
-////y.query('');
-//
-//// For each song
-//for (var trackindex in recenttracks.results.track)
-//{
-// y.log(recenttracks.results.track[trackindex].name);
-// y.log(recenttracks.results.track[trackindex].artist.content);
-// y.log(recenttracks.results.track[trackindex].date.uts);
-//
-//
-// var trackDate = new Date();
-// trackDate.setTime( recenttracks.results.track[trackindex].date.uts * 1000 );
-//
-// var dayDate = new Date(""+trackDate.getFullYear()+"/"+trackDate.getMonth()+"/"+trackDate.getDate());
-// dayDate = (dayDate.getTime()/1000);
-//
-// y.log(dayDate);
-//
-// if (days_array[dayDate] == undefined)
-// {
-// days_array[dayDate] = new Object();
-// }
-//
-// y.log('Call gettoptags for '+recenttracks.results.track[trackindex].artist.content+ ' - '+recenttracks.results.track[trackindex].name);
-//
-// var yql = 'SELECT * FROM lastfm.track.gettoptags WHERE api_key="'+inputs['api_key']+'" and track="'+recenttracks.results.track[trackindex].name+'" and artist="'+recenttracks.results.track[trackindex].artist.content+'"';
-// y.log(yql);
-//
-// var toptags = y.query(yql);
-//
-// y.log(toptags.status);
-//
-// for (var tagindex in toptags.results.lfm.toptags.tag)
-// {
-// var tag = toptags.results.lfm.toptags.tag[tagindex];
-//
-// if (days_array[dayDate][tag.name] != undefined)
-// {
-// days_array[dayDate][tag.name] = (parseInt(days_array[dayDate][tag.name],10) + parseInt(tag.count, 10));
-// }
-// else
-// {
-// days_array[dayDate][tag.name] = parseInt(tag.count,10);
-// }
-// }
-//
-// y.log('End call');
-//}
-//
-//
-//// Order the tags by popularity and format XML
-//var returnXml = <days></days>;
-//
-//for (var day in days_array)
-//{
-// var content = <day></day>;
-// var sortable = [];
-//
-// for (var tagname in days_array[day])
-// {
-// sortable.push([tagname, days_array[day][tagname]])
-// }
-// sortable.sort(function(a, b) {
-// return b[1] - a[1]
-// });
-//
-// y.log("Day "+day+", best tag : "+sortable[0][0]+" with "+ sortable[0][1]);
-//
-// for (var index in sortable)
-// {
-// content.appendChild( <tag count={sortable[index][1]}>{sortable[index][0]}</tag> );
-// }
-//
-// content.@uts = day;
-// returnXml.appendChild( content );
-//}
-//
-////response.object = returnXml;
-////response.object = y.jsonToXml(days_array);
+var days_array = new Object();
+
+//var ws_toptags = y.rest("http://ws.audioscrobbler.com/2.0/?method=track.gettoptags");
+//y.query('');
+
+// For each song
+for (var trackindex in recenttracks)
+{
+ y.log(recenttracks[trackindex].name);
+ y.log(recenttracks[trackindex].artist.content);
+ y.log(recenttracks[trackindex].date.uts);
+
+continue;
+
+ var trackDate = new Date();
+ trackDate.setTime( recenttracks.results.track[trackindex].date.uts * 1000 );
+
+ var dayDate = new Date(""+trackDate.getFullYear()+"/"+trackDate.getMonth()+"/"+trackDate.getDate());
+ dayDate = (dayDate.getTime()/1000);
+
+ y.log(dayDate);
+
+ if (days_array[dayDate] == undefined)
+ {
+ days_array[dayDate] = new Object();
+ }
+
+ y.log('Call gettoptags for '+recenttracks.results.track[trackindex].artist.content+ ' - '+recenttracks.results.track[trackindex].name);
+
+ var yql = 'SELECT * FROM lastfm.track.gettoptags WHERE api_key="'+inputs['api_key']+'" and track="'+recenttracks.results.track[trackindex].name+'" and artist="'+recenttracks.results.track[trackindex].artist.content+'"';
+ y.log(yql);
+
+ var toptags = y.query(yql);
+
+ y.log(toptags.status);
+
+ for (var tagindex in toptags.results.lfm.toptags.tag)
+ {
+ var tag = toptags.results.lfm.toptags.tag[tagindex];
+
+ if (days_array[dayDate][tag.name] != undefined)
+ {
+ days_array[dayDate][tag.name] = (parseInt(days_array[dayDate][tag.name],10) + parseInt(tag.count, 10));
+ }
+ else
+ {
+ days_array[dayDate][tag.name] = parseInt(tag.count,10);
+ }
+ }
+
+ y.log('End call');
+}
+
+
+// Order the tags by popularity and format XML
+var returnXml = <days></days>;
+
+for (var day in days_array)
+{
+ var content = <day></day>;
+ var sortable = [];
+
+ for (var tagname in days_array[day])
+ {
+ sortable.push([tagname, days_array[day][tagname]])
+ }
+ sortable.sort(function(a, b) {
+ return b[1] - a[1]
+ });
+
+ y.log("Day "+day+", best tag : "+sortable[0][0]+" with "+ sortable[0][1]);
+
+ for (var index in sortable)
+ {
+ content.appendChild( <tag count={sortable[index][1]}>{sortable[index][0]}</tag> );
+ }
+
+ content.@uts = day;
+ returnXml.appendChild( content );
+}
+
+//response.object = returnXml;
+//response.object = y.jsonToXml(days_array);
Please sign in to comment.
Something went wrong with that request. Please try again.