Browse Source

Created the basic file structure for crawling the steam friends network.

pull/8/head
jrtechs 5 years ago
parent
commit
85a2f8d6bc
6 changed files with 165 additions and 2 deletions
  1. +2
    -2
      src/main/java/net/jrtechs/www/graphDB/SteamGraph.java
  2. +15
    -0
      src/main/java/net/jrtechs/www/server/Player.java
  3. +28
    -0
      src/main/java/net/jrtechs/www/webCrawler/APIThrottler.java
  4. +59
    -0
      src/main/java/net/jrtechs/www/webCrawler/FileIO.java
  5. +34
    -0
      src/main/java/net/jrtechs/www/webCrawler/SteamWebCrawler.java
  6. +27
    -0
      src/main/java/net/jrtechs/www/webCrawler/SteamdFileWriter.java

+ 2
- 2
src/main/java/net/jrtechs/www/graphDB/SteamGraph.java View File

@ -195,8 +195,8 @@ public class SteamGraph
/**
* Fetches a list of friends from the graph database
*
* @param id
* @return
* @param id steam id
* @return list of friends
*/
private List<Player> getFriendsFromGraph(String id)
{

+ 15
- 0
src/main/java/net/jrtechs/www/server/Player.java View File

@ -1,6 +1,8 @@
package net.jrtechs.www.server;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -20,6 +22,9 @@ public class Player
/** List of friends the player has */
private List<Player> friends;
/** Time which the player was crawled */
private Date date;
/**
* Sets the name and id of the player
@ -32,8 +37,18 @@ public class Player
this.name = name;
this.id = id;
this.friends = null;
this.date = new Date();
}
public List<Player> getFriends() {
return friends;
}
public Date getDate() {
return date;
}
/**
* Returns a list of all the friends of a specific player

+ 28
- 0
src/main/java/net/jrtechs/www/webCrawler/APIThrottler.java View File

@ -0,0 +1,28 @@
package net.jrtechs.www.webCrawler;
import java.util.Calendar;
/**
* @author Jeffery Russell
*/
public class APIThrottler
{
public int totalqueries;
private long lastQuery;
boolean queryAvailable()
{
return true;
}
public long getCurrentTimeInMS()
{
Calendar calendar = Calendar.getInstance();
//Returns current time in millis
long timeMilli2 = calendar.getTimeInMillis();
return timeMilli2;
}
}

+ 59
- 0
src/main/java/net/jrtechs/www/webCrawler/FileIO.java View File

@ -0,0 +1,59 @@
package net.jrtechs.www.webCrawler;
import com.google.gson.Gson;
import net.jrtechs.www.server.Player;
/**
* File which handles the file IO for storing
* all the players on the HHD
*
* @author Jeffery Russell 11-18-18
*/
public class FileIO
{
/** Base directory to store all the data */
private String baseFilaPath;
/** Object used to convert objects to json strings */
private final Gson gson;
/**
* Initalizes the base directory
* @param basePath
*/
public FileIO(String basePath)
{
this.baseFilaPath = basePath;
this.gson = new Gson();
}
/**
* Determines if we already have the player
* on disk.
*
* @param id
* @return
*/
public boolean playerExists(String id)
{
return false;
}
/**
* Writes the player to the file.
*
* @param player
*/
public void writeToFile(Player player)
{
String data = gson.toJson(player);
String fileName = baseFilaPath + player.getId() + ".json";
SteamdFileWriter.writeToFile(data, fileName);
}
}

+ 34
- 0
src/main/java/net/jrtechs/www/webCrawler/SteamWebCrawler.java View File

@ -0,0 +1,34 @@
package net.jrtechs.www.webCrawler;
import net.jrtechs.www.SteamAPI.APIConnection;
import java.io.File;
/**
* Main class for digging up the entire
* steam network.
*
* @author Jeffery Russell
*/
public class SteamWebCrawler
{
private APIThrottler throttler;
private APIConnection connection;
private FileIO fileIO;
public void runSteamCrawler(String baseID)
{
}
public static void main(String args[])
{
new SteamWebCrawler().runSteamCrawler("76561198188400721");
}
}

+ 27
- 0
src/main/java/net/jrtechs/www/webCrawler/SteamdFileWriter.java View File

@ -0,0 +1,27 @@
package net.jrtechs.www.webCrawler;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
public class SteamdFileWriter
{
public static void writeToFile(String data, String fileName)
{
BufferedWriter writer;
try
{
File file = new File(fileName);
file.createNewFile();
writer = new BufferedWriter(new FileWriter(file));
writer.write(data);
writer.flush();
writer.close();
System.out.println("Wrote to " + fileName);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Loading…
Cancel
Save