Graph database Analysis of the Steam Network
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
4.2 KiB

  1. package net.jrtechs.www.webCrawler;
  2. import net.jrtechs.www.SteamAPI.APIConnection;
  3. import net.jrtechs.www.model.Player;
  4. import java.util.*;
  5. /**
  6. * Main class for digging up the entire
  7. * steam network.
  8. *
  9. * @author Jeffery Russell 11-18-18
  10. */
  11. @Deprecated
  12. public class SteamWebCrawler
  13. {
  14. /** Object used to limit the speed at which I access the steam
  15. * network */
  16. private APIThrottler throttler;
  17. /** Connection to the steam network */
  18. private APIConnection connection;
  19. /** Saves players to the disk */
  20. private FileIO fileIO;
  21. /** Queue used for a BFS search */
  22. private LinkedList<Player> downlaodQueue;
  23. /** Players which have been detected by
  24. * our search and currently in a queue
  25. * or has already been processed*/
  26. private HashSet<String> visited;
  27. /** List of players which we have accessed
  28. * in the steam network, but, have no clue what
  29. * their name is*/
  30. private LinkedList<String> namelessQueue;
  31. /**
  32. * Initializes the steam crawler's objects
  33. */
  34. public SteamWebCrawler()
  35. {
  36. throttler = new APIThrottler();
  37. this.connection = new APIConnection();
  38. this.fileIO = new FileIO("/media/jeff/A4BA9239BA920846/steamData/");
  39. this.downlaodQueue = new LinkedList<>();
  40. visited = new HashSet<>();
  41. namelessQueue = new LinkedList<>();
  42. }
  43. /**
  44. * If the download queue is empty, this will
  45. * look up the names of the first 100 players in the
  46. * nameless queue and add them to download queue.
  47. */
  48. private void shiftNamelessToDownload()
  49. {
  50. //this is a while instead of if because the getfull players query fails
  51. //once in a blue moon
  52. while(this.downlaodQueue.isEmpty() && !this.namelessQueue.isEmpty())
  53. {
  54. List<String> winners = new ArrayList<>();
  55. for(int i = 0; i < (100 < namelessQueue.size()? 100: namelessQueue.size()); i++)
  56. {
  57. winners.add(this.namelessQueue.remove());
  58. }
  59. List<Player> namedPlayers = connection.getPlayers(winners);
  60. this.throttler.wait(1);
  61. downlaodQueue.addAll(namedPlayers);
  62. }
  63. }
  64. /**
  65. * Does one of the following three actions for each
  66. * of the steam members in the list:
  67. * 1: Ignore- already has been queued by program
  68. * 2: Add to nameless queue -- doesn't have name yet
  69. * 3: Add to download queue -- already on HHD but needed for
  70. * the search algo to work.
  71. *
  72. * @param ids list of steam ids
  73. */
  74. private void queueUpPlayers(List<String> ids)
  75. {
  76. for(String s: ids)
  77. {
  78. if(!visited.contains(s))
  79. {
  80. if(fileIO.playerExists(s))
  81. {
  82. //downlaodQueue.add(new Player("dummy", s));
  83. }
  84. else
  85. {
  86. namelessQueue.add(s);
  87. }
  88. visited.add(s);
  89. }
  90. }
  91. System.out.println("Download Queue: " + downlaodQueue.size());
  92. System.out.println("Nameless Queue: " + namelessQueue.size());
  93. }
  94. /**
  95. * Runs a BFS search of the steam network
  96. */
  97. private void runCrawler()
  98. {
  99. while(!downlaodQueue.isEmpty())
  100. {
  101. Player current = downlaodQueue.remove();
  102. List<String> currentFriends;
  103. if(!fileIO.playerExists(current.getId()))
  104. {
  105. this.throttler.wait(1);
  106. currentFriends = connection.getFriends(current.getId());
  107. fileIO.writeToFile(current, currentFriends);
  108. }
  109. else
  110. {
  111. currentFriends = fileIO.readFriends(current.getId());
  112. }
  113. queueUpPlayers(currentFriends);
  114. shiftNamelessToDownload();
  115. }
  116. }
  117. /**
  118. * pop first fiend on the queue
  119. * and release the beast
  120. *
  121. * @param baseID
  122. */
  123. public void runSteamCrawlerBase(String baseID)
  124. {
  125. //downlaodQueue.add(new Player("jrtechs", baseID));
  126. runCrawler();
  127. }
  128. public static void main(String args[])
  129. {
  130. new SteamWebCrawler().runSteamCrawlerBase("76561198188400721");
  131. }
  132. }