Autofill with the game database

404 views
Skip to first unread message

Holly

unread,
Mar 24, 2018, 6:47:27 PM3/24/18
to mementodatabase
Hi. I'm a new user and I understand nothing about scripts/javascript.
I've a DB for my games and I'd like to do as a book DB; see the searches from the website when I write a name in the "Game Title" field.
I've found a script on github and it seems working when I make the test.
But nothing when I'm working on my DB ( just a "search"circle)
I opened an account on the website and on the API.
I don't know where's the mistake.
If someone can help me🙁
Thank you.

ccov

unread,
Mar 25, 2018, 11:40:06 AM3/25/18
to mementodatabase
What script on github? What website? Do tell more.

Holly

unread,
Mar 25, 2018, 12:18:11 PM3/25/18
to mementodatabase
Thank you for answer😊
Here the code I've found:
function TheGamesDb() {
}

TheGamesDb.prototype.search = function(gameTitle) {
var resultArray = [];
var result = http().get("http://thegamesdb.net/api/GetGamesList.php?name=" + encodeURIComponent(gameTitle));
var rawxml = result.body;
if (rawxml) {
var xml = new XmlDocument(rawxml);
xml.eachChild(function(game) {
var object = {};
object["id"] = game.valueWithPath("id");
object["title"] = game.valueWithPath("GameTitle");
object["desc"] = game.valueWithPath("Platform");
resultArray.push(object);
});
}
return resultArray;
}

TheGamesDb.prototype.getDetails = function(id) {
var object = {};
var result = http().get("http://thegamesdb.net/api/GetGame.php?id=" + encodeURIComponent(id));
var rawxml = result.body;
if (rawxml) {
var xml = new XmlDocument(rawxml);
var imageBase = xml.valueWithPath("baseImgUrl");
var game = xml.childNamed("Game");
var v;
v = game.valueWithPath("id"); if (v !== undefined) object["ID"] = Number(v);
v = game.valueWithPath("GameTitle"); if (v !== undefined) object["Title"] = v;
v = game.valueWithPath("Platform"); if (v !== undefined) object["Platform"] = v;
v = game.valueWithPath("ReleaseDate"); if (v !== undefined) object["ReleaseDate"] = moment(new Date(v)).toDate().getTime();
v = game.valueWithPath("Overview"); if (v !== undefined) object["Description"] = v;
v = game.valueWithPath("Co-op"); if (v !== undefined) object["CoOp"] = v;
v = game.valueWithPath("Youtube"); if (v !== undefined) object["YouTube"] = v;
v = game.valueWithPath("Rating"); if (v !== undefined) object["Rating"] = Number(v);
v = game.valueWithPath("Players"); if (v !== undefined) object["Players"] = v;
v = game.valueWithPath("Developer"); if (v !== undefined) object["Developer"] = v;
v = game.valueWithPath("Publisher"); if (v !== undefined) object["Publisher"] = v;
v = game.valueWithPath("ESRB"); if (v !== undefined) object["ESRB"] = v;
var genres = game.childNamed("Genres");
var genreList = [];
if (genres) {
genres.eachChild(function(genre) {
genreList.push(genre.val);
});
object["Genres"] = genreList.join();
}
}
return object;
}

And I'd like the informations will be taken on the "thegamesdb.net"
It's seem to be an important videogames DB and I don't think we are able to take informations on Nintendo,Playstation...... own websites.

Is there any mistakes in the code or should I do something else?
I've just copy and past the code.
🤔🤔

Holly

unread,
Mar 26, 2018, 1:03:27 AM3/26/18
to mementodatabase
I've seen that Scott sduensin already post. This is his code I'm trying to apply but I can't.
https://github.com/sduensin/MementoDB/blob/master/TgdbAutofill.js

ccov

unread,
Mar 26, 2018, 7:28:38 PM3/26/18
to mementodatabase
Observation
- The website's API response is in XML format.
- There is no convenient way to parse XML in Memento.

* Memento uses Rhino, a JavaScript implementation in Java.
This engine implements core-language only and doesn't contain web-browser DOM related objects or methods.

Approaches
- Wait for the website to implement JSON format.
- Look for JSON format API website. (recommended)
- Search a way to parse XML that conforms with Rhino.
- Suggest the Memento developer to add a native XML parser:)

* Edit
I have to look at Scott's code, and that I am afraid would take some time.

On Sunday, March 25, 2018 at 5:47:27 AM UTC+7, Holly wrote:

ccov

unread,
Apr 12, 2018, 5:11:09 AM4/12/18
to mementodatabase
Hello. I'm back. Have you found the solution?:)




On Sunday, March 25, 2018 at 5:47:27 AM UTC+7, Holly wrote:

Sokudo Ningyou

unread,
Apr 18, 2018, 10:28:48 PM4/18/18
to mementodatabase

I know I'd like to see an answer.  I really would like to have a DB for my video games that auto fills, but I'm pants at this scripting. I tried using the example Holly posted and pasting in the IGDB suggestion, but either I'm using the wrong URL, or posting something else wrong, because I keep getting errors at line 19.

Bill Crews

unread,
Apr 18, 2018, 10:54:59 PM4/18/18
to Sokudo Ningyou, mementodatabase
Sorry I can't help. I'm just about totally clueless about all this. If you want help with line 19, I could try, but of course, I'd have to see all script lines up to 19 and beyond, and I'd need to know the exact error message, and I might need to know some field types & names and maybe something about how they're used. If that's too much trouble, start with the first two, and maybe I don't need the last two so much.

Sokudo Ningyou

unread,
Apr 19, 2018, 9:14:13 PM4/19/18
to mementodatabase

The frustrating part is, at least in Memento, the lines aren't numbered, or I'm not seeing them, else I could at least pinpoint what "line 19" is.  It just says it's an evaluator exception,missing exponent, custom source.js #19.

Bill Crews

unread,
Apr 19, 2018, 9:49:12 PM4/19/18
to Sokudo Ningyou, mementodatabase
OK, but I still can't help unless you just Select All and Copy the script and post it so we can see it. The other info I mentioned would help, also.

The developer says he will upgrade the editor some day to one that shows line numbers. While waiting, I usually just make do with the editor in Memento, but when I'm working on something big, I use a code editor app -- on Android, I use Quoda, and on Windows, I use Atom -- They support line numbers. They have better syntax color schemes, also.

Sokudo Ningyou

unread,
Apr 22, 2018, 5:31:35 PM4/22/18
to mementodatabase
I can give you the script, but the error message isn't saving to the log. I don't know if it's because I am testing it in the "edit library" area instead of running it, but I can't get a copy of it.

**
The data source for obtaining information from giantbomb
@param {string} apiKey - Consumer key.
@param {string} apiSecret - Consumer secret.
@param {string} type request - search, game
https://www.giantbomb.com/api/documentation
@example
var giant = new GiantBomb("Consumer key" ,10, "game" );
var r = giant.search('search/',query);
result(giant.getGamesArray(r));
//result( r , function(id) { return giant.extra(id);});
*/


/**
constructor
**/
function GiantBomb (apiKey ,searchLimit, type) {
this.apiKey = 9425ea86684f24e51a9b6ffc9299f82b;
this.type = game;
this.searchLimit = searchLimit;
this.url = "https://api-endpoint.igdb.com";
this.platformsPriority = ["PC","PS4","TurboGrafx-16","PC-FX","TGCD","PCFX","TurboGrafx-CD","Nintendo DS","WonderSwan","DS"];


}
/**
Issue a search query to GiantBomb database.
@param {string} query - Search query.
@return json
*/
GiantBomb.prototype.search = function(resource,query) {
var filter="&field_list=id";
var searchString= https://api-endpoint.igdb.com'+resource+'/?api_key='+9425ea86684f24e51a9b6ffc9299f82b+'&query='+ encodeURIComponent(query)+'&resources='+ this.type +'&format=json&limit='+this.searchLimit+filter;
var result = http().get(searchString);
var json = JSON.parse(result.body);
return json.results;
}///search

/**
@param (array) games : json results of the search
@description : build an array[title,desc]
**/
GiantBomb.prototype.getGamesArray = function(games) {
var resultArray=[];
for (i=0;i<games.length;i++){
var object = {};
var object = this.getGame(games[i].id);
resultArray.push(object);
}
return (resultArray);
}///getGamesArray

/**
@param {string} id - The resource identifier.
@return array of game
*/
GiantBomb.prototype.getGame = function(id) {

var gameID = '3030-'+id;
var resource = 'game/' + gameID;
var object = {};

var filter ="&field_list=name,deck,original_release_date,publishers,developers,genres,platforms,image";
var searchString= this.url+resource+'/?api_key='+this.apiKey+'&format=json'+filter;
var result = http().get(searchString);
var game = JSON.parse(result.body);

var obj = game.results;
var tab = []; var strGenre=""; var strPub = ""; var strDev = ""; var strPlat = "";
for (x in obj.genres ){ tab.push(obj.genres[x].name);}
strGenre = tab.toString();
tab = [];
for (x in obj.publishers ){ tab.push(obj.publishers[x].name);}
strPub = tab.toString();
tab = [];
for (x in obj.developers ){ tab.push(obj.developers[x].name);}
strDev = tab.toString();
tab = [];
for (x in obj.platforms ){
if (this.platformsPriority.indexOf(obj.platforms[x].abbreviation)>-1)
tab.push(obj.platforms[x].abbreviation);
}
strPlat = tab.toString();

object["title"] = obj.name ;
object["id"] = id ;
object["desc"] = strPlat + "\n" +obj.deck ;
object["date"] = obj.original_release_date ;
object["dev"] = strDev ;
object["pub"] = strPub ;
object["genres"] = strGenre ;
object["image"] = obj.image.thumb_url ;


return object;

}///getGame

Bill Crews

unread,
Apr 23, 2018, 12:57:59 AM4/23/18
to Sokudo Ningyou, mementodatabase
I'm sorry. I'm out of my depth. I've never done a Web Autofill, and though I've learned some JavaScript for running within Rhino within Memento, this JavaScript seems to run elsewhere, to have a preprocessor, and use JavaScript elements that Rhino doesn't know.

Before I bow out, I'll say that line 19 is either just before function GiantBomb() or right after it, depending on whether line numbering includes preprocessor lines (like @param) or not. There are no exponents there.

Good luck.

ccov

unread,
Apr 23, 2018, 10:36:38 PM4/23/18
to mementodatabase
function GiantBomb (apiKey ,searchLimit, type) {

   
this.apiKey = apiKey;
   
this.type = type;
   
this.searchLimit = searchLimit;
       
// ...

Don't plug and play code hoping it would somehow works.The script is meant for this video game website.
And never write your API key in public forum.

On Sunday, March 25, 2018 at 5:47:27 AM UTC+7, Holly wrote:

Sokudo Ningyou

unread,
Apr 24, 2018, 9:08:24 PM4/24/18
to mementodatabase


On Sunday, April 22, 2018 at 4:31:35 PM UTC-5, Sokudo Ningyou wrote:
I can give you the script, but the error message isn't saving to the log. I don't know if it's because I am testing it in the "edit library" area instead of running it, but I can't get a copy of it.

**
The data source for obtaining information from giantbomb
@param {string} apiKey - Consumer key.
@param {string} apiSecret - Consumer secret.
@param {string} type request - search, game
https://www.giantbomb.com/api/documentation
@example
var giant = new GiantBomb("Consumer key" ,10, "game" );
var r = giant.search('search/',query);
result(giant.getGamesArray(r));
//result( r , function(id) { return giant.extra(id);});
*/


/**
constructor
**/
function GiantBomb (apiKey ,searchLimit, type) {

    this.apiKey = ;


    this.type = game;
        this.searchLimit = searchLimit;
        this.url = "https://api-endpoint.igdb.com";
        this.platformsPriority = ["PC","PS4","TurboGrafx-16","PC-FX","TGCD","PCFX","TurboGrafx-CD","Nintendo DS","WonderSwan","DS"];


}
/**
Issue a search query to GiantBomb database.
@param {string} query - Search query.
@return json
*/
GiantBomb.prototype.search = function(resource,query) {
        var filter="&field_list=id";

  var searchString= https://api-endpoint.igdb.com'+resource+'/?api_key='++'&query='+ encodeURIComponent(query)+'&resources='+ this.type +'&format=json&limit='+this.searchLimit+filter;

Reply all
Reply to author
Forward
0 new messages