Jupyter: grab JSON with multiple async calls and update cell - asynchronous

I am new to Jupyter and trying to put together a formatted HTML cell to present the content of a series of API calls. I know how to make API calls and I know how to present formatted HTML with %%latex. My question is how can I generate the HTML only after all async calls return and using content from all those calls to create an HTML cell in a Jupyter notebook?
Thanks for any suggestions.

Related

How to take a list of strings that comprise of several different URLs and convert them into clickable links on R?

I currently have a variable that contains over 1000 different strings of website URLs however they are all in strings so are not clickable or anything. Is there a function (or set of steps) to which I can convert all of those string of URLs into actual clickable URLs on R.
My goal is to then make a data frame with all of those and merge it in to another data frame, but I'll worry about that part later :)
R itself isn't a web browser and so doesn't have any concept of "clickable links". If you just want the link functionality, the easiest method is to create an html page that you can open in a browser. You can do this in R as follows.
UrlVec <- c("https://stackoverflow.com/url_A",
"https://stackoverflow.com/url_B",
"https://stackoverflow.com/url_C")
cat("<!DOCTYPE html>\n<html>\n<head>\n<title>Links document from R</title>\n</head>\n<body>\n<h1>My Links</h1>\n",
paste0("<p>Link ",seq_along(UrlVec),"</p>",collapse="\n"),
"\n</body>\n</html>\n",file="C:/Path/Links Page.html")
This uses a paste0 to construct the html links in UrlVec, and embeds the result in a very simple template for a web page. This is written to the file "C:/Path/Links Page.html". Open that file in a web browser, and you ought to have clickable links.

PDF creation tool that can handle Client-side view changes

I am trying to find a tool that can be used to create PDFs from websites. These websites all have Bootstrap based client side view settings, such as tabs, toggles, and paging. As such, there is no post-back to the server. I need to be able to create a pdf that is in the same state as the user sees it.
In my research, I have only been able to find tools that can create PDFs if given a URL, or if given a HTML string. Examples of these tools include ActivePDF's Webgrabber, and EVO PDF. However, they are not able to generate the PDF's with the client-specific settings, but instead only see the default selections of a given page. It is not possible for me to do a post-back to the server, so I am looking for a tool that can create PDFs on the fly, with the dynamic settings intact. I am working in ASP.NET, and so I would like a tool that is .NET friendly as well. Lastly, I would prefer the tool to not be open-sourced.
It sounds like a proper solution here would be to take data from your client side, post it via AJAX (not an ASP.NET postback!) and then process it on the server side to generate the PDF. Since you haven't given much detail, I'm going to assume we don't need to send over all the HTML, but rather values that were entered via a form.
<script>
function postDataToServer(){
var itemId = $("#ItemIdTB").val();
var quantityOrdered = $("#QuantityTB").val();
$.ajax({
url : "GeneratePdfFromForm?itemId="+itemId+"&quantityOrdered="+quantityOrdered
})
.done(function(){alert("Success!");})
.fail(function(){alert("Failure!");});
}
</script>
My answer is using jQuery, which is a JavaScript library that simplifies AJAX and DOM manipulation. However, this technique is doable with other JavaScript libraries (or even without a library).
On the server side, let's have an ASP.NET Web API function that can handle that AJAX Post.
[Route("GeneratePdfFromForm")]
public static void GeneratePdfFromForm(string itemId, int quantityOrdered)
{
Debug.WriteLine("Received itemId {0} and quantity {1}", itemId, quantityOrdered);
byte[] pdf = GeneratePDF(itemId, quantityOdered); //you'll need a function called GeneratePDF that can generate your PDF based on the parameters, probably using a library like iTextSharp.
//now do you want with the PDF byte array
}
So that's how you'd generate the PDF. You could return it from the GeneratePdfFromForm() function back to the client. But since that's potentially a long running task, you should probably implement it in the background using something like Hangfire, then when the PDF is ready you'd present it to the client for download (perhaps using SignalR or jQuery AJAX polling to alert the client of when the PDF is ready).
I was passing data from the client side to the server side via query string. You could instead create a class to represent the parameters for your PDF generation, then pass that form the client side to the server side via jQuery AJAX's data parameter.
If you really want to post the entire HTML from the client side to the server, you could so something like this:
var html=$("html").html();
$.ajax({
url: <your url here>,
data: html,
contentType: "text/html"
});
However, I'm willing to bet the actual HTML isn't what you care about for generating the PDF, but rather the selected values from some client side form. The actual HTML would include everything on the client side, including navigation menus, scripts etc. You could post a subset of the HTML using a different selector (ex: $("#OrderDiv").html()), which is a technique some people use to generate PDF's. But I think it's much cleaner to decouple your HTML intended for the browser from the way the PDF is generated, so that changes to your site don't mess up the PDF. You can then use the PDF creating library's capabilities to build the PDF rather than using HTML.

Ext.js4 - Show plain text returned from Java servlet

I am using Ext.js4 and Java servlets. When the user clicks a button on a panel, I execute a Servlet which in turn executes another application, which produces a log file in .txt format. I know the servlet and the other application are being executed. I want the servlet to return the contents of the .txt file, which Ext.js should in turn display as straight text on a separate "Log" tab. Do I need a store and model for something like this? Note that the data returned by the servlet is just text, not JSON or HTML, and special characters (which would preclude the use of JSON or HTML) may be included in that text. Thanks in advance.
No, you don't need a store and model for this.
I would write a servlet that simply returns the contents of the .txt file.
Then use the Ext.Ajax class to create a request to this servlet and save the text as a variable.
Then you can just do: logTab.update(theText) to fill your tab with the contents of the .txt file (where logTab is your tab you want updated).
For example:
Ext.Ajax.request({
url: '../textServlet',
success: function(response){
var theText = response.responseText;
logTab.update(theText); // or however you define your tab
}
});

Scraping ASP pages with Excel/VBA

I'm trying to scrape an ASP.NET page with Excel. Unfortunately, the page only returns 50 records at a time, of several pages. Excel's native Web Query module only picks up the first page. I want all the pages.
Like most (all?) ASP pages, there are a few hidden variables sent back to the server when requesting a new page. The important ones are _VIEWSTATE and _EVENT_VALIDATION.
I've written a VBA function that gets the HTML source of the page and scrapes these variables from it.
I've also written an .iqy page, which allows for POST requests in it. It looks something like this:
WEB
1
http://www.myaspwebsite/search/search_List.aspx
__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTEy[....truncated ..50k characters..]Mhudyk5U6u8%2BBpvxDPN8R4%3D&__EVENTVALIDATION=%2FwEWFQL%2FkN%2FBCgL6g%2B5vAvfY06EOAoic4qIIAome%2Bf4PAuOrjYgIAuKrjYgIAuGrjYgIAuCrjYgIAuerjYgIAt7e34UPAvuL7m8CtuLToQ4CiaTioggCyKX5%2Fg8C4tv1sAgC49v1sAgC4Nv1sAgC4dv1sAgC5tv1sAgC%2Fd7fhQ%2BU8QRtxd7MM4Bpa%2F%2FZC7I64eUh3Q%3D%3D&ctl00_RadMenu1_ClientState=&ctl00%24ContentPlaceHolder1%24NavBar1%24PageNoDropDownList=2&ctl00%24ContentPlaceHolder1%24NavBar1%24btnGo=Go&ctl00%24ContentPlaceHolder1%24NavBar2%24PageNoDropDownList=1
Selection=AllTables
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=False
This iqy page successfully retuns the desired results if the post query is placed in the file.
I can also use this .iqy page programmatically in VBA and assign the POST query dynamically using QueryTables. However, I get told that my query returned nothing.
I suspect this is because of the length of my argument. The VIEWSTATE alone is about 50k characters. I've tried printing the argument string to a file and it truncates it. However, I can read the same string from a file and use it dynamically successfully.
My questions are : Am I going about this the best way? What limitations should I be aware of when doing this? Also, is there a limit to string size in Excel?
According to Microsoft's documentation on Visual Basic strings (same value applies to VBA strings):
A string can contain from 0 to approximately two billion (2 ^ 31) Unicode characters.
That is more than enough to handle a 50k string. A simple way to bypass IDE line limits and immediate window printing limits would be to print the string into an Excel cell and then read it back into a variable when you need to use that piece of data.

How to capture the output from wmd editor in C# asp.net 3.5

I'm using WMD -editor in a message board Application that I am developing in ASP .net 3.5 using C# .
How can I capture the output(markdown?) to the server side so that I can save the user input.
All I could come up is this :
var txt =document.getElementById("wmd-output").innerHTML;
If you're capturing the input as the user is writing the post, e.g. to save a draft, then what you have above is fine and should work.
If you mean capturing the Markdown after the form has been submitted then you need to remove the call to convertToHtml(). The WMD editor converts the Markdown on the fly and submits this in the form for some reason (doesn't seem all that useful if you want to be able to edit the Markdown later).
The call is around line 1200 in the file wmd.js. Either delete or comment the convertToHtml() line.
edit: looks like there is a better way to do this: Using wmd-new to submit markdown

Resources