Last active
September 13, 2015 07:00
-
-
Save Dartv/14a06f5255e907879f94 to your computer and use it in GitHub Desktop.
loop through months and insert maps to database
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
| _.each(dateRange(), function (month) { | |
| var beatmaps = osu.getBeatmapsRaw({ | |
| since: month | |
| }, Meteor.bindEnvironment(function (err, res) { | |
| if (err) throw new Meteor.Error(err); | |
| var mapsJson = JSON.stringify(res); | |
| var maps = JSON.parse(mapsJson); | |
| for (var map in maps) { | |
| var objectToUpdate = { | |
| "beatmapset_id": maps[map].beatmapset_id, | |
| "beatmap_id": maps[map].beatmap_id, | |
| "approved": maps[map].approved, | |
| "total_length": maps[map].total_length, | |
| "hit_length": maps[map].hit_length, | |
| "version": maps[map].version, | |
| "file_md5": maps[map].file_md5, | |
| "diff_size": maps[map].diff_size, | |
| "diff_overall": maps[map].diff_overall, | |
| "diff_approach": maps[map].diff_approach, | |
| "diff_drain": maps[map].diff_drain, | |
| "mode": maps[map].mode, | |
| "approved_date": maps[map].approved_date, | |
| "last_update": maps[map].last_update, | |
| "artist": maps[map].artist, | |
| "title": maps[map].title, | |
| "creator": maps[map].creator, | |
| "bpm": maps[map].bpm, | |
| "source": maps[map].source, | |
| "genre_id": maps[map].genre_id, | |
| "language_id": maps[map].language_id, | |
| "favourite_count": maps[map].favourite_count, | |
| "playcount": maps[map].playcount, | |
| "passcount": maps[map].passcount, | |
| "max_combo": maps[map].max_combo, | |
| "difficultyrating": maps[map].difficultyrating | |
| }; | |
| Test.upsert({ | |
| beatmap_id: maps[map].beatmap_id | |
| }, { | |
| $set: objectToUpdate | |
| }, { | |
| multi: true, | |
| upsert: true | |
| }, function (err, res) { | |
| if (err) throw new Meteor.Error(err); | |
| }); | |
| } | |
| })); | |
| }); | |
| console.log("DONE"); | |
| } | |
| function dateRange() { | |
| var resultList = []; | |
| var months = []; | |
| var date = new Date("August 07, 2015"); | |
| var endDate = new Date(); | |
| var monthNameList = ["January", "February", "March", "April", "May", "Jun", "Jul", "August", "September", "October", "November", "December"]; | |
| while (date <= endDate) { | |
| var stringDate = monthNameList[date.getMonth()] + " " + date.getFullYear(); | |
| resultList.push(stringDate); | |
| date.setMonth(date.getMonth() + 1); | |
| } | |
| _.each(resultList, function (month) { | |
| var currentMonth = new Date(month); | |
| months.push(currentMonth); | |
| }); | |
| console.log(months); | |
| return months; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment