Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <string>
  4.  
  5. #include <ctime>
  6. #include <sstream>
  7. #include <locale>
  8. #include <iomanip>
  9.  
  10. #define ARTIST_PREFIX 20
  11. #define TRACK_PREFIX 19
  12. #define TIME_PREFIX 14
  13. #define POSTFIX 2
  14.  
  15. struct lastFmEntry {
  16. std::string artist;
  17. std::string title;
  18. std::string album = "single";
  19. int track = 1;
  20. long timestamp;
  21. int length = 300;
  22. char noIdea = 'P';
  23. };
  24.  
  25. int main() {
  26. std::tm t = {};
  27. lastFmEntry currentEntry;
  28.  
  29. bool newEntry = true;
  30.  
  31. std::string line;
  32. while (std::getline(std::cin, line)) {
  33. if (newEntry) {
  34. currentEntry.artist = "";
  35. currentEntry.title = "";
  36. currentEntry.timestamp = 0;
  37. newEntry = false;
  38. }
  39.  
  40. if (line.find("artistName") != std::string::npos) {
  41. std::string artist = line.substr(ARTIST_PREFIX, line.size() - ARTIST_PREFIX - POSTFIX);
  42. if (artist.find(',') != std::string::npos) {
  43. currentEntry.artist = artist.substr(0, artist.find(','));
  44. } else currentEntry.artist = artist;
  45. } else if (line.find("track") != std::string::npos) {
  46. currentEntry.title = line.substr(TRACK_PREFIX, line.size() - TRACK_PREFIX - POSTFIX);
  47. } else if (line.find("time") != std::string::npos) {
  48. // convert human readable time to unix gmt timestamp
  49. std::istringstream ss(line.substr(TIME_PREFIX, line.size() - TIME_PREFIX - POSTFIX + 1));
  50. ss >> std::get_time(&t, "%Y-%m-%d %H:%M:%S");
  51.  
  52. currentEntry.timestamp = std::mktime(&t);
  53.  
  54. if (1528715908 < currentEntry.timestamp && currentEntry.timestamp < 1528960251) {
  55. std::cout <<
  56. "a = " << currentEntry.artist << "\n" <<
  57. "t = " << currentEntry.title << "\n" <<
  58. "b = " << currentEntry.album << "\n" <<
  59. "n = " << currentEntry.track << "\n" <<
  60. "i = " << currentEntry.timestamp << "\n" <<
  61. "l = " << currentEntry.length << "\n" <<
  62. "o = " << currentEntry.noIdea << "\n\n";
  63. }
  64. }
  65. }
  66.  
  67. return 0;
  68. }
Add Comment
Please, Sign In to add comment