Using Microsoft Custom Translator Category ID in the Translate Text API - microsoft-translator

I have got the Category ID from the Microsoft Custom Translator after training the Translator. Now I don't know the script that needs to be inserted in my Translator Text API that I already have.
the sample code pasted here. I have just entered the category ID below as shown, however, not sure what is the right script to enable it.
Code sample:
# Replace the SUBSCRIPTION_KEY string value with your valid subscription key.
`SUBSCRIPTION_KEY = 'xxxx' #Place your subscription key here
HOST = 'api.cognitive.microsofttranslator.com'
PATH = '/translate?api-version=3.0'
`
# Replace the CATEGORY string value with your valid ID that you obtain from the Microsoft Custom Translator
`CATEGORY = 'xxxx'`
# Translation from to parameter
`PARAMS = "&from=en&to=de"`

You can pass the category to the PARAMS like below:
PARAMS = "&from=en&to=de&category=" + CATEGORY

Related

(Microsoft Dynamics Online) Get Account GUID inside embedded Web Resource

I'm trying to access entities (Contacts) in a HTML WebResource inside an Account formular in Microsoft Dynamics. However I cannot figure out how to get the record GUID (accountId) from the PageContext. It tells me the entityId is undefined.
I'm trying to replace this deprechated code line:
const accountId = parent.Xrm.Page.data.entity.getId();
I've been trying to use
const pageContext = window.parent.Xrm.Utility.getPageContext();
but the attributes are almost all null or undefined including the entityId. All it tells me is that I'm in an account record. See image. https://imgur.com/a/oeA1SOz
Thanks for any help
Yes is possible, you were close in your second attempt.
This will return the id:
var id = parent.Xrm.Utility.getPageContext().input.entityId.replace("{", '').replace("}", '');
From Microsoft docs:
Pass parameters to HTML web resources

How do I use a google apps script to auto fill a google form with info taken from the user? [duplicate]

With the recent study-from-home dynamics hastly implemented by budget schools, I am now facing a mindless-robot-like-task of filling in attendance for my kids everyday multiple times per child. The school shared this form:
I, being a developer, want to create a UI and have my kids submit thier attendance to this form on thier own when the teacher asks for one over Zoom. Ids it possible? I'm a .Net developer and have not developed anything for Office 365 Online and have no idea where to start looking for Google.
It is possible by reconstructing the form URL with pre-filled values.
In the Google Form, each question is named internally with "entry.". For each of the question, you need to find the entry number and assign them the right values and add it to the URL parameters like in the below image:
(Edited Oct 2021: The ids are no longer found in the name attribute of each input field in the HTML as shown in the image. They are now located in a div within the form element. #hdrz's answer below to look in the Javascript present just at the end of the body tag is now also defunct.)
I've recreated your form here https://docs.google.com/forms/d/e/1FAIpQLSfrGn49hcbeioNNa25Osp4fwTG2xV3BmmN9-cMWWC2-xvcQyg/viewform
And here is the reconstructed URL with prefill values
https://docs.google.com/forms/d/e/1FAIpQLSfrGn49hcbeioNNa25Osp4fwTG2xV3BmmN9-cMWWC2-xvcQyg/viewform?entry.1475351979=Julia&entry.280503419=Andrews&entry.519373518=4&entry.301819105=E
Hope it helps
As #AHunt writes, the entry number used to be in a name attribute on the form fields. As of this answer time, I can no longer find the name attribute on any of the form fields. However, now there is a script tag at the end of the body tag, with a short javascript code, and in it you can find the entry numbers, see here:
Also, it is possible to submit the form directly with pre-filled values. Just replace viewform in the URL with formResponse.
Similar URL as in the accepted answer, but now it will be submitted at once. Note that all required fields have to be filled!
https://docs.google.com/forms/d/e/1FAIpQLSfrGn49hcbeioNNa25Osp4fwTG2xV3BmmN9-cMWWC2-xvcQyg/formResponse?entry.1475351979=Julia&entry.280503419=Andrews&entry.519373518=4&entry.301819105=E&entry.1124370742=Art
I think I may be late but still give you a solution. I had made similar script to send my school attendance.
Every field in Google Forms is associated with a entry.<id>. You have two ways to automate the form.
One way is to extract those IDs with and make a dictionary where entry.<id> is the key and your answer is the value.Then you have to send a POST request to the form URL with the dictionary as the data. You have automated the form.
To extract the IDs, inspect the html code and look at the <script> at the (very) end of the page. It lòoks something like this :
var FB_PUBLIC_LOAD_DATA_ = [null,[null,[[2030831236,"First Name (in English)",null,0,[[1475351979,null,1]
]
]
,[86681139,"Last Name (in English)",null,0,[[280503419,null,1]
]
]
,[836880978,"Grade",null,2,[[519373518,[["KG 1",null,null,null,0]
,["KG 2",null,null,null,0]
,["1",null,null,null,0]
,["2",null,null,null,0]
,["3",null,null,null,0]
,["4",null,null,null,0]
,["5",null,null,null,0]
,["6",null,null,null,0]
,["7",null,null,null,0]
,["8",null,null,null,0]
,["9",null,null,null,0]
,["10",null,null,null,0]
,["11",null,null,null,0]
,["12",null,null,null,0]
]
,1,null,null,null,null,null,0]
]
]
,[221348070,"Section",null,2,[[301819105,[["A",null,null,null,0]
,["B",null,null,null,0]
,["C",null,null,null,0]
,["D",null,null,null,0]
,["E",null,null,null,0]
,["G",null,null,null,0]
]
,1,null,null,null,null,null,0]
]
]
,[366027193,"Subject",null,2,[[1124370742,[["Math",null,null,null,0]
,["Science",null,null,null,0]
,["English",null,null,null,0]
,["Arabic",null,null,null,0]
,["Islamic",null,null,null,0]
,["Social",null,null,null,0]
,["Moral",null,null,null,0]
,["Art",null,null,null,0]
,["Computer",null,null,null,0]
,["French",null,null,null,0]
,["Physics",null,null,null,0]
,["Chemistry",null,null,null,0]
,["Biology",null,null,null,0]
,["Business",null,null,null,0]
]
,1,null,null,null,null,null,0]
]
]
]
,null,null,[null,null,null,null,null,[null,null,null,[3,169,244,null,1]
,[217,242,253,null,1]
]
]
,null,null,null,"Attendance Form",48,null,null,null,null,null,[2]
]
As you can see there are two numbers with each field. One of them is the ID and another one I don't know. The second number is the ID we need. Using RegEx we can extract all the numbers and collect every second number in a list. This list will contain all the IDs.
Another way, as stated by others, is to reconstruct the URL with prefilled values. But in this too you have to extract the IDs.
I have included both of them in one and made this script :
import requests
from bs4 import BeautifulSoup
import re
def get_questions(url):
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
content = soup.body.find_all(text = re.compile('var FB'))
match = re.findall('[,]["][\w\s]+["][,]', str(content))
#It will match all the questions in the form
question_strings = [x.strip('"') for x in match]
match_ids = re.findall('(?<=\[\[)(\d+)', str(content))
#It will find all the numbers in the content
question_ids = ['entry.' + x for x in match_ids[1:]]
#It will leave the first numbers (they are not the ids)
return question_ids
# Below are only for when you want to know the form fills with their corresponding entry ids
# questions = dict(zip(question_strings, question_ids))
# return questions
def send_answers(url, fname, lname, grade, section, subject): #arrange this as per your form requirements
ids = get_questions(url)
answers = [fname, lname, grade, section, subject]
response = dict(zip(ids, answers))
if 'viewform' in url:
s = url.index('viewform')
response_url = url.replace(url[s::], 'formResponse?')
try:
r = requests.post(response_url, response)
if r.status_code == 200:
return '[!] Attendence posted !'
#In case an error happens, it will raise an exception
else:
raise Exception
#After raising the exception it will retry to submit using url reconstruction with prefilled values
except:
try:
ans_list = [x + '=' + y for x, y in zip(ids, answers)]
for i in range(0, len(ans_list)):
response_url += ans_list[i]
response_url += '&'
response_url.strip("&")
r = requests.get(response_url)
status = r.status_code
if status == 200:
return '[!] Attendance sent !'
else:
raise Exception
#If still an error happens, it will print out a message.
except:
return '[!] Attendance not sent !'
url = 'Form URL here'
fname = 'Your first name here'
lname = 'Your last name here'
grade = 'Your grade here'
section = 'Section here'
subject = 'Enter subject'
print(send_answers(url, fname, lname, grade, section, subject))
Hope it helps. Sorry for my bad English.
As a Google Form editor you can get a pre-filled URL (complete with entry values) by choosing the 'Get pre-filled link' option at the top right of the page, after clicking the three dots.
This will open the form in a new tab. The Submit (or Next) button will be replaced with a 'Get link' button.
After filling in the desired form responses, clicking 'Get link' will open a preview of what users will see. If everything is correct, clicking the 'COPY LINK' button (at the bottom left of page) will provide the URL.
The URL will look like this:
https://docs.google.com/forms/d/e/yourFormidhere/viewform?usp=pp_url&entry.1890935147=exampleprefilledvalue1&entry.1928475566=exampleprefilledvalue2&entry.2145528193=exampleprefilledvalue3
You can find the IDs in the console development section of Chrome.
Fill the form open networks tabs.
You can find the ID of each query in the form.
Easiest way is to simply launch Developer Tools (F12 or Ctrl+Shift+I usually) and go to the Network tab. Enable "Preserve log". Then just submit your form as usual, with the values you want (or test values).
In the Network tab, type "formResponse" in the filter bar. Find the latest entry and select it. Then go to Payload tab and click "view source". You should see something like this.
The text you see in the form data is simply what your append to the link of your form plus a '?' (question mark). So in this case our link will be https://docs.google.com/forms/d/e/1FAIpQLSfrGn49hcbeioNNa25Osp4fwTG2xV3BmmN9-cMWWC2-xvcQyg/viewform?entry.1475351979=test&entry.280503419=test&entry.519373518=KG+1&entry.1124370742=French&entry.301819105=A&dlut=1662432187937&hud=true&entry.519373518_sentinel=&entry.301819105_sentinel=&entry.1124370742_sentinel=&fvv=1&partialResponse=%5Bnull%2Cnull%2C%22-6523749705829110087%22%5D&pageHistory=0&fbzx=-6523749705829110087.
Now let's just remove the extra parameters that aren't answers. Find the last answer you input and remove the rest. Our new link will be https://docs.google.com/forms/d/e/1FAIpQLSfrGn49hcbeioNNa25Osp4fwTG2xV3BmmN9-cMWWC2-xvcQyg/viewform?entry.1475351979=test&entry.280503419=test&entry.519373518=KG+1&entry.1124370742=French&entry.301819105=A
This will open the form page with pre-filled values. If you actually want to submit the response right away, replace "viewform" with "formResponse".
The google form I tried is from #AHunt's answer, so thank you for that sample google form.

Google Drive API: find a file by name using wildcards?

When using the Google Drive API v3, can one search for a file by its name using wildcards or regular expressions? The docs don't mention anything.
I am trying to match a set of files whose names have the format
backup_YYYY-MM-DD-XXXX_NameOfWebsite_xxxxxxxxxx.zip
And am wondering what's the best way to construct a pattern that might match it. Of course, I could follow the docs and just do something like:
q="name contains 'backup' and name contains 'NameOfWebsite'"
But if I need to match a different pattern, or something with more than 2 distinctive strings in its filename ("backup_" and "NameOfWebsite"), you can quickly see what a pain would be to construct a query in that way:
q="name contains 'string1' and name contains 'string2' and name contains...
Answer:
You can't use a wildcard in the middle of a file name when making a Drive.list request with a q parameter.
More Information:
The name field only takes three operators - =, != and contains:
The = operator is regular equivalence and with this you can not use a wildcard.
name = 'backup*' will return no results.
The != operator is not equivalence, not relevant here but does the opposite of =
The contains operator. You can use wildcards with this, but with restrictions:
name contains 'backup*' will return all files with filenames starting with the string backup.
name contains '*NameOfWebsite' will return all files with filenames that have a word starting with the string NameOfWebsite. The file name backup0194364-NameOfWebsite.zip will not be returned, because there is no space before the string.
Therefore, the only way for this to work is if you do it the way you have already started to realise; string chaining:
name contains 'backup' and name contains 'NameOfWebsite' and name contains ...
References:
Files: list | Google Drive API | Google Developers
Search for files | Google Drive API | Google Developers

HTML url passing multiple parameters

I'm trying to pass multiple parameters with an url. I have checked out almost every topic about it, but can't seem to find an answer. I have tried different ways, but it still doesn't work.
It is only sending the first parameter.
If I start with post_id - I can't get comment_id
If I start with comment_id - I can' get post_id
My idea of url:
http://localhost/index.php?post_id=3&comment_id=6
OR
http://localhost/index.php?post_id=3&comment_id=6
I try to use it later like this:
else if(isset($_GET['post_id']) & isset($_GET['comment_id'])){
$post_id = $_GET['post_id'];
$comment_id = $_GET['comment_id'];
$user_id = $this->UserModel->getUser();
$BlogPost = $this->BlogModel->getBlogPost($post_id);
$BlogComments = $this->BlogModel->getBlogCommentList($post_id);
$BlogComments = $this->BlogModel->deleteBlogComment($comment_id,$user_id);
include 'views/ViewBlogPost.php';
}
Your below URL Structure is perfactly true
http://localhost/index.php?post_id=3&comment_id=6
Logic to Pass data Through URL in your script is called as QueryString Which you can build in below way
NAME=VALUE - this is called Name Value Pair , you can Pass Multiple Name Value pair by appending with '&' only
e.g.
http://localhost/index.php?name_1=value_1&name_2=value_2
on server side you will retrive them by using GLOBAL $_GET e.g print_r($_GET); to view all the passed data.
individually you can access them by using
echo $_GET['name_1']; echo $_GET['name_2'];
Also i suggest you to check your GPSC setting in your php.ini to define the priorities between your Super Globals.

Mapping json field with database table field

How can a json id and database table id be mapped in ruby on rails and the output of the result be shown on UI. I have a collection of entries in my database say for id, name, url, code, and on UI i have implemented a table whose values are from Json field. I need to fetch data from database for url and code on UI using map concepts in rails.
Example :
Json field : [position":"1","name":"Bitcoin","change24":"-2.59 %","currency":"usd","id":"btc"]. My database has url and id, where id is the same value as in json. All thats needed is to map the id in-order to get the corresponding url on UI.
So is this something you are going for?
#json_data.map! do |json_item|
db_item = #database_data.detect{|dbi| dbi['id']==json_item['id']}
json_item['url'] = db_item['url'] if db_item
end