Steam ID Project - More and more
So here we are 8 days later and I'm still here, back for another update. Last week I told you why I'm here, how I ended up on WSGF and a little project I'm working on with the Steam Library Compare application. Well it's been a busy week so I haven't done much, the task at the moment is to get the Steam IDs I've managed to match into the WSGF database. On my initial run through I managed to match 537 games and we are almost there. From the 537 I have S and T to do, all others are in there.
To extend the blog a little I'm going to do a show and tell of the code it took to get the matches. Bare in mind when I started this project I had to copy all Games from the master games list manually.
When I get a little further down the line I'm going to be contacting the "dev" guys at WSGF for their help (CrackerJackMack & Brett) I'm hoping to get a dynamic xml off all games in WSGF rather than the current cut down version which only shows those games with Steam IDs. If you're reading this guys :) PLEASE!!
Anyway back to the code sorry it's pretty shoddy and but it was written quickly, oh and C# !!
public static XDocument GetSteamGamesList()
{
return XDocument.Load("http://api.steampowered.com/ISteamApps/GetAppList/v0001/?format=xml");
}
public static XDocument GetAllWSGFGamesList()
{
return XDocument.Load(@"d:\andy\documents\visual studio 2012\Projects\WSGFSteamGameComparer\WSGFnew.xml");
}
protected void generateXML()
{
var wsgf = GetAllWSGFGamesList();
var steam = GetSteamGamesList();
var matches = new Dictionary();
var match = 0;
foreach (var wsgfGame in wsgf.Descendants("node"))
{
var name = new string(wsgfGame.Element("Title").Value.Where(c => !char.IsPunctuation(c)).ToArray());
if (steam.Descendants("name").Select(s => s.Value).Contains(wsgfGame.Element("Title").Value))
{
var theMatch = steam.Descendants("app").First(s => s.Element("name").Value == wsgfGame.Element("Title").Value);
matches.Add(wsgfGame.Element("Title").Value, theMatch.Element("appid").Value);
match++;
}
else if (steam.Descendants("name").Select(s => new string(s.Value.Where(c => !char.IsPunctuation(c)).ToArray())).Contains(name))
{
var theMatch = steam.Descendants("app").First(s => new string(s.Element("name").Value.Where(c => !char.IsPunctuation(c)).ToArray()) == name);
matches.Add(wsgfGame.Element("Title").Value, theMatch.Element("appid").Value);
match++;
}
}
var matchbulder = new StringBuilder();
foreach (var item in matches)
{
matchbulder.AppendLine(string.Format("{0}\t{1}",item.Key,item.Value));
}
var sw = new StreamWriter(@"d:\andy\documents\visual studio 2012\Projects\WSGFSteamGameComparer\AllWSGFMatched.tsv",false);
sw.Write(matchbulder.ToString());
sw.Close();
var builder = new StringBuilder();
builder.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
builder.AppendLine("");
foreach (var wsgfGame in wsgf.Descendants("node"))
{
builder.AppendLine("");
builder.AppendLine(string.Format("{0}", wsgfGame.Element("Title").Value));
builder.AppendLine(string.Format("{0}", wsgfGame.Element("WideScreenGrade").Value));
builder.AppendLine(string.Format("{0}", wsgfGame.Element("MultiMonitorGrade").Value));
if (matches.ContainsKey(wsgfGame.Element("Title").Value))
builder.AppendLine(string.Format("{0}", matches[wsgfGame.Element("Title").Value]));
builder.AppendLine("");
}
builder.AppendLine("");
builder.Replace("&", "&");
var finalDoc = XDocument.Parse(builder.ToString());
finalDoc.Save(@"d:\andy\documents\visual studio 2012\Projects\WSGFSteamGameComparer\AllWSGFMatched.xml");
}
Now it's not elegant but this goes through all WSGF games and matches against the title of the steam game library. To match more I removed punctuation from both steam and WSGF game names.
So I guess that's it for now, I'll finish the steamIDs I have and then see if I can try something else.
S7evin