youtube api search respond unexpected data - youtube-api

We are using youtube API for searching our own video files, and the search result responds with data that has no information about the query search, for example:
search: cultura
result: some videos has not cultura in the title, description or tags
API call for video list:
https://www.googleapis.com/youtube/v3/search?key=KEY&channelId=CHANNELID&part=snippet&order=date&q=cultura&maxResults=50
Response:
"items" => array:50 [▼
0 => array:4 [▼
...
"snippet" => array:8 [▼
...
"title" => "Primavera"
"description" => "Arroyo y cascada del rio Castaños en la cara norte del Eretza ([eitb.com][g1] [tiempo-naturaleza] [ bizkaia] [ galdames] [alberto-zorrilla] [1755] [tiemponaturaleza] )
...
API call for video information:
https://www.googleapis.com/youtube/v3/videos?key=KEY&channelId=CHANNELID&part=snippet%2CcontentDetails&id=ID
...
"title": "Primavera",
"description": "Arroyo y cascada del rio Castaños en la cara norte del Eretza ([eitb.com][g1] [tiempo-naturaleza] [ bizkaia] [ galdames] [alberto-zorrilla] [1755] [tiemponaturaleza] )",
...
"tags": [
"category2:tiemponaturaleza",
"category:tiempo-naturaleza",
"city:galdames",
"domain:eitb.com",
"id_user:1755",
"province:bizkaia",
"type:g1",
"username:alberto-zorrilla"
],
"categoryId": "22",
"liveBroadcastContent": "none",
"localized": {
"title": "Primavera",
"description": "Arroyo y cascada del rio Castaños en la cara norte del Eretza ([eitb.com][g1] [tiempo-naturaleza] [ bizkaia] [ galdames] [alberto-zorrilla] [1755] [tiemponaturaleza] )"
}
}
...
,
Some help will be appreciated :)

Related

How can I access value in deeply nested hash in Ruby?

Could someone help me to access "value" in this deeply nested hash:
hash = {
"data" => {},
"content" => [
{
"data" => {},
"content" => [
{
"data" => {},
"marks" => [],
"value" => "est ce que j'arrive à te choper",
"nodeType" => "text"
}
],
"nodeType" => "paragraph"
}
],
"nodeType" => "document"
}
You can get value with dig
hash.dig('content', 0, 'content', 0, 'value')
#=> "est ce que j'arrive à te choper"

Firebase - Download specific child (Swift 3)

I have attached a picture of my JSON tree
{
"-Ko4cg3ik5OFsnLTI4q4" : {
"FacebookPage" : {
"id" : "187736205061418",
"page" : "partyunlimitedtoronto"
},
"MapView" : {
"Edate" : 523940400,
"Sdate" : 523929600,
"intersted" : 3843,
"lat" : 45.510772273476,
"lng" : -73.563586483671,
"type" : "MUSIC",
"userID" : 1373802105986614,
"visibility" : "Public"
},
"address" : "Théâtre Corona",
"bio" : "evenko & Greenland Productions présentent\t\nMogwai\navec/with Xander Harris \nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 24 mars à 10h\n\n37$ à 42$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: March 24 at 10am\n\n$37 to $42\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Mogwai // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17361785_10155183713782422_6829705267219994059_n.jpg?oh=150f6f53c74233b70b7f1b372c1db1e4&oe=59CF07EE",
"site" : "http://www.evenko.ca/fr/evenements/12392/mogwai/theatre-corona/12-06-2017",
"status" : "normal"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"FacebookPage" : {
"id" : "620998508097068",
"page" : "partyunlimitedtoronto"
},
"MapView" : {
"Edate" : 43223454,
"Sdate" : 65837495,
"interested" : 2355,
"lat" : 45.3846583,
"lng" : -74.4736583,
"type" : "Party",
"userID" : 1373802105986614,
"visibility " : "Public"
},
"address" : "Théâtre Corona",
"bio" : "Greenland Productions & evenko présentent\t\t\t\t\t\t\nNazareth\t\t\t\navec/with Les Deuxluxes\t\n\nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 14 avril à midi \n\n44,50$ à 48$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: April 14 at noon\n\n$44,50 to $48\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Nazareth // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17759677_10155255160737422_1735715699829358715_n.jpg?oh=1d6d1c250c2c6b38c6ef0de4483bd0a9&oe=5A0C4879",
"site" : "http://www.evenko.ca/fr/evenements/12489/nazareth/theatre-corona/08-03-2017",
"status" : "normal"
}
}
So I'm attempting to only download the "MapView" node inside every child when I run my program but in this case, I won't know the name of the parent of "MapView". Is there any way to only download a specific child like in this case. Otherwise, I was thinking whether I should use this style of structuring.
{
"EventView" : {
"-Ko4cg3ik5OFsnLTI4q4" : {
"FacebookPage" : {
"id" : "187736205061418",
"page" : "partyunlimitedtoronto"
},
"address" : "Théâtre Corona",
"bio" : "evenko & Greenland Productions présentent\t\nMogwai\navec/with Xander Harris \nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 24 mars à 10h\n\n37$ à 42$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: March 24 at 10am\n\n$37 to $42\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Mogwai // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17361785_10155183713782422_6829705267219994059_n.jpg?oh=150f6f53c74233b70b7f1b372c1db1e4&oe=59CF07EE",
"site" : "http://www.evenko.ca/fr/evenements/12392/mogwai/theatre-corona/12-06-2017",
"status" : "normal"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"FacebookPage" : {
"id" : "620998508097068",
"page" : "partyunlimitedtoronto"
},
"address" : "Théâtre Corona",
"bio" : "Greenland Productions & evenko présentent\t\t\t\t\t\t\nNazareth\t\t\t\navec/with Les Deuxluxes\t\n\nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 14 avril à midi \n\n44,50$ à 48$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: April 14 at noon\n\n$44,50 to $48\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Nazareth // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17759677_10155255160737422_1735715699829358715_n.jpg?oh=1d6d1c250c2c6b38c6ef0de4483bd0a9&oe=5A0C4879",
"site" : "http://www.evenko.ca/fr/evenements/12489/nazareth/theatre-corona/08-03-2017",
"status" : "normal"
}
},
"MapView" : {
"-Ko4cg3ik5OFsnLTI4q4" : {
"Edate" : 534312000,
"Sdate" : 534301200,
"intersted" : 652,
"lat" : 45.4827983,
"lng" : -73.575107687761,
"type" : "MUSIC",
"userID" : "1373802105986614",
"visibility" : "Public"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"Edate" : 523508400,
"Sdate" : 523497600,
"intersted" : 382,
"lat" : 45.4827983,
"lng" : -73.575107687761,
"type" : "MUSIC",
"userID" : "1373802105986614",
"visibility" : "Public"
}
}
}
where in this case I would have the information in a separate child but where there are parent nodes with the same name in both EventView and MapView.
For the First structure
This structure will definitely make our query download the whole EventView node
var AllMapViews = []; //<-- array of all mapview objects
var path = "/EventView";
firebase.database().ref(path)
.once("value")
.then(eventViews => {
eventViews.forEach(thisevent => {
AllMapViews.push(thisevent.val().MapView);
})
});
Hence the result of the above will look like this
AllMapViews = [
{ "EventDate":343,"Sdate" : 65837495 ..},
{ "EventDate":343,"Sdate" : 65837495 ..},
{ "EventDate":343,"Sdate" : 65837495 ..},
...
]
For the Second structure (My Choice)
This structure will allow our query download only MapViews for all EventViews. Hence, making it the structure of choice in your implementation. Though it will need you to monitor the main EventView nodes often to know when the main event is deleted so that you can also delete it's corresponding MapView.
var AllMapViews = []; //<-- array of all mapview objects
var path = "/MapViews";
firebase.database().ref(path)
.once("value")
.then(mapViews => {
mapViews.forEach(map => {
AllMapViews.push(map.val());
})
});
Hence the result of the above will look like this
AllMapViews = [
{ "EventDate":343,"Sdate" : 65837495 ..},
{ "EventDate":343,"Sdate" : 65837495 ..},
{ "EventDate":343,"Sdate" : 65837495 ..},
...
]

Couchbase N1QL query running, but no data retrieved (wrong query i guess)

I am trying to retrieve data from 2 buckets, no error but nothing shows up (I do have documents I need in these buckets).
1st bucket: a_bucket
here is the document I am interested in (I do have 3 different docs)
author_ID document:
{
"author_ID": 1,
"profil_creation_date": "2017/01/01/01:23:05/+5",
"prefix": "Mr.",
"first_name": "Dylan",
"middle_name_s": "Alfred",
"last_name": "Kerr",
"date_of_birth": "1974/01/02",
"sex": "M",
"marital_status": "Single",
"mobile_phone": "(860) 231-3336",
"address": [
{
"address_1": {
"address_ID": 1,
"home_address": "338 Counts Lane",
"city": "West Hartford",
"province/state": "CT",
"postal_code": "06105"
}
},
{
"address_2": {
"address_ID": 2,
"work_address": "977 Copperhead Rd",
"city": "Newington",
"province/state": "CT",
"postal_code": "06111"
}
}
]
}
2nd bucket: b_bucket
here are the 2 docs I am interested in:
p_output_ID document:
{
"p_output_ID": 1,
"author_ID": 2,
"overall_score": 4.41,
"status": {
"r_status_first": "TRUE",
"r_status_second": "FALSE",
"r_status_third": "YES",
"y_status_second": "TRUE",
"y_status_third": "FALSE",
"g_status_third": "TRUE"
}
}
timing_ID document:
{
"timing_ID": 1,
"p_output_ID": 1,
"author_ID": 1,
"date_and_time": "2017-06-06/23:45:25.25/+5",
"time_in_seconds": 12525,
"incremental_time_in_seconds": "time_in_seconds",
"current_state_and_duration": {
"state": "RED",
"duration_in_seconds": 33333
}
}
my goal is to grab these informations in one query ():
prefix, first_name, middle_name_s, last_name (from author_ID document in a_bucket)
overall_score (from p_output_ID document in b_bucket)
date_and_time, state (from timing_ID document in b_bucket)
Here is my query:
select p2.current_state_and_duration.state, p1.overall_score, p2.date_and_time
from proc_data_bucket p1 USE KEYS "p_output_ID"
JOIN proc_data_bucket p2 ON KEYS "author_ID";
The syntax is OK, but I am getting no data
Please help me with that...
CREATE INDEX ix1 ON b_bucket(timing_ID);
SELECT p1.prefix, p1.first_name, p1.middle_name_s, p1.last_name,
p2.date_and_time,p2.state,
p3.overall_score
FROM b_bucket p2
JOIN a_bucket p1 ON KEYS ("author_" || TO_STRING(p2.author_ID))
JOIN b_bucket p3 ON KEYS ("p_output_" || TO_STRING(p2.p_output_ID))
WHERE p2.timing_ID BETWEEN 10 AND 50;

Rails merge multiple json response

Can anyone help me with this problem?
So, here is the problem, I want to merge this query response:
#energy = Alert.where(["alert_type = ?", "Energy"]).last.as_json
#cost = Alert.where(["alert_type = ?", "Cost"]).last.as_json
Then I merge those object with:
#current_notif = #energy.merge(#cost)
But those just give me #cost object like this:
{
"alert_type": "Cost",
"value": 30000000,
"status": "Cost exceeds limit",
"created_at": "2017-06-03T15:31:21.156+07:00",
"updated_at": "2017-06-03T15:31:21.156+07:00",
"home_id": 2
}
Rather than a merged #energy + #cost like this:
{ {"alert_type": "Energy",
"value": 384455.813978742,
"status": "Energy too high",
"created_at": "2017-05-31T11:31:12.907+07:00",
"updated_at": "2017-05-31T11:31:12.907+07:00",
"home_id": 2 },
{
"alert_type": "Cost",
"value": 30000000,
"status": "Cost exceeds limit",
"created_at": "2017-06-03T15:31:21.156+07:00",
"updated_at": "2017-06-03T15:31:21.156+07:00",
"home_id": 2
}
}
If you want you could "join" both values, and then over that use as_json:
[#energy, #cost].as_json
# [{"alert_type": "Energy", ... }, {"alert_type": "Cost", ... }]
Or if you want you could use the IN expression, in order to deal with ActiveRecord instead having to customize the result this gives you:
Alert.where(alert_type: ['Energy', 'Cost']).as_json
# [{"alert_type": "Energy", ... }, {"alert_type": "Cost", ... }]
This is happening because that's how merge works.
hash = {:name => "Ade", :gender => "Male"}.merge(:name => "Bob")
puts hash # {:name=>"Bob", :gender=>"Male"}
Solution:
results = [ #energy, #cost ]
results.each do |result|
puts result['alert_type'] # Energy, Cost
end

TypeError: no implicit conversion of Symbol into Integer - Ruby on Rails

I have a pretty basic question.
I tried the solution posted like this one
However it is not working for me.
My code is:
#Logic for connecting to end point and getting the response is above this line...
puts res.body
Rails.logger.debug "Response from endpoint: #{res.body}"
# Once a successful response is received, update the corresponding service table.
content = Hash.new
Rails.logger.debug "Content initial value: #{content}"
content = res.body
Rails.logger.debug "Content loaded value: #{content}"
if content[:result].length != 0
if content[:result][:hotel][:#type] == "LodgingReservation"
#More logic below this line . . .
The format of the response i.e. "res.body" is json and it looks like this
{"message": "OK", "code": 200, "id": "de97c01a-b206-11e5-8976-0a5d4c2d1469", "result": {"hotel": {"reservationFor": {"telephone": "+123456", "#type": "LodgingBusiness", "x-days": "6"}, "reservationStatus": "http://schema.org/ReservationConfirmed", "broker": {"#type": "Organization", "name": "xyz"}, "checkoutTime": "2014-04-06T12:00:00", "reservationId": "426396323", "checkinTime": "2014-03-31T15:00:00", "#context": "http://schema.org", "#type": "LodgingReservation"}}}
When I try to run the code it gives the "TypeError:" at this line -- if content[:result].length != 0
The following is output from the debugger:
Content initial value: {}
Content loaded value: {"message": "OK", "code": 200, "id": "de97c01a-b206-11e5-8976-0a5d4c2d1469", "result": {"hotel": {"reservationFor": {"telephone": "+123456", "#type": "LodgingBusiness", "x-days": "6"}, "reservationStatus": "http://schema.org/ReservationConfirmed", "broker": {"#type": "Organization", "name": "xyz"}, "checkoutTime": "2014-04-06T12:00:00", "reservationId": "426396323", "checkinTime": "2014-03-31T15:00:00", "#context": "http://schema.org", "#type": "LodgingReservation"}}}
As you can see from the output "content" is not a hash. I'm trying to figure out why?
When I run this code line by line in the rails console it is working.
>> c = Hash.new
=> {}
>> c = {"message": "OK", "code": 200, "id": "de97c01a-b206-11e5-8976-0a5d4c2d1469", "result": {"hotel": {"reservationFor": {"telephone": "+123456", "#type": "LodgingBusiness", "x-days": "6"}, "reservationStatus": "http://schema.org/ReservationConfirmed", "broker": {"#type": "Organization", "name": "xyz"}, "checkoutTime": "2014-04-06T12:00:00", "reservationId": "426396323", "checkinTime": "2014-03-31T15:00:00", "#context": "http://schema.org", "#type": "LodgingReservation"}}}
=> {:message=>"OK", :code=>200, :id=>"3048f3f4-b205-11e5-849c-0a5d4c2d1469", :result=>{:hotel=>{:reservationFor=>{:telephone=>"+123456", :#type=>"LodgingBusiness", :"x-days"=>"6", :reservationStatus=>"http://schema.org/ReservationConfirmed", :broker=>{:#type=>"Organization", :name=>"xyz"}, :checkoutTime=>"2014-04-06T12:00:00", :reservationId=>"426396323", :checkinTime=>"2014-03-31T15:00:00", :#context=>"http://schema.org", :#type=>"LodgingReservation"}}}
>> c[:result].length
=> 1
>> c[:result].length !=0
=> true
>> c[:result][:hotel][:#type]
=> "LodgingReservation"
>> c[:result][:hotel][:#type] == "LodgingReservation"
=> true
As you can it is working perfectly from the rails console. Any ideas on how I can fix this strange issue?!
The keys are being converted to strings so try
content["result"].length

Resources