ZXDB based Open API

This is the place for general discussion and updates about the ZXDB Database. This forum is not specific to Spectrum Computing.

Moderator: druellan

User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

[mention]Turrican[/mention] - I've added a /magazine/search method to the API, please try it out - https://api.zxinfo.dk/doc/

/Thomas
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
Turrican
Microbot
Posts: 187
Joined: Thu Apr 12, 2018 5:48 pm
Location: Brazil

Re: ZXDB based Open API

Post by Turrican »

kolbeck wrote: Sat Dec 01, 2018 11:31 pm @Turrican - I've added a /magazine/search method to the API, please try it out - https://api.zxinfo.dk/doc/

/Thomas
Ok. Thank you!
User avatar
Turrican
Microbot
Posts: 187
Joined: Thu Apr 12, 2018 5:48 pm
Location: Brazil

Re: ZXDB based Open API

Post by Turrican »

kolbeck wrote: Sat Dec 01, 2018 11:31 pm @Turrican - I've added a /magazine/search method to the API, please try it out - https://api.zxinfo.dk/doc/

/Thomas
Hi Thomas.
I´m using the magazine search in a different way.
This new method shows all magazines (only one line, with basic info) with all words that I input, right?
The app lists all magazines issues with the same name in the input field. :)

So in the new method if I input "your sinclair" it shows "Your Sinclair", "Sinclair User", "Your Spectrum", etc...
How my search works:
When I input "Your Sinclair" it shows all Your Sinclair issues with cover images. The problem here is that it is case sensitive.
Thank you.
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

ahh.. ok - in general REST URLs are case sensitive. The idea was that a client, in this case your app, used the magazine list or the new search to find the exact magazine name - but in this case I think an exception could be made.

The following should now work and return the same result:
https://api.zxinfo.dk/api/zxinfo/v2/mag ... ir/issues/
https://api.zxinfo.dk/api/zxinfo/v2/mag ... ir/issues/
https://api.zxinfo.dk/api/zxinfo/v2/mag ... ir/issues/

/Thomas
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
Turrican
Microbot
Posts: 187
Joined: Thu Apr 12, 2018 5:48 pm
Location: Brazil

Re: ZXDB based Open API

Post by Turrican »

kolbeck wrote: Tue Dec 04, 2018 8:25 pm ahh.. ok - in general REST URLs are case sensitive. The idea was that a client, in this case your app, used the magazine list or the new search to find the exact magazine name - but in this case I think an exception could be made.

The following should now work and return the same result:
https://api.zxinfo.dk/api/zxinfo/v2/mag ... ir/issues/
https://api.zxinfo.dk/api/zxinfo/v2/mag ... ir/issues/
https://api.zxinfo.dk/api/zxinfo/v2/mag ... ir/issues/

/Thomas

Danke!
User avatar
PeterJ
Site Admin
Posts: 6858
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: ZXDB based Open API

Post by PeterJ »

I set myself a goal for January.. I wanted to get started with Python and JSON. I have never used either of these technologies before (so treat me gently!). I thought the best way to approach this would be to use the excellent API from [mention]kolbeck[/mention].

This will never win any awards, but shows how relatively straightforward it is to get information out of the API using standard Python modules. The beauty of Python is that it's multi-platform. So I have it running on my Windows 10 machine, my Ubuntu box and the Raspberry Pi. I'm hoping to be able to add a GUI using tkinter in the future, and of course allow users to search for a title. When I have something half decent I will add it onto the Spectrum Computing GutHub page.

I did originally try learning C# but it blew my mind!

Code: Select all

import json
import urllib.request

data = urllib.request.urlopen("https://api.zxinfo.dk/api/zxinfo/games/0005671?mode=compact").read().decode('utf8')

output = json.loads(data)

id = output ['_id']
fulltitle= output ['_source']['fulltitle']
type=output ['_source']['type']
machinetype=output ['_source']['machinetype']
messagelanguage=output ['_source']['messagelanguage']
yearofrelease=output ['_source']['yearofrelease']
originalpublisher=output ['_source']['publisher'][0]['name']
print ('ID:\t\t',id)
print ('Full Title:\t',fulltitle)
print ('Genre:\t\t',type)
print ('Machine Type:\t',machinetype)
print ('Message Language:\t',messagelanguage)
print ('Year of Release:\t',yearofrelease)
print ('Original Publisher:\t',originalpublisher)
print ('')
print ('Control Options:')
for item in output['_source']['controls']:
        controls=item ['control']
        print(controls)
print ('')
print ('Roles:')
for item in output ['_source']['roles']:
	roles_name=item ['name']
	roles_role=item ['role']
	print (roles_name,':\t',roles_role)
print ('')
print ('Authors:')
for item in output  ['_source']['authors']:
	aname=item ['authors'][0]['name']	
	print (aname)
 
Image
User avatar
Turrican
Microbot
Posts: 187
Joined: Thu Apr 12, 2018 5:48 pm
Location: Brazil

Re: ZXDB based Open API

Post by Turrican »

It seems to be easy!
Much more than what I have done in Android.
Good work. :mrgreen:
User avatar
4thRock
Manic Miner
Posts: 415
Joined: Thu Nov 09, 2017 9:35 am
Location: Portugal

Re: ZXDB based Open API

Post by 4thRock »

I love Python because it allows you to write friendly code. :D
Things are logical and the outcomes are predictable.
Very easy to debug just by looking at the code.
One day I'd like to try on a Web server. I think it might be a good alternative to PHP.

Peter, you should look at Python "dictionaries" to manage the data coming from the queries.
Or arrays of arrays ;)
User avatar
PeterJ
Site Admin
Posts: 6858
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: ZXDB based Open API

Post by PeterJ »

Thanks [mention]4thRock[/mention]

I will take a look at dictionaries on the online resources I'm using.

Peter
User avatar
4thRock
Manic Miner
Posts: 415
Joined: Thu Nov 09, 2017 9:35 am
Location: Portugal

Re: ZXDB based Open API

Post by 4thRock »

This is self explanatory:

Code: Select all

thisdict =	{
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
x = thisdict["model"]
print(x)
You get Mustang as expected.

I'm sure you will enjoy your reading!
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

Hi

Website and API updated to latest ZXDB (Feb 03 - 2019)

API now returns additional prices, if available, on each release - as a result of internal re-structuring of ZXDB on prices.

/Thomas
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: ZXDB based Open API

Post by Einar Saukas »

Thank you!
User avatar
druellan
Dynamite Dan
Posts: 1466
Joined: Tue Apr 03, 2018 7:19 pm

Re: ZXDB based Open API

Post by druellan »

kolbeck wrote: Tue Feb 05, 2019 1:08 pm Website and API updated to latest ZXDB (Feb 03 - 2019)
Thanks!
BTW, I'm getting some broken images for the MIA games, but also for not-so-popular ones that actually have a screenshot. Tested on Chrome and Firefox.

Image

The problem seems related to the in.game screens

Image
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

It’s a known issue- I’m working on it :-)

/T
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

[mention]druellan[/mention] - images should be working again

/T
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

ZXDB Open API updated to 25.02.2019 release.

The ZXDB contains some internal changes which affects the output from the API.

- Mod of / inspired by is now NxN relations, which means the "mod_of" property now is returned as an array.

Code: Select all

"mod_of": [
	{
		"id": "0003899",
		"is_mod": 1,
		"type": "Mod from",
		"title": "Project Future",
		"publisher": "Micromania",
		"machinetype": "ZX-Spectrum 48K"
	},
	{
		"id": "0009408",
		"is_mod": 1,
		"type": "Mod from",
		"title": "Sabre Wulf",
		"publisher": "Ultimate Play The Game",
		"machinetype": "ZX-Spectrum 48K"
	}
]
The "relationtype" is added to the output, taken directly from ZXDB (can be "Mod of" or "Inspired by"), will by next release replace the "is_mod" property, used in the old ZXDB structure.

/Thomas
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

ZXDB Open API v1.5.0 has just been released.

https://api.zxinfo.dk/doc/

Added 'tiny' outputmode, containing the following properties:
  • fulltitle
    yearofrelease
    machinetype
    type + subtype (genre)
    publisher
    additionals (for screens)
Added API endpoint for fetching random SOFTWARE entries from the following categories:
  • Adventure Game
    Arcade Game
    Casual Game
    Game
    Sport Game
    Strategy Game
Are these changes essential? Not really, but they are required in my upcoming project :o

/T
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
Turrican
Microbot
Posts: 187
Joined: Thu Apr 12, 2018 5:48 pm
Location: Brazil

Re: ZXDB based Open API

Post by Turrican »

Hi kolbeck!
A doubt: I updated the ZX App with Downloads Tab where we can download any software on the external storage of our device.
Old softwares are in the "releases" section where I´m getting the urls.
But new softwares are in the "additionals" section.
How can I know if I have to take url from releases or additionals?

Thank you!
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

[mention]Turrican[/mention] - thanks for the observations :-)

The short explanation is that in old WOS data, each "game release" is linked to a machine type - this is not the case in ZXDB. I guess the reason is that this would require a one-to-many relation and a restructure of the database model. The API used this information to determine if a file has to be in the release part or the additional section.

I've changed the logic, so now the API assumes if the file is on of the known "game" formats. such as tap, tzx, disk image etc. it belongs to the release section, otherwise the additional part. Not perfect - but at least it seems to be working for all my test cases.

So for now, you can assume that the software for an entry is to be found in the release section - otherwise let me know of any cases where this does not apply.

/Thomas
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
Turrican
Microbot
Posts: 187
Joined: Thu Apr 12, 2018 5:48 pm
Location: Brazil

Re: ZXDB based Open API

Post by Turrican »

Great!!!
Now we get all downloads.
Thank you very much!
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

You're welcome :-)

I'm this far for now.... hehe

Image
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
Turrican
Microbot
Posts: 187
Joined: Thu Apr 12, 2018 5:48 pm
Location: Brazil

Re: ZXDB based Open API

Post by Turrican »

Great!!
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: ZXDB based Open API

Post by Einar Saukas »

kolbeck wrote: Mon Mar 04, 2019 7:55 pmThe short explanation is that in old WOS data, each "game release" is linked to a machine type - this is not the case in ZXDB. I guess the reason is that this would require a one-to-many relation and a restructure of the database model.
What do you mean?

kolbeck wrote: Mon Mar 04, 2019 7:55 pmI've changed the logic, so now the API assumes if the file is on of the known "game" formats. such as tap, tzx, disk image etc. it belongs to the release section, otherwise the additional part. Not perfect - but at least it seems to be working for all my test cases.
Instead of file format, it's more reliable to check file type:

Code: Select all

filetype_id IN (46, 47) OR filetype_id BETWEEN 8 AND 22
User avatar
kolbeck
Manic Miner
Posts: 309
Joined: Mon Nov 13, 2017 9:04 pm

Re: ZXDB based Open API

Post by kolbeck »

Einar Saukas wrote: Tue Mar 05, 2019 12:19 pm
kolbeck wrote: Mon Mar 04, 2019 7:55 pmThe short explanation is that in old WOS data, each "game release" is linked to a machine type - this is not the case in ZXDB. I guess the reason is that this would require a one-to-many relation and a restructure of the database model.
What do you mean?
I used the machinetype_id in the downloads table, however it looks like its only valid for the old WOS entries. All new downloads (software) added to ZXDB seems to have machinetype_id set to NULL.

However, it's not a big problem - i will just use your suggested where clause instead :-)

/T
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
User avatar
Turrican
Microbot
Posts: 187
Joined: Thu Apr 12, 2018 5:48 pm
Location: Brazil

Re: ZXDB based Open API

Post by Turrican »

Hi [mention]kolbeck[/mention] !
One doubt: I´m getting trouble to get the front inlay image of the cassetes.
Sometimes I get the back inlay, sometimes the inside inlay... because there is no order on images.
Example:
Pit Fighter has the front inlay in the 2nd image:
/zxdb/sinclair/entries/0003742/Pit-Fighter_Back.jpg
/zxdb/sinclair/entries/0003742/Pit-Fighter_Front.jpg

And Out Run is on the first image:
/pub/sinclair/games-inlays/o/OutRun.jpg
/pub/sinclair/games-inlays/o/OutRun_2.jpg
/pub/sinclair/games-inlays/o/OutRun_Inside.jpg

Is there a way where the front inlay is always the first one?

Thanks!
Locked