Read data from wikipedia using API [closed] - matlab

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
For my project, I am trying to read data from Wikipedia, I am not completely sure, how I can do that.
My main concern is to read, date, location and subject of event.
For a start, I have started reading above mentioned information for 91st academy awards.
I tried using Wikipedia query service, but it didn't helped much.
Then I came across API solution and ran following URL,
https://en.wikipedia.org/w/api.php?action=parse&format=json&prop=sections&page=91st_Academy_Awards
But didn't found the information what I was looking for.
I am trying to read the information marked in red box in below image,
Can somebody help me with this and let me know how can I read the above mentioned section.
PS:I am using Matlab for writing my algorithm

A possible solution is to read the webpage using webread, and process the data using the functions from the Text Analytics Toolbox:
% Read HTML data.
raw = webread('https://en.wikipedia.org/w/api.php?action=parse&format=json&prop=text&page=91st_Academy_Awards');
% Specify sections of interest.
SectionsOfInterest = ["Date","Site","Preshow hosts","Produced by","Directed by"];
% Parse HTML data.
myTree = htmlTree(raw.parse.text.x_);
% Find table element.
tableElements = findElement(myTree,'Table');
tableOfInterest = tableElements(1);
% Find header cell elements.
thElements = findElement(tableOfInterest,"th");
% Find cell elements.
tdElements = findElement(tableOfInterest,"td");
% Extract text.
thHTML = thElements.extractHTMLText;
tdHTML = tdElements.extractHTMLText;
for section = 1:numel(SectionsOfInterest)
sectionName = SectionsOfInterest(section);
sectIndex = strcmp(sectionName,thHTML);
% Remove spaces if present from section name.
sectionName = strrep(sectionName,' ','');
% Clean up data.
sectData = regexprep(tdHTML(sectIndex),'\n+','.');
% Create structure.
s.(sectionName) = sectData;
end
Visualising the output structure:
>> s
s =
struct with fields:
Date: "February 24, 2019"
Site: "Dolby Theatre.Hollywood, Los Angeles, California, U.S."
Preshowhosts: "Ashley Graham.Maria Menounos.Elaine Welteroth.Billy Porter.Ryan Seacrest. "
Producedby: "Donna Gigliotti.Glenn Weiss"
Directedby: "Glenn Weiss"

Related

How to write data to excel in MATLAB in next columns when each time program executes having the previous results saved in previous columns [duplicate]

This question already has an answer here:
How can I update calculated data in my excel sheet in the next column each time I run my code in MATLAB?
(1 answer)
Closed 4 years ago.
function []=calculate(a,b,c,d)
calculation(1)=a*b;
calculation(2)=a+b+c+d;
calculation(3)=a*b*c*d;
calculation(4)=(a+b)-(c+d);
calculation = calculation'; %transpose of calculation array
excelfile= 'test.xlsx';
xlswrite(excelfile,calculation,'C4');
end
My actual code consists of a function that accepts 5 arguments and returns 14 values in an array similar to the code posted here. My problem is that each time I run the program which has the calculate() function called, it writes the data into test.xlsx file at column C starting from row4, but it overwrites the previously calculated data stored from C4. I want that when the 2nd time the main program is run the data should be written from column D and row4, for the third time to E4 and so on. Please help me with a solution.
if you can pass a variable, that counts the amount of columns written, you can proceed like this:
function [] = calculate(a,b,c,d,counter)
stringvect = ('A':'Z');
posColumn = [stringvect(counter) '4'];
calculation(1)=a*b;
calculation(2)=a+b+c+d;
calculation(3)=a*b*c*d;
calculation(4)=(a+b)-(c+d);
calculation = calculation'; %transpose of calculation array
excelfile = 'test.xlsx';
xlswrite(excelfile,calculation,posColumn);
end
In case you want to have more than 26 columns you should simply add an if else to determine whether to add another letter or not.
If you can't use a counter, just write a response.
I hope this helps, cheers Pablo

Accessing values - Swift [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
You are given a dictionary crypt of type [String:String] which has values for all lowercase letters. The crypt dictionary represents a way to encode a message. For example, if crypt["h"] = "#" and crypt["i"] = "!" the encoded version of the message "hi" will be "#!".
The thing is that i have to Write code that would take any string containing only lower case letters and spaces and encode it using the crypt dictionary. I have successfully failed trying to write the code so i ended up just using a single print statement
//print(crypt["h"]!,crypt["i"]!).
If you have any idea you would like to share, please do so.
Thank you
Does this do what you're looking for:
let message = "hi"
let encryptedMessage = message.map { crypt[String($0)]! }.joined()
If you're unfamiliar with it, mapping a string iterates through each character, doing something to it, and returning that string. $0 refers to the first parameter (in this case #1 of 1, but 0-indexed).
As Dopapp suggests, map is the most elegant solution. If you want to see the steps broken out a bit, you can do it the long way.
var message = "hi"
var crytpedMessage = ""
for char in message {
let newChar = crypt[String(char)]
cryptedMessage.append(newChar)
}

How can I get user responses in surveygizmo?

I want to get user's response along with question from surveyGizmo. I am getting list of questions and possible answers.
But I want specific answer which user has given during survey.
https://restapi.surveygizmo.com/v5/survey/123456/surveyresponse?api_token='some token'
I can suggest solution, but only on python and missing some profit for you, becasue your task is not exact. It's a general way to print all answers. And you can choose that you need.
#needed packages
from surveygizmo import SurveyGizmo
import json
#auth
sg = SurveyGizmo(
api_version='v4',
response_type='json',
api_token = api_token,
api_token_secret = api_token_secret
)
#get data from your account as json (as I know json is optional)
answers = json.loads(sg.api.surveyresponse.list(surveyid, resultperpage=resultperpage, page=page)
#in answers['data'] are saved onlu responses
list_of_answers = answers['data']
#using loop you can get all answers on all questions
for answer_index in list_of_respondents:
for question_index, question_value in enumerate(list_of_answers[answer_index])
#SurveyGizmo data structure contains answers with labels like '[question(question_id), [option(option_id)' — that's why we need this 'if'
if question_value.startswith('[question'):
print(list_of_answers[answer_index][question_value])
Actually I'm working with it now and try to transfer all sg-data to sql like database and it makes me to do find simpliest ways to work. So f you give more information, I can make more profit for you.

Trigger a Custom Event in ABAP ZPROGRAM [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am developing in ABAP.
I have a requirement to trigger a custom event in an ABAP Z-program.
Can anyone pls tell me how can I call a custom event in a Z-program to send an email.
(please note: It is not workflow, I need to complete this task in the Z-program).
Your description is a little vague, so in general if you talk about a button to press and a following action that is to be triggered you may need to:
define a button for the Application Toolbar in GUI-Status with a custom function code that is used when the button is clicked
add a gloabl general attribute with "type of screen element" = OK to the dynpro screen's element list
check this global attribute in the PAI module for the custom function code value and then perform/call your sendEmail function
You should create your custom event within transaction SM62. At your program, you call the function module BP_EVENT_RAISE, to raise your custom event. "eventid" is the name of the event you created previously at SM62.
Use the following code example to send an email in ABAP z-program code, via calling function module SO_NEW_DOCUMENT_SEND_API1 (SAPoffice: Send new document):
* Data Declarations
DATA: LT_MAILSUBJECT TYPE SODOCCHGI1.
DATA: LT_MAILRECIPIENTS TYPE STANDARD TABLE OF SOMLREC90 WITH HEADER LINE.
DATA: LT_MAILTXT TYPE STANDARD TABLE OF SOLI WITH HEADER LINE.
* Recipients
LT_MAILRECIPIENTS-REC_TYPE = 'U'.
LT_MAILRECIPIENTS-RECEIVER = 'sheetal#gmail.com'.
APPEND LT_MAILRECIPIENTS .
CLEAR LT_MAILRECIPIENTS .
* Subject.
LT_MAILSUBJECT-OBJ_NAME = 'TEST'.
LT_MAILSUBJECT-OBJ_LANGU = SY-LANGU.
LT_MAILSUBJECT-OBJ_DESCR = 'Mail Subject'.
* Mail Contents
LT_MAILTXT = 'This is a test mail'.
APPEND LT_MAILTXT. CLEAR LT_MAILTXT.
* Send Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = LT_MAILSUBJECT
TABLES
OBJECT_CONTENT = LT_MAILTXT
RECEIVERS = LT_MAILRECIPIENTS
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.
IF SY-SUBRC EQ 0.
COMMIT WORK.
* Push mail out from SAP outbox
SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.
ENDIF.

What text (in English) should I use when asking the user to overwrite a document? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I write a lot of applications in C# and I'm trying to sew up some holes in my standard practices.
Specifically, I'm trying to decide on the best text to use in a message box, and I thought I'd ask the StackOverflow community since I believe that many opinions are always better than one.
What I have currently is:
"Document XXX.docx already exists. Okay to overwrite?"
Buttons for; Yes, No and Cancel
I'm really interested to see which examples turn out to be the most popular.
There are no limits on the style used; formal, casual, humourous, etc. All suggestions are welcome. Aim to err safely within political correctness though.
On a small side note: It would also be great, but by no means essential, to consider that the same text could also be suitable for a command line program.
Please note: English language only please. For other languages, please raise a new question.
Personally, I like to see a bit more context and slightly different wording. Something like:
"<existing document name>" already exists in "<destination path>".
Would you like to replace it (Y/N)?
or perhaps with even more information:
"<existing document name>" (<bytes>) (<date modified>) already exists in
"<destination path>".
Would you like to replace it with file of size <new bytes>, last modified
<new date modified> (Y/N)?
I think "replace" is a bit more clear than "overwrite" - and (speculation) may translate into other languages, and maintain the intended meaning more often.
...and one last option with new file name/location info:
"<existing document name>" (<bytes>) (<date modified>) already exists in
"<destination path>".
Would you like to replace it with file "<new file name>" in "<new path>" of
size <new bytes>, last modified <new date modified> (Y/N)?
This last one would probably just show a temp file / buffer location for an initial file save--but it is reusable, and more meaningful when doing a file copy.
Hope you find one of these useful.
Cheers,
Hans
Title: Overwrite?
"XXX.docx exists.
Would you like to overwrite XXX.docx?"
Buttons: Overwrite, Keep, Panic
Simple solutions are usually best, for example windows user might find it familiar to see a message :
He has 3 options :
Replace
Abort action x3
Create with a new name