How to retrieve all book categories from Amazon by ASIN? - amazon-product-api

Could anybody tell how to retrieve list of categories from a book by ASIN like this website does?

Use the Amazon Product Advertising API v5 for this. Create a GetItems request with the ASIN (e.g 1641521198) as ItemsId and request the BrowserNoteInfo.BrowserNodes and BrowserNoteInfo.BrowserNodes.Ancestor as ressources.
The response will look like the following:
{
"ItemsResult": {
"Items": [
{
"ASIN": "1641521198",
"BrowseNodeInfo": {
"BrowseNodes": [
{
"Ancestor": {
"Ancestor": {
"Ancestor": {
"Ancestor": {
"ContextFreeName": "Books",
"DisplayName": "Books",
"Id": "283155"
},
"ContextFreeName": "Subjects",
"DisplayName": "Subjects",
"Id": "1000"
},
"ContextFreeName": "Cookbooks, Food & Wine",
"DisplayName": "Cookbooks, Food & Wine",
"Id": "6"
},
"ContextFreeName": "Baking",
"DisplayName": "Baking",
"Id": "4196"
},
"ContextFreeName": "Bread Baking",
"DisplayName": "Bread",
"Id": "4197",
"IsRoot": false
},
{
"Ancestor": {
"Ancestor": {
"Ancestor": {
"Ancestor": {
"ContextFreeName": "Books",
"DisplayName": "Books",
"Id": "283155"
},
"ContextFreeName": "Subjects",
"DisplayName": "Subjects",
"Id": "1000"
},
"ContextFreeName": "Cookbooks, Food & Wine",
"DisplayName": "Cookbooks, Food & Wine",
"Id": "6"
},
"ContextFreeName": "Cooking by Ingredient",
"DisplayName": "Cooking by Ingredient",
"Id": "4208"
},
"ContextFreeName": "Natural Food Cooking",
"DisplayName": "Natural Foods",
"Id": "4340",
"IsRoot": false
},
{
"Ancestor": {
"Ancestor": {
"Ancestor": {
"Ancestor": {
"ContextFreeName": "Books",
"DisplayName": "Books",
"Id": "283155"
},
"ContextFreeName": "Subjects",
"DisplayName": "Subjects",
"Id": "1000"
},
"ContextFreeName": "Cookbooks, Food & Wine",
"DisplayName": "Cookbooks, Food & Wine",
"Id": "6"
},
"ContextFreeName": "Main Courses & Side Dishes",
"DisplayName": "Main Courses & Side Dishes",
"Id": "4234"
},
"ContextFreeName": "Garnishing Meals",
"DisplayName": "Garnishes",
"Id": "7696136011",
"IsRoot": false
}
]
},
"DetailPageURL": "https://www.amazon.com/dp/1641521198?tag=getabstractcom&linkCode=ogi&th=1&psc=1"
}
]
}
}
With that data you should be able to determinate the categories such as
Books » Cookbooks, Food & Wine » Baking » Bread Baking
or
Books » Cookbooks, Food & Wine » Main Courses & Side Dishes » Garnishing Meals
More information about the PAAPI5 you find here. There exists as well some SDK for different programming languages such as Java, PHP, Node or Python.

Related

Metadata converter?

Im currently working on a generated collection and got a huge metadata file. Its build up like this:
[
{
"name": "amongnfts #1",
"description": "This is one member of the AmongNFT collection. It's unique and only exists once, but may be a bit cooler than the others.",
"image": "/1.png",
"dna": "055b93fd187e52f85e3ea8b0ad660fa51aaea9e0",
"edition": 1,
"date": 1645368881553,
"attributes": [
{
"trait_type": "background",
"value": "blue"
},
{
"trait_type": "body",
"value": "pink"
},
{
"trait_type": "clothing",
"value": "teamred"
},
{
"trait_type": "hat",
"value": "pilot"
},
{
"trait_type": "visor",
"value": "krieghaus"
},
{
"trait_type": "pet",
"value": "minimateorange"
}
],
"compiler": "HashLips Art Engine"
},
{
"name": "amongnfts #2",
"description": "This is one member of the AmongNFT collection. It's unique and only exists once, but may be a bit cooler than the others.",
"image": "/2.png",
"dna": "a05e9acf4665b9e9e5adbcb9dfc33df255e2e58f",
"edition": 2,
"date": 1645368883622,
"attributes": [
{
"trait_type": "background",
"value": "orange"
},
{
"trait_type": "body",
"value": "white"
},
{
"trait_type": "clothing",
"value": "elf"
},
{
"trait_type": "hat",
"value": "wethair"
},
{
"trait_type": "visor",
"value": "none"
},
{
"trait_type": "pet",
"value": "minimatetan"
}
],
"compiler": "HashLips Art Engine"
},
]
(Goes down for 10.000 editions so thats why I dont do it manually.)
But it should look like this:
{
"nft": [
{
"file_path": "/1.png",
"nft_name": "amongnfts #1",
"external_link": "",
"description": "This is one member of the AmongNFT collection. It's unique and only exists once, but may be a bit cooler than the others.",
"collection": "AmongNFTs",
"properties": [
{
"type": "background",
"name": "blue"
},
{
"type": "body",
"name": "pink"
},
{
"type": "clothing",
"name": "teamred"
},
{
"type": "hat",
"name": "pilot"
},
{
"type": "visor",
"name": "krieghaus"
},
{
"type": "pet",
"name": "minimateorange"
},
],
"levels": "",
"stats": "",
"unlockable_content": "",
"explicit_and_sensitive_content": "",
"supply": "1",
"blockchain": "Polygon",
"sale_type": "",
"price": 0.001,
"method": "",
"duration": "",
"specific_buyer": "",
"quantity": ""
}
]
}
Is there an easy way of converting them automatically and if so, how would the code look like?
The metadata.json file is here.

How to map Nested Array of Objects using Swift Object Mapper?

I am trying to map an array of objects using Object Mapper
I have this code so far, and my mapping is not successful
do {
if let data = data, let sectorData = Mapper<SubSectorsModel>().mapArrayOfArrays(JSONObject: try JSONSerialization.data(withJSONObject: data, options: [])) {
completionHandler(sectorData,(response as! HTTPURLResponse), error)
print("SectionData Received Successfully")
}
} catch {
completionHandler(nil,(response as! HTTPURLResponse), error)
print("Error parsing json get sector data: ", error.localizedDescription)
}
My Json data is as follows:
[
{
"SECTOR_NAME": "MANUFACTURERS",
"ID": "8",
"SECTOR": [
{
"ID": "144",
"NAME": "Biomass Processing"
},
{
"ID": "8",
"NAME": "Servicing engines and motors"
},
{
"ID": "23",
"NAME": "Furniture & fittings"
},
{
"ID": "31",
"NAME": "Fabrics & textiles"
},
{
"ID": "20",
"NAME": "Hand and machine tools"
},
{
"ID": "28",
"NAME": "Safety and security products"
},
{
"ID": "147",
"NAME": "Jewellery"
},
{
"ID": "156",
"NAME": "Beverages"
},
{
"ID": "165",
"NAME": "Stationery"
},
{
"ID": "9",
"NAME": "Industrial equipment"
},
{
"ID": "25",
"NAME": "Cleaning equipment"
},
{
"ID": "33",
"NAME": "Household consumer products"
},
{
"ID": "162",
"NAME": "Paper Products"
},
{
"ID": "170",
"NAME": "Memoribilia"
},
{
"ID": "143",
"NAME": "Food Products"
},
{
"ID": "22",
"NAME": "Automotive aviation marine and rail products"
},
{
"ID": "30",
"NAME": "Household appliances"
},
{
"ID": "151",
"NAME": "Iron Sheet"
},
{
"ID": "167",
"NAME": "Cosmetics"
},
{
"ID": "11",
"NAME": "Fuel Lubricants & Detergents"
},
{
"ID": "19",
"NAME": "Electrical appliances and equipment"
},
{
"ID": "27",
"NAME": "Packaging products"
},
{
"ID": "7",
"NAME": "Engines & parts"
},
{
"ID": "24",
"NAME": "Glass products"
},
{
"ID": "32",
"NAME": "Clothing & footwear"
},
{
"ID": "152",
"NAME": "Building Material"
},
{
"ID": "142",
"NAME": "Food Processing and Packaging"
},
{
"ID": "21",
"NAME": "Plastic products"
},
{
"ID": "29",
"NAME": "Pool & garden products"
},
{
"ID": "157",
"NAME": "Steel Products"
},
{
"ID": "138",
"NAME": "Optical Prescription Lenses"
},
{
"ID": "10",
"NAME": "Servicing & refurbishing"
},
{
"ID": "18",
"NAME": "Chemical"
},
{
"ID": "26",
"NAME": "Board paper and"
}
]
},
.
.
.
]
If you just want to send completionHandler anyway, use code below:
struct MyJsonStruct : Decodable {
struct SectorStruct : Decodable {
var ID : String
var NAME : String
}
var SECTOR_NAME : String
var ID : String
var SECTOR : [SectorStruct]
}
func handle(_ data : Data ) {
do {
let sectorData = try JSONDecoder().decode(MyJsonStruct.self, from: data) as MyJsonStruct
let yourArray = sectorData.SECTOR // if you need an array result
completionHandler(sectorData,(response as! HTTPURLResponse), error)
print("SectionData Received Successfully")
} catch {
completionHandler(nil,(response as! HTTPURLResponse), error)
print("Error parsing json get sector data: ", error.localizedDescription)
}
}

Getting Error:Expecting 'EOF', '}', ',', ']', got '{'

I have got json file to work on and this is the error log ,I am getting
Expecting 'EOF', '}', ',', ']', got '{'
Below is my json file
{
"_id": {
"$oid": "5b39c97045d12b6cd10fbf18"
},
"info": {
"living": {},
"work": [],
"fb_id": "100004808533368",
"contact": {},
"basic": {},
"education": [],
"user_tag": "azzamalig"
},
"liked pages": []
}
Error is coming in last line.
I am new to json and will appreciate any help on further learning about it.
As per json pasted in https://pastebin.com/zphmyVft json is wrong. Its array of items so it has to be like
[{
"_id": {
"$oid": "5b39c97045d12b6cd10fbf18"
},
"info": {
"living": {},
"work": [],
"fb_id": "100004808533368",
"contact": {},
"basic": {},
"education": [],
"user_tag": "azzamalig"
},
"liked pages": []
},
{
"_id": {
"$oid": "5b39d7c045d12b6f16b0a424"
},
"info": {
"living": {
"Current City": {
"link": "https://m.facebook.com//profile.php?id=108505579174201",
"name": "Aligarh"
},
"Home Town": {
"link": "https://m.facebook.com//profile.php?id=107966902556876",
"name": "Gaya, India"
}
},
"work": [{
"link": "https://m.facebook.com//AMU-Students-Union-119182428118156/",
"name": "AMU Student's Union"
},
{
"link": "https://m.facebook.com//profile.php?id=112824832065214",
"name": "Aligarh Muslim University"
},
{
"link": "https://m.facebook.com//profile.php?id=452244444871895",
"name": "Student"
}
],
"fb_id": "100004808533368",
"contact": {
"Facebook": " /azzamalig"
},
"basic": {
"Languages": "Urdu, English language, Hindi, Arabic and Persian language",
"Gender": "Male"
},
"education": [{
"link": "https://m.facebook.com//profile.php?id=112824832065214",
"name": "Aligarh Muslim University"
}],
"user_tag": "azzamalig"
},
"liked pages": [{
"link": "/a/subscribe.php?id=100004808533368\u0026gfid=AQDO9-GsqyZZrdIn",
"name": "Follow"
},
{
"link": "/mbasic/more/?owner_id=100004808533368",
"name": "More"
}, {
"link": "/azzamforamusu/?fref=none",
"name": "Abdullah Azzam President AMUSU 2014-15"
},
{
"link": "/profile.php?id=112824832065214\u0026fref=none",
"name": "Aligarh Muslim University"
},
{
"link": "/StudentsOfAMU/?fref=none",
"name": "\"Students of AMU\""
}, {
"link": "/WhereAmIHeading/?fref=none",
"name": "Where Am I Heading ?"
},
{
"link": "/cec.amu/?fref=none",
"name": "Cultural Education Centre - AMU"
}, {
"link": "/amulitfest/?fref=none",
"name": "AMU Literary Festival"
},
{
"link": "/amuecoclub/?fref=none",
"name": "Eco-Club Aligarh Muslim University"
}, {
"link": "/aissmd201415/?fref=none",
"name": "All India Sir Syed Memorial Debate 2014-15"
},
{
"link": "/youthkiawaaz/?fref=none",
"name": "Youth Ki Awaaz"
},
{
"link": "/page.amirudras/?fref=none",
"name": "Rudrajit Sarkar"
}, {
"link": "/sio.kochi.7/?fref=none",
"name": "Sio Kochi"
},
{
"link": "/a/subscribe.php?id=100004808533368\u0026gfid=AQDO9-GsqyZZrdIn",
"name": "Follow"
}, {
"link": "/mbasic/more/?owner_id=100004808533368",
"name": "More"
},
{
"link": "/newsclickonline/?fref=none",
"name": "NewsClick.in"
}, {
"link": "/Moez-Ahmed-246449752513372/?fref=none",
"name": "Moez Ahmed"
},
{
"link": "/ifteshid2/?fref=none",
"name": "Iftekhar Ahmad Page"
}, {
"link": "/Mukul-Sharma-Monu-627044647634256/?fref=none",
"name": "Mukul Sharma Monu"
},
{
"link": "/FurqanDawahCenterGhat/?fref=none",
"name": "Mohammad Areeb Furqani"
}, {
"link": "/ShehlaRashidOfficial/?fref=none",
"name": "Shehla Rashid"
},
{
"link": "/proamuofficial/?fref=none",
"name": "Aligarh Muslim University News"
}, {
"link": "/MrAMFs/?fref=none",
"name": "Abdullah Mohammed Faiz"
},
{
"link": "/sabrangindia.in/?fref=none",
"name": "Sabrang सबरंग"
}
]
}]
You were missing [ ] and ',' between two items.

Data structure for a family tree with multiple partners and siblings?

I have a very basic family tree structure but I need to figure out how to make it support multiple partners and siblings without as much redundancy.
The base of the entire tree is the person that's creating the tree.
Consider this very simple structure:
{
"name": "Me",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
],
"children": [
{
"name": "Tim",
"dob": "1992"
}
]
}
This works nicely but what if I discovered I had a half sibling named Judy (Genghis Khan loved the ladies) and a full sibling named Brian and expanded it to this?
{
"name": "Me",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
],
"children": [
{
"name": "Tim",
"dob": "1992"
}
],
"siblings": [
{
"name": "Judy",
"dob": "1987",
"parents": [
{
"name": "Courtney Carano",
"dob": "1965"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
]
},
{
"name": "Brian",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
]
}
]
}
This does map my 2 newfound siblings but now I have a bit of redundancy in my data, as Genghis Khan is in 3 different places. I could potentially create a one level list such as this:
[
{ "id": "1", "name": "Me", "dob": "1988", "parents": [2,3], "siblings": [4,5] },
{ "id": "2", "name": "Genghis Khan", "dob": "1961", "children": [1,4,5] },
{ "id": "3", "name": "Gina Carano", "dob": "1967", "children": [1] },
{ "id": "4", "name": "Tim", "dob": "1992", "parents" : [2,3] },
{ "id": "5", "name": "Judy", "dob": "1987", "parents": [2,6] },
{ "id": "6", "name": "Courtney Carano", "dob": "1965", "children": [5] }
]
Would this work out the same way without as much redundancy? And are there any foreseeable circumstances in which there would be any limitations in terms of mapping out multiple partners with children?
Note: I figure if I keep the initial structure, I'd have to add id keys to properly identify that Genghis Khan is the same in all 3 instances.
My end goal is mapping a pedigree tree (probably in d3.js) that is visually going to be in this manner, with a line in the middle between partners going to their children.
So with the dataset above, I'm trying to render:
Almost all genealogy systems have IDs for people, so I wouldn't worry about adding/requiring that.
The traditional way of doing this is to have a Family node type as well as a Person node type. This allows multiple marriages and also gives you a place to connect information like marriage date, marriage place, etc.
person[
{ "id": "p1", "name": "Me", "dob": "1988", "parents": "f3" },
{ "id": "p2", "name": "Genghis Khan", "dob": "1961", "parents": "f1", "spouse_families": ["f2", "f3"] },
{ "id": "p3", "name": "Gina Carano", "dob": "1967", "spouse_families" : ["f3"] },
{ "id": "p4", "name": "Brian", "dob": "1992", "parents" : "f3" },
{ "id": "p5", "name": "Judy", "dob": "1987", "parents": "f2" },
{ "id": "p6", "name": "Courtney Carano", "dob": "1965", "spouse_families": ["f2"] },
{"id": "p7", "name": "Mother of Ghengis"},
{"id": "p8", "name": "Father of Ghengis"},
]
family[
{"id":"f1","marriage date":"", "parents": ["p7", "p8"],"children":["p2"]},
{"id":"f2","marriage date":"", "parents": ["p6", "p2"],"children":["p5"]},
{"id":"f3","marriage date":"", "parents": ["p3","p2"],"children":["p1", "p4"]},
]
This gives you a place to connect all the parents and children together without redundancy and lots of special casing. (Note: I corrected "Tim" to "Brian" in the data structure to match the graphic.)

Add Facebook json feed to a MySQL db

I guess this is a big ask. Using PHP I grab this Facebook Graph API json feed json feed link
{
"data": [
{
"id": "10369058551_10150645263758552",
"from": {
"name": "Land Rover",
"category": "Cars",
"id": "10369058551"
},
"message": "This week's Land Rover photo of the week is by Rodrigo Beja. Don't forget to submit your best photos each week to get featured.",
"link": "http://www.facebook.com/photo.php?fbid=10150645263678552&set=a.443106273551.221975.10369058551&type=1",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/10369058551/posts/10150645263758552"
},
{
"name": "Like",
"link": "http://www.facebook.com/10369058551/posts/10150645263758552"
}
],
"privacy": {
"description": "United Kingdom",
"value": "CUSTOM"
},
"type": "photo",
"object_id": "10150645263678552",
"created_time": "2012-02-03T17:19:03+0000",
"updated_time": "2012-02-03T22:32:28+0000",
"likes": {
"data": [
{
"name": "Mandy Elder",
"id": "100000250758731"
}
],
"count": 85
},
"comments": {
"data": [
{
"id": "10369058551_10150645263758552_6835532",
"from": {
"name": "John Sharp",
"id": "652940638"
},
"message": "This photo was used as part of the g4 challenge publicity photo pack around 2005-6 \nI remember because at the time I used it as a profile pic on msn \n\nAwesome photo - sums it up perfectly - I love it!!",
"created_time": "2012-02-03T21:39:48+0000"
},
{
"id": "10369058551_10150645263758552_6835852",
"from": {
"name": "Kathryn Piddington",
"id": "777370532"
},
"message": "Mud is good for the soul :)",
"created_time": "2012-02-03T22:32:28+0000"
}
],
"count": 14
}
},
{
"id": "10369058551_355476307803889",
"from": {
"name": "Land Rover",
"category": "Cars",
"id": "10369058551"
},
"message": "Click below to watch the new Range Rover Sport advert and catch up on the latest Land Rover and Range Rover news in this week\u2019s round-up. ",
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQAx7xz602rfhyIn&w=90&h=90&url=http\u00253A\u00252F\u00252Fblog.landrover.com\u00252Fwp-content\u00252Fuploads\u00252F12my_rrs_044_LowRes.jpg",
"link": "http://blog.landrover.com/vehicles/the-land-rover-and-range-rover-weekly-19-3578.html#axzz1lKthI4F1",
"name": "The Land Rover and Range Rover Weekly 19 | Land Rover Blog",
"caption": "blog.landrover.com",
"description": "In this week\u2019s round-up of all things Land Rover and Range Rover, the new Range Rover Sport advert, Which? figures reveal the running costs of the Range Rover Evoque in comparison with competitors and a history of Land Rover narrated by Ranulph Fiennes.",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yD/r/aS8ecmYRys0.gif",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/10369058551/posts/355476307803889"
},
{
"name": "Like",
"link": "http://www.facebook.com/10369058551/posts/355476307803889"
}
],
"privacy": {
"description": "United Kingdom",
"value": "CUSTOM"
},
"type": "link",
"created_time": "2012-02-03T16:44:42+0000",
"updated_time": "2012-02-03T16:44:42+0000",
"likes": {
"data": [
{
"name": "Steve Nesbitt",
"id": "533982936"
}
],
"count": 10
},
"comments": {
"count": 0
}
},
{
"id": "10369058551_10150642499593552",
I'd like to the top level items to a mysql table, then each sub level to anaother table keeping a key / link between each table and then any sub level of a sublevel and linking this too. Is this possible?
I have got as far as this:-
$page = file_get_contents($url);
$json_output = json_decode($page, true);
I can't figure out how to loot hrough each row and add teh data to a Mysql table.
Thanks for your help in advance
Jonathan
Try to loop it as array then make sql query. Each array you put a unique key (for top level item). So, you can use your top level key to sub level foreign key..