How to retrieve simple xml from public Google spreadsheet - google-sheets

I am working in an Arduino device in which I need to retrieve public data from a Google spreadsheet.
So far I have published the spreadsheet and I can access it at https://spreadsheets.google.com/feeds/cells/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/1/public/full?range=a11:c12 which can be opened in the browser or in the Arduino (I am working with a SIM800 module so it can work with HTTPS without problems).
The output of this is xml items like (I am not very into XML):
<entry>
<id>https://spreadsheets.google.com/feeds/cells/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/1/public/full/R12C11</id>
<updated>2018-04-30T05:31:51.590Z</updated>
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#cell'/>
<title type='text'>K12</title>
<content type='text'>12345</content>
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/1/public/full/R12C11'/>
<gs:cell row='12' col='11' inputValue='12345' numericValue='12345.0'>12345</gs:cell>
One of them for every cell requested.
The thing is that here I can see too much unneeded/redundant information, for example, in "title" and "content" I get the same information as in "gs:cell", "updated" may actually be useful but "link" and "category" are completely disposable to me.
Since I will be working with an Arduino and a sim800 module (which cannot handle high data transfer speeds) making this as simple as possible will be great.
Probably there is a way to request this simplified in the HTTP call, maybe adding some parameters or changing "full" to something else.
Any help will be greatly appreciated

You want to retrieve the simpler response from range=a11:c12 of the spreadsheet ID 1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4. If my understanding is correct, how about retrieving values using Query Language? I think that there may be several methods. So please think of this as one of them.
Pattern 1: Retrieve response as HTML
https://docs.google.com/spreadsheets/d/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/gviz/tq?range=a11:c12&tqx=out:html
Result :
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>A11:C12</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="0">
<tr style="font-weight: bold; background-color: #aaa;">
<td></td><td></td><td></td>
</tr>
<tr style="background-color: #f0f0f0">
<td>DataInCellA11</td><td>DataInCellB11</td><td>DataInCellC11</td>
</tr>
<tr style="background-color: #ffffff">
<td>DataInCellA12</td><td>DataInCellB12</td><td>DataInCellC12</td>
</tr>
</table>
</body>
</html>
Pattern 2: Retrieve response as CSV
https://docs.google.com/spreadsheets/d/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/gviz/tq?range=a11:c12&tqx=out:csv
Result :
"DataInCellA11","DataInCellB11","DataInCellC11"
"DataInCellA12","DataInCellB12","DataInCellC12"
Note :
In this case, the response cannot be retrieved as the xml format. There is no tqx=out:xml.
As a sample, you can retrieve values using curl and browser from above URLs.
If you want to retrieve values from other sheets, please use the query of gid. In this sample, gid=od6 which means 1st sheet is omitted.
Reference :
Query Language Reference
If I misunderstand your question, I'm sorry.

Related

ErrorCode "12200" XML Validation warning: " Cannot find the declaration of element 'html'."

I am trying to run the code sample given by Twilio devs: https://github.com/TwilioDevEd/ivr-phone-tree-csharp
When I call my test number, the code doesn't execute because of the warning
"XML Validation warning"
line "1"
parserMessage " Cannot find the declaration of element 'html'."
ErrorCode "12200"
LogLevel "WARN"
and the XML that allegedly has the problem is Twilio's own code that has the "html" tags just fine.
<html>
<head>
<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
<title>IVR Phone Tree</title>
<link href="/Content/site.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha256-k2/8zcNbxVIh5mnQ52A0r3a6jAgMGxFJFE2707UxGCk= sha512-ZV9KawG2Legkwp3nAlxLIVFudTauWuBpC10uEafMHYL0Sarrz5A7G79kXh5+5+woxQ5HM559XX2UZjMJ36Wplg==" crossorigin="anonymous"></link>
</head>
<body>
<div class="body-content"></div>
<footer>
Made with
<i class="fa fa-heart"></i> by your pals
#twilio
</footer>
</body>
</html>
Does anyone know what the problem really is? I have already had to add closing tags, comment out DOCTYPE.. I am getting frustrated to find that the sample that is supposed to teach me something doesn't actually work
Twilio developer evangelist here.
When Twilio makes a webhook request to your application to find out what to do with the incoming call, it expects the response to be XML, TwiML in fact. Instead, your application is serving HTML, which Twilio doesn't know what to do with.
I would ensure that your phone number is configured to point to the correct path in the application, which should be http://<your-ngrok-subdomain>.ngrok.io/ivr/welcome.
Let me know if that helps at all.

Adding new divs (blocks of content) inside OneNote page using the Microsoft Graph API

I am using the Microsoft Graph API to programmatically add content to a OneNote Page on my Office365 OneNote Notebook. For an example page like this:
OneNote snip consisting of Title & 2 separate divs/blocks, this is the generated HTML that I get by making a GET to the pages/{myPageID}/content?includeids=true endpoint
<html lang="en-US">
<head>
<title>Thursday, December 6, 2018</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="created" content="2018-12-06T19:55:00.0000000" />
</head>
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
<div id="div:{95790d05-168a-4f61-81a7-5c13e3124069}{4}" style="position:absolute;left:48px;top:115px;width:624px">
<p id="p:{95790d05-168a-4f61-81a7-5c13e3124069}{10}" style="margin-top:0pt;margin-bottom:0pt">It is a jolly good day</p>
</div>
<div id="div:{3a6b78e9-2af8-4a5b-abf8-09871fb6eec5}{20}" style="position:absolute;left:44px;top:180px;width:624px">
<p id="p:{3a6b78e9-2af8-4a5b-abf8-09871fb6eec5}{24}" style="margin-top:0pt;margin-bottom:0pt">Lets do this shall we</p>
</div>
</body>
</html>
I now try adding a new div/block by making the following PATCH using the requests library in Python. The myPageID and access_token are collected previously by making GET requests to the graph API:
patchPageURL='https://graph.microsoft.com/v1.0/users/'+userID+'/onenote/pages/'+myPageID+'/content?includeIDs=true'
patchPageHeaders={
'Content-Type':'application/json',
'Authorization':'Bearer '+access_token
}
patchPageBody=[{
'target':'div:{3a6b78e9-2af8-4a5b-abf8-09871fb6eec5}{20}',
'action':'insert',
'position':'after',
'content':'<div><p> And God said let there be new blocks </p></div>'
}]
patchResp = requests.patch(patchPageURL, headers=patchPageHeaders, json=patchPageBody)
However, I end up with a 400 error as a response to my PATCH request with the following code and message:
code: 20135
message: The entity type is not supported for this operation.
If I change the opening div tag for the content to something like <div data-id="new-div">, I still receive the same 400 error, code 20135.
I am following the instructions from this documentation here. What subtlety is being missed here? There are no authentication or other similar errors. The PATCH works fine if I change the target to body and the action to append but that doesn't make a new div/block and only adds the content as a child of the first div in the page.
Is there a straightforward way to add new blocks/divs as a sibling of existing blocks or even just something as simple as adding a new block at the end of the OneNote page?

Microsoft edge v 17.17134 displays a # on postback

I recently stumbled upon a weird problem with the last version of Microsoft Edge (17.17134).
I have a really simple classic asp form that posts data to another asp form. If I post a string which contains
input
and
onclick=""
the receiving page will only display a "#" even if the code behind seems ok(see screenshot)
here's a snippet:
<!doctype html>
<html>
<body>
<form method="POST" action="to.asp">
<input type="text" name="hidInnerHTML" id="hidInnerHTML" style="width:500px;" value="steve would like your input on what to do when you activate the onclick= method" />
<br />
<input type="submit" value="click me"/>
</form>
</body>
</html>
and here is the code at the receiving end:
<!doctype html>
<html>
<body>
<div style="border:1px solid red;"></div>
</body>
</html>
It seems that certain keyword in the post data will trigger this effect. IE, chrome, probably Firefox, previous version of edge - all work correctly.
Any clues or idea what is happening here?
I'll take all the help I can get! :)
After doing a bit more research, i can see that this exact issue has just been raised here...
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/19045578/
Check out the link for a fuller explanation but the short story is that you either set a "X-XSS-Protection" response header on your site with a value of "0" or you wait for the Windows 10 Insider Preview version (Build 17758) of Edge which includes the fix for this bug.
Microsoft Edge 44.17758.1.0
Microsoft EdgeHTML 18.17758

Parsing HTML in Jenkins

I'm using poll-mailbox-trigger-plugin to trigger Jenkins jobs based on incoming emails.
One of the build parameters (pmt_content) contains the body of the email specified in HTML.
Is there a Jenkins plugin that can parse the HTML and retrieve the values of user-specified tags?
Email content example:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8">
<title></title>
</head>
<body style='margin:20px'>
<p>The following user has registered a device, click on the link below to
review the user and make any changes if necessary.</p>
<ul style='list-style-type:none; margin:25px 15px;'>
<li><b>User name:</b> Test User</li>
<li><b>User email:</b> test#abc.com</li>
<li><b>Identifier:</b> abc123def132afd1213afas</li>
<li><b>Description:</b> Tom's iPad</li>
<li><b>Model:</b> iPad 3</li>
<li><b>Platform:</b></li>
<li><b>App:</b> Test app name</li>
<li><b>UserID:</b></li>
</ul>
<p>Review user: https://cirrus.app47.com/users?search=test#abc.com</p>
<hr style='height=2px; color:#aaa'>
<p>We hope you enjoy the app store experience!</p>
<p style='font-size:18px; color:#999'>Powered by App47</p><img alt='' src=
'https://cirrus.app47.com/notifications/562506219ac25b1033000904/img'>
</body>
</html>
Specifically, how could I retrieve the value of the "Identifier:" tag?
I'm sure I could write a script to do it but I'd rather the logic in Jenkins.
Is there a Jenkins plugin that can parse the HTML and retrieve the values of user-specified tags?
Its a one-liner on the shell or few lines in the scripting language of your choice. But seems, thats not what you are looking for.
In general, no, there isn't a plugin for the purpose of parsing HTML and retrieving the value of a tag, see https://wiki.jenkins-ci.org/display/JENKINS/Plugins
How could I retrieve the value of the "Identifier:" tag?
There is a generic plugin called Conditional BuildStep,
which supports regular expressions on parameters.
When the HTML Email content is in pmt_content you could use the following
RegExp
<li><b>Identifier:<\/b>(.*)<\/li> to extract the value abc123def132afd1213afas (or match and exec another command, if found).

jQuery UI Autocomplete can't figure it out

I decided to use jQuery UI for my autocomplete opposed to a plugin because I read that the plugins are deprecated. My overall goal is to have an autocomplete search bar that hits my database and returns users suggestions of city/state or zipcodes in a fashion similar to google. As of now I am not even sure that the .autocomplete function is being called. I scratched everything I had and decided to start with the basics. I downloaded the most recent version of jQuery UI from http://jqueryui.com/download and am trying to get the example that they use here http://jqueryui.com/demos/autocomplete/ to work. All the scripts that I have included seem to be connected at least linked through Dreamworks so I am fairly certain that the paths I have included are correct. The CSS and Javascripts that I have included are unaltered straight from the download. Below is my HTML code and my backend PHP code that is returning JSon formated data. Please help me. Maybe I need to include a function that deals with the JSon returned data but I am trying to follow the example although I see that they used a local array.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQueryUI Demo</title>
<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.17.custom.css" type="text/css" />
<script type="text/javascript" src ="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src ="js/jquery-ui-1.8.17.custom.min.js"></script>
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#tags").autocomplete({
source: "search_me.php"
});
});
</script>
</head>
<body>
<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p>
<p>The datasource is a simple JavaScript array, provided to the widget using the source-option.</p>
</div><!-- End demo-description -->
</body>
</html>
Below the PHP part.
<?php
include 'fh.inc.db.php';
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));
$location = htmlspecialchars(trim($_GET['term'])); //gets the location of the search
$return_arr = array();
if(is_numeric($location)) {
$query = "SELECT
zipcode_id
FROM
user_zipcode
WHERE
zipcode_id REGEXP '^$location'
ORDER BY zipcode_id DESC LIMIT 10";
$result = mysql_query($query, $db) or die(mysql_error($db));
while($row = mysql_fetch_assoc($result)) {
extract($row);
$row_array['zipcode_id'] = $zipcode_id;
array_push($return_arr, $row_array);
}
}
mysql_close($db);
echo json_encode($return_arr);
?>
Thanks for the ideas. Here is an update.
I checked the xhr using firebug and made sure that it is responding thanks for that tip. also the above php code I hadn't initialized $return_arr so i took care of that. Also thanks for the clarification of the js required or rather not required. Now when I type in a zipcode a little box about a centimeter shows up underneath it but I can't see if anything is in there, I would guess not. I went to my php page and set it up to manually set the variable to "9408" and loaded the php page directly through my browser to see what it returned. This is what it returned.
[{"zipcode_id":"94089"},{"zipcode_id":"94088"},{"zipcode_id":"94087"},{"zipcode_id":"94086"},{"zipcode_id":"94085"},{"zipcode_id":"94083"},{"zipcode_id":"94080"}]
I then went to a JSON code validator at this url http://jsonformatter.curiousconcept.com/ at it informed me that my code is in fact returning JSON formatted data. Anymore suggestions to help me troubleshoot the problem would be terrific.
Wow after more research I stumbled across the answer on someone another post.
jquery autocomplete not working with JSON data
Pretty much the JSON returned data must contain Label or Value or both. Switched the zipcode_id to value in my $row_array and... boom goes the dynamite!
Your scripts (js files) references are not correct, should only be:
<!-- the jquery library -->
<script type="text/javascript" src ="js/jquery-1.7.1.min.js"></script>
<!-- the full compressed and minified jquery UI library -->
<script type="text/javascript" src ="js/jquery-ui-1.8.17.custom.min.js"></script>
The files "jquery.ui.core.js", "jquery.ui.widget.js" and "jquery.ui.position.js" are the separated development files, the jquery ui library is splitted into modules.
The file "jquery-ui-1.8.17.custom.min.js" contains them all, compressed and minified !
Concerning the data source, as stated in the "Overview" section of the Autocomplete documentation: when using a an URL, it must return json data, either of the form of:
an simple array of strings: ['string1', 'string2', ...]
or an array of objects with label (and a value - optionnal) property [{ label: "My Value 1", Value: "AA" }, ...]
I'm really not familiar with PHP so just make sure your php script returns one of those :-)

Resources