Is there any option exists in the Youtube API to check whether a channel is blocked in a country. For Video, in the API there is the item value " Region Restriction" {'blocked':['IN']}. But nothing for the Channel so far. Want to check whether a channel is restricted or not using the Youtube API
The solution can be found on the JSON of the video in question. To find the countries where the video is unavailable, it searches for the term "regionRestriction" in the JSON of the video. Here is the code I built which allows you to display the countries (with Python):
import requests,json
api_key = 'tap_your_api_code'
url = f"https://www.googleapis.com/youtube/v3/videos?id=mCChxHZXacA&part=contentDetails&key={api_key}"
dictio_data = json.loads(requests.get(url).text)
contentDetails_json = dictio_data["items"][0]["contentDetails"]["regionRestriction"]["blocked"]
print(contentDetails_json)
Result:
['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BM', 'BN', 'BO', 'BR', 'BS', 'BT', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY', 'SZ', 'TC', 'TD', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW']
Related
I have a simple_form with a phone number. I'm using Intl-Tel-Input to get the entire phone_number and confirm SMS in different countries (twilio). In console.log, I succeed to display the entire number. When I submit, I just get the phone_number without the country indicator (dial_code)
I read the doc, tried to get it by other way (.value, .data, etc...), but impossible to save the entire phone_number (for example, +33612345678, I just get 61234567).
Here's my code :
<div class="userphonenumber">
<%= f.input :phone_number, label: 'N° de téléphone', required: true, autofocus: true ,
input_html: { autocomplete: "intlNumber" }, wrapper_html: { id: 'userphonenumber' }%>
</div>
<script>
$("#user_phone_number").intlTelInput({
formatOnInit: true,
separateDialCode: true,
onlyCountries: ['fr', 'at', 'be', 'bg', 'cz', 'dk', 'de', 'ee', 'ie', 'el', 'es', 'hr', 'it', 'cy', 'lv', 'lt', 'lu', 'hu', 'mt', 'nl', 'pl', 'pt', 'ro', 'si', 'sk', 'fi', 'se', 'uk'],
initialCountry: "fr"
});
const flag = document.querySelector(".flag-container")
flag.addEventListener("click", () => {
var intlNumber = $("#user_phone_number").intlTelInput("getNumber");
console.log("intlNumber", intlNumber)
var input = document.querySelector("#user_phone_number");
window.intlTelInput(input);
});
</script>
I'm expecting to get +33612345678 to use the phone_number with twilio. Beginner on RoR and JS. Did I miss something ?
Thanks for your help.
Finally fix with this solution :
<script>
$("#user_phone_number").intlTelInput({
formatOnInit: true,
separateDialCode: true,
onlyCountries: ['at', 'be', 'bg', 'cz', 'dk', 'de', 'ee', 'ie', 'el', 'es', 'fr', 'hr', 'it', 'cy', 'lv', 'lt', 'lu', 'hu', 'mt', 'nl', 'pl', 'pt', 'ro', 'si', 'sk', 'fi', 'se', 'uk'],
initialCountry: "fr",
});
var phone = document.getElementById('user_phone_number')
phone.addEventListener('keyup', (event) => {
console.log(event)
});
$("form").submit(function() {
$('#user_phone_number').val($(phone).intlTelInput("getNumber"));
});
</script>
$(".form").submit( function(eventObj) {
$("<input />").attr("type", "hidden")
.attr("name", "ccode")
.attr("value", $(this).find(".selected-dial-code").text())
.appendTo(".form");
return true;
});
I have some code which is written in mysql (i think) to return valid postcodes, and I am trying to convert the code to Firebird SQL but I am getting errors. Stopping at the CASE part at the minute. What I want to happen eventually is for it to delete all non-valid postcodes. So if you know an another solution that would be of great help:
SET TERM ^ ;
CREATE PROCEDURE ValidatePostCode ( PostCode VARCHAR(8) )
RETURNS ( ValidPC CHAR(1) )
AS
BEGIN
RETURN CASE
-- Special case GIR 0AA
WHEN PostCode LIKE 'GIR 0AA' THEN i=1
-- Current postcode prefixes
WHEN LEFT(Postcode, 2) NOT IN ('AB', 'AL', 'BA', 'BB', 'BD', 'BH', 'BL', 'BN', 'BR', 'BS', 'BT', 'CA', 'CB', 'CF', 'CH', 'CM', 'CO', 'CR', 'CT', 'CV', 'CW', 'DA', 'DD', 'DE', 'DG', 'DH', 'DL', 'DN', 'DT', 'DY', 'EC', 'EH', 'EN', 'EX', 'FK', 'FY', 'GL', 'GU', 'GY', 'HA', 'HD', 'HG', 'HP', 'HR', 'HS', 'HU', 'HX', 'IG', 'IM', 'IP', 'IV', 'JE', 'KA', 'KT', 'KW', 'KY', 'L', 'LA', 'LD', 'LE', 'LL', 'LN', 'LS', 'LU', 'ME', 'MK', 'ML', 'NE', 'NG', 'NN', 'NP', 'NR', 'NW', 'OL', 'OX', 'PA', 'PE', 'PH', 'PL', 'PO', 'PR', 'RG', 'RH', 'RM', 'SA', 'SE', 'SG', 'SK', 'SL', 'SM', 'SN', 'SO', 'SP', 'SR', 'SS', 'ST', 'SW', 'SY', 'TA', 'TD', 'TF', 'TN', 'TQ', 'TR', 'TS', 'TW', 'UB', 'WA', 'WC', 'WD', 'WF', 'WN', 'WR', 'WS', 'WV', 'YO', 'ZE')
OR WHEN LEFT(Postcode, 1) NOT IN ('B', 'E', 'G', 'L', 'N', 'S', 'W') THEN 0
-- AANN NAA
WHEN PostCode LIKE '[ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY][0123456789][0123456789] [0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]' THEN 1
-- AANA NAA
WHEN PostCode LIKE '[ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY][0123456789][ABEHMNPRVWXY] [0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]' THEN 1
-- ANN NAA
WHEN PostCode LIKE '[ABCDEFGHIJKLMNOPRSTUWYZ][0123456789][0123456789] [0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]' THEN 1
-- AAN NAA
WHEN PostCode LIKE '[ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY][0123456789] [0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]' THEN 1
-- ANA NAA
WHEN PostCode LIKE '[ABCDEFGHIJKLMNOPRSTUWYZ][0123456789][ABCDEFGHJKSTUW] [0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]' THEN 1
-- AN NAA
WHEN PostCode LIKE '[ABCDEFGHIJKLMNOPRSTUWYZ][0123456789] [0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]' THEN 1
-- Not a valid postcode
ELSE 0
END
END^
SET TERM ; ^
I ended up doing the following thanks to useful comment:
select postcode from CUSTOMER_ADDRESSES
where LEFT(postcode, 2) NOT IN ('AB', 'AL', 'BA', 'BB', 'BD', 'BH', 'BL', 'BN', 'BR', 'BS', 'BT', 'CA', 'CB', 'CF', 'CH', 'CM', 'CO', 'CR', 'CT', 'CV', 'CW', 'DA', 'DD', 'DE', 'DG', 'DH', 'DL', 'DN', 'DT', 'DY', 'EC', 'EH', 'EN', 'EX', 'FK', 'FY', 'GL', 'GU', 'GY', 'HA', 'HD', 'HG', 'HP', 'HR', 'HS', 'HU', 'HX', 'IG', 'IM', 'IP', 'IV', 'JE', 'KA', 'KT', 'KW', 'KY', 'L', 'LA', 'LD', 'LE', 'LL', 'LN', 'LS', 'LU', 'ME', 'MK', 'ML', 'NE', 'NG', 'NN', 'NP', 'NR', 'NW', 'OL', 'OX', 'PA', 'PE', 'PH', 'PL', 'PO', 'PR', 'RG', 'RH', 'RM', 'SA', 'SE', 'SG', 'SK', 'SL', 'SM', 'SN', 'SO', 'SP', 'SR', 'SS', 'ST', 'SW', 'SY', 'TA', 'TD', 'TF', 'TN', 'TQ', 'TR', 'TS', 'TW', 'UB', 'WA', 'WC', 'WD', 'WF', 'WN', 'WR', 'WS', 'WV', 'YO', 'ZE') OR LEFT(postcode, 1) NOT IN ('B', 'E', 'G', 'L', 'N', 'S', 'W')
and postcode not SIMILAR TO '[ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY][0123456789][0123456789][0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]'
and postcode not SIMILAR TO '[ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY][0123456789][ABEHMNPRVWXY][0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]'
and postcode not SIMILAR TO '[ABCDEFGHIJKLMNOPRSTUWYZ][0123456789][0123456789][0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]'
and postcode not SIMILAR TO '[ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY][0123456789][0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]'
and postcode not SIMILAR TO '[ABCDEFGHIJKLMNOPRSTUWYZ][0123456789][ABCDEFGHJKSTUW][0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]'
and postcode not SIMILAR TO '[ABCDEFGHIJKLMNOPRSTUWYZ][0123456789][0123456789][ABDEFGHJLNPQRSTUWXYZ][ABDEFGHJLNPQRSTUWXYZ]'
Before doing this however I removed all the spaces as they were not needed. If they were needed I would have put a space in the similar to string. Here is the code I used to remove the spaces:
update CUSTOMER_ADDRESSES set POSTCODE = replace(POSTCODE, ' ', '');
I am trying to add twitter's typeahead plugin to my rails application. I have downloaded the typeahead.bundle.js and placed it in vendor/assets/javascripts directory. And I have added //= require typeahead.bundle to app/assets/javascripts/application.js. Then I put the first example given there
<div id="the-basics">
<input class="typeahead" type="text" placeholder="States of USA">
</div>
on one of my views and the following javascript on
app/assets/javascripts/example.js
but nothing happens when i try to type characters, not even on the logs. Thanks for your help
var substringMatcher = function(strs) {
return function findMatches(q, cb) {
var matches, substrRegex;
matches = [];
substrRegex = new RegExp(q, 'i');
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
matches.push({ value: str });
}
});
cb(matches);
};
};
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];
$('#the-basics .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
displayKey: 'value',
source: substringMatcher(states)
});
I want to tag location string in text using NLTK and also in Stanford-NLP
and am looking for dictionary lookup tagger for NLTK/Stanford-NLP, for so far I haven't found anything with Dictionary-lookup method.
One way is to use RegexpTagger(NLTK) and supply every location strings in there, but it might slow.
I don't need to do any semantic analysis, other than to tag the locations based on my location-dictionary.
Ideas ?
You could use UnigramTagger:
#!/usr/bin/env python2
from nltk.tag.sequential import UnigramTagger
from nltk.tokenize import word_tokenize, sent_tokenize
text = 'I visited Paris and Bordeaux. Not Los Angeles'
locations = [[('Paris', 'LOC'), ('Bordeaux', 'LOC'), ('France', 'LOC'),
('Los Angeles', 'LOC')]]
location_tagger = UnigramTagger(locations)
for sentence in sent_tokenize(text):
tokens = word_tokenize(sentence)
print(location_tagger.tag(tokens))
Prints:
[('I', None), ('visited', None), ('Paris', 'LOC'), ('and', None),
('Bordeaux', 'LOC'), (',', None), ('but', None), ('not', None),
('Los', None), ('Angeles', None)]
You will need a better tokenizer if you want to tag multi-word locations like Los Angeles.
If all you need is to look up from dictionaries, then htql.RegEx() may be a good fit. Here is the example from http://htql.net:
import htql;
address = '88-21 64th st , Rego Park , New York 11374'
states=['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut',
'Delaware', 'District Of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana',
'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan',
'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma',
'Oregon', 'PALAU', 'Pennsylvania', 'PUERTO RICO', 'Rhode Island', 'South Carolina', 'South Dakota',
'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin',
'Wyoming'];
a=htql.RegEx();
a.setNameSet('states', states);
state_zip1=a.reSearchStr(address, "&[s:states][,\s]+\d{5}", case=False)[0];
# state_zip1 = 'New York 11374'
state_zip2=a.reSearchList(address.split(), r"&[ws:states]<,>?<\d{5}>", case=False)[0];
# state_zip2 = ['New', 'York', '11374']
You can use parameter: useindex=True to return matching positions.
this is what I'm testing:
model
scope :user_pending, lambda { |user|
where("jobs.available = 0 AND jobs.user_id = ?", user.id) }
test
it "should have the scope" do
Job.should respond_to(:user_pending)
end
it "should return a list of jobs that are unavailable for the current_user" do
#user = Factory(:user, :id => 1)
#job = Factory(:job, :available => false, :user_id => #user)
Job.user_pending(#user).should == #job
end
the first test is passing, but I can't pass on second. The following error message is returning:
Failures:
1) Job Job :user_pending should return a list of jobs that are unavailable for the current_user
Failure/Error: Job.user_pending(#user).should == #job
expected: #<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para contato#test.com", locked: false, visits: 0>,
got: [#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para contato#test.com", locked: false, visits: 0>] (using ==)
Diff:
## -1,2 +1,2 ##
-#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para contato#test.com", locked: false, visits: 0>
+[#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para contato#test.com", locked: false, visits: 0>]
# ./spec/models/job_spec.rb:91:in `block (3 levels) in <top (required)>'
what I missing? it's look all okay, right? I can't understand whats wrong there.
It appears that your scope is returning an array (which is what I would expect). Your test should probably look like:
Job.user_pending(#user).first.should == #job