The specific information that I want to get is the list of videos that were most viewed in South Korea on Apr 1st, 2020. It would be awesome I can also get the statistics of each videos(such as the number of view counts, likes, dislikes, and comments)
I tried some coding with python using youtube API, but the results seem very different from what I expected. (The title of some videos in the results are written in Arabic or Russian even though their regioncode is KR, I have no idea what's happening.) The followings are my code. Any comments would help. Thx!!
api_key=" "
from apiclient.discovery import build
youtube = build('youtube','v3',developerKey=api_key)
from datetime import datetime
start_time = datetime(year=2020, month=4, day=1).strftime('%Y-%m-%dT%H:%M:%SZ')
end_time = datetime(year=2020, month=4, day=2).strftime('%Y-%m-%dT%H:%M:%SZ')
res = youtube.search().list(part='snippet',
maxResults='50',
regionCode='KR',
order='viewCount',
type='video',
publishedAfter=start_time,
publishedBefore=end_time
).execute()
for item in res['items']:
print(item['snippet']['title'], item['snippet']['publishedAt'])
res
The Search.list endpoint's doc says that:
regionCode string
The regionCode parameter instructs the API to return search results for videos that can be viewed in the specified country. The parameter value is an ISO 3166-1 alpha-2 country code.
This means that filtering a search result set by the regionCode being KR produces a list of videos that are allowed to be viewed in the KR region, regardless of the respective videos being actually viewed from within that region or not.
Related
I am trying to get the number of views of every video in the channel but measured from the release date for 90 days. I would like something like this:
ID, Release date, 0, 1, 2, 3, 4, ...... 90
Video1, 2020-04-03, 100, 40, 20, 10, ....., 0
Video2, 2020-06-03, 100, 40, 20, 10, ....., 0
...
Is there a way to achive this?
You can achieve this by using a combination of YouTube Data API and YouTube Analytics API requests.
Firstly, query the Data API to retrieve all videos of a channel from the search endpoint.
Set the query parameters to:
part:snippet
channelId:CHANNEL_ID
You will get a list of videos with their details as a response, among others the videoId and publishedAt values. This is what you will need for the second query.
Secondly, query the Analytics API to retrieve view stats of the videos as a video report (differs for content owners and just channel owners).
Set the query parameters to:
dimensions:video,day
filters:video==comma separated list of video ids
metric:views
startDate:earliest published date of all videos
endDate:latest published date of all videos + 90
ids:refer to docs for your owner type
The scope you need for this query is:
yt-analytics.readonly
This query will return views for each video aggregated by day for the date span you provided. After you get the response, you can filter out just the first 90 days for each video.
Alternatively, you can write a separate query for each video with the specified start date and end date, getting a result that does not need to be filtered.
Using the Advanced Tab in YouTube Studio > Analytics you can download your statistics as a CVS-File or open in Google Tables.
That's the quickest way possible.
Hope it helps :)
Now,I am integrating my amazon Lex chat bot to my web. I got the time zone issue. Time zone is in US East (N. Virginia). So if I say today, that is based on Virginia time. So I find how to change time zone and the suggestion is to set the x-amz-lex:time-zone request attribute to my region. but I donot know how to do and where to do. PLs help me!! Thanks.
I used simple Template "https://s3.amazonaws.com/aws-bigdata-blog/artifacts/aws-lex-web-ui/artifacts/templates/master.yaml".
I copied the codes from SnippetUrl and paste to my web page. The Chat Bot appear. So how should I pass these request attribute.
this this my chat bot in amazon lex
this is my cloud formation
These codes are from SnippetUrl in CodeBuildDeploy
There may be an option in the template you are using but I can't find it, so here is what you need to know about setting timezones in Lex.
First of all, the only way to change the timezone from the default East US is to use PostContent API or PostText API. They should really have a timezone setting in the Lex Console so you can set the default timezone at least, but they don't.
The correct way:
The AWS SDK is needed to use PostContent API or PostText API to pass the user's input to your Lex chat bot. When passing data to Lex this way, you can include requestAttributes with the user's input, unique ID and session attributes (optional). Here's an example of how you would set the timezone in requestAttributes to Singapore Time:
{
"inputText": "What the user said.",
"requestAttributes": {
"x-amz-lex:time-zone" : "Singapore"
},
"sessionAttributes": null
}
The workaround:
If you cannot use or cannot access the use of PostContent or PostText, then you need to work with what you have. Right now, it looks like you are only using a Lambda function for fulfillment, but you should really also use it for "initialization and validation" too.
This will pass a request to your Lambda function every time Lex processes an input and you can direct Lex with exactly how to reply. This gives you much greater control of your chat bot.
To understand the format of the Request (sometimes called "Event") and how to format the Response in that Lambda function, you will want to read these docs.
Now, Lex processes the date and time from the user's input...(In your example, the user says "today")...and Lex will fill the date or time slots with something like (date) 2018-11-02 (time) 13:00 which will be appropriate for Eastern Standard Time (UTC -5). But Singapore is UTC +8. So you will need to convert that date and time in your Lambda function and overwrite the slots to the equivalent Singaporean time then pass those slots back in your Lambda's response to Lex.
There are multiple ways to do that conversion depending on whether your Lambda is in Node.js or Python and plenty of answers and guides on timezone conversion.
Example:
User Input: "I want to book a meeting room from 1pm to 2pm for today"
To capture the values of this input, your Intent should be set up with something like:
3 slots: {date} {time_start} {time_end}
Intent Utterance: "I want to book a meeting room from {time_start} to {time_end} for {date}"
Lex will then parse the input and fill the slots (using timezone default: East US). Then Lex will pass the request to your "initialization and validation" Lambda Function. The request (or "event") will include:
{
"currentIntent": {
"name": "BookRoom",
"slots": {
"date": "2018-11-05",
"time_start": "13:00",
"time_end": "14:00",
},
},
...
}
Then in the Lambda Function you can take those values (Node.js):
var date = event['currentIntent']['slots']['date'];
var time_start = event['currentIntent']['slots']['time_start'];
var time_end = event['currentIntent']['slots']['time_end'];
Now for your conversion logic:
Since Singapore is 13 hours ahead of East US, just take those times and add 13 hours to them. If when doing that, it passes midnight, then also increase the date by 1 day.
This will work for inputs of "today", "tomorrow", "next tuesday", or even "25 Jan 2035", because Lex parses all of those the same way and simply delivers them to your Lambda in default East US time formatted as (date) yyyy-mm-dd and (time) hh:mm.
After you convert them, just set those slots as the new date and times, then pass the slots back to Lex in your response. Lex will then hold the slot values in Singapore time.
This is the solution image
Finally, I got the solution. If someone want to know the solution check in the photo. I just try to fix the codes from aws github. Thanks.
Executing my code (using the Google Adwords Library to build an oauth user etc) works when using a query with Month as a segment
String query = "SELECT EffectiveFinalUrl, Cost, Clicks, Impressions,
Month FROM FINAL_URL_REPORT";
But it aggregates across all time, split into months. I am trying to pull in the data as daily aggregates. The documentation has both Month and Date (splitting data into yyyy-MM-dd) as a segment you can include in the query, but Date does not work.
String query = "SELECT EffectiveFinalUrl, Cost, Clicks, Impressions,
Date FROM FINAL_URL_REPORT";
Results in Error 400: Bad Request.
Am I missing something in the documentation that tells me how to resolve this?
Adwords Final_URL_Report Documentation
Try set a date range by adding something like DURING ... to your query.
Is there a way to return a series of records in OData by specifying a "Date greater than xxxxx" filter...but using a Date that was previously obtained form an OData feed?
Use Case: Pretend that I want to build a web page that displays a list of the most recently completed online orders. This is what I'm aiming for:
Load the page
Hit my OData service asynchronously, returning the last 100 orders (ordering by date descending so that the most recently completed order shows up first)
Build the HTML on the page using the OData data
Store the MAX date into a global variable (looks like this: /Date(1338336000000)/)
Hit the OData service on a 30 second interval but this time specify a filter to only return records where the order date is greater than the previous MAX Date. In this case: /Date(1338336000000)/
If any records are returned, build the HTML for those records and prepend the items to the previously loaded items.
Where I am struggling is in specifying the Date "greater than" filter. For some reason, the date filters in OData do not seem to play very nice with OData's own native date format. Do I need to convert the date originally obtained into a different format that can be used for filtering?
I want to do something like this:
http://mydomain/Services/v001.svc/Orders?$filter=close_dt%20gt%201338336000000
FYI: I'm using V2
Figured this out.
OData V2 out-of-the-box returns dates out of SQL in JSON Date format like so:
/Date(1338282808000)/
However, in order to use a date as a filter within an OData call, your date has to be in EDM format, looking like this:
2012-05-29T09:13:28
So, I needed to get the date from my initial OData call, then convert it to the EDM format for use in my subsequent OData calls, which look like this:
/Services/v001.svc/Orders?$filter=close_dt gt DateTime'2012-05-29T09:13:28'
I ended up creating a javascript function that does the formatting switcharoo:
function convertJSONDate(jsonDate, returnFormat) {
var myDate = new Date(jsonDate.match(/\d+/)[0] * 1);
myDate.add(4).hours(); //using {date.format.js} to add time to compensate for timezone offset
return myDate.format(returnFormat); //using {date.format.js} plugin to format :: EDM FORMAT='yyyy-MM-ddTHH:mm:ss'
}
A couple of notes:
The JSON format does not seem to adjust for timezone, so the date returned does not match the date I see in my database. So I had to add time manually to compensate (someone please explain this).
I am using the date.format.js plugin which you can download here for formatting the date and adding time.
In OData V4 date filtering format has changed to $filter=close_dt gt 2006-12-30T23:59:59.99Z
For example
http://services.odata.org/V4/OData/OData.svc/Products?$filter=ReleaseDate%20gt%202006-12-30T23:59:59.99Z
For previous versions of OData see previous answers
If you use the datetime logic, you can do lt or gt.
e.g.
...mydomain/Services/v001.svc/Orders?$filter=close_dt gt datetime'20141231'
Just an FYI: in V3 of the protocol the non-tick-based datetime format is now the default:
http://services.odata.org/Experimental/OData/OData.svc/Products%280%29?$format=application/json;odata=verbose&$select=ReleaseDate
..."ReleaseDate":"1992-01-01T00:00:00"...
I will just try to make the answer of #avitenberg more clear:
var date= DateTime.Now;
//Convert time to UTC format
$"filter={close_dt} gt {date:yyyy-MM-ddTHH:mm:ss.FFFZ}";
See Microsoft:
I'm trying to write a small javascript code to query data filtered by date.
If I write the following sentence in my browser, I can get data :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883"
but if I write the same thing, except I want only data after a certain date :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883 WHERE Date > 2/29/12"
From the SQL-like API, https://developers.google.com/fusiontables/docs/developers_reference#Select, it should work
I get an error witch is "'internal_error', message:'Could not parse query'"
-Date is a DATETIME format in my fusion table.
-I've tried different format, but I can not get data.
What am I doing wrong?
Thank you very much for your help.
The Date value must be quoted and the format is MM/dd/yy so you must pad single digits with leading zeros.
I had success with:
select Date,Poids from 3049883 where Date >= '02/29/12'
Note: I did not test with gvizdata, just with the FT JSONP API