Gspread append is not removing the single quote - gspread

I have switched to using gspread instead of pure google sheets api. Before i formatted my input into a json body but now i send the list direct. The append works without an error but the first item has an extra single quote on the beginning of the date.
I fell like im following the example to the letter so it seems like a bug but i wanted to ask here first just in case i'm doing something silly.
values = ['2021-08-11', '-', '-', 372, 373, 'Brayden', 'ChrisT',
'Chris', 'Dida', 'Darren', 'Ferdi', 'Bernard', 'Cal', 'Gavin',
'Conor']
ws.append_row(values)
First item in sheet: '2021-08-11
Originally using the pure api i was formatting the body as follows but as i understand it with gspread i should just be able to send the list.
body = {
'majorDimension': 'ROWS',
'values': [
google_output,
],
}
The same seems to happen if i update instead of append:
ws.update(range, values, major_dimension='ROWS')
Im using version 4.0.0 of gspread and here is the guide im following:
(method) append_row: (values, value_input_option='RAW',
insert_data_option=None, table_range=None) -> Any Adds a row to the
worksheet and populates it with values.
Widens the worksheet if there are more values than columns.
:param list values: List of values for the new row. :param str
value_input_option: (optional) Determines how the input data
should be interpreted. See ValueInputOption_ in the Sheets API reference. :param str insert_data_option: (optional) Determines how
the input data
should be inserted. See InsertDataOption_ in the Sheets API reference. :param str table_range: (optional) The A1 notation of a
range to search
for a logical table of data. Values are appended after the last row of the table. Examples: A1 or B2:D4

It seems to be a problem with gspread itself. I encountered this problem myself and according to this thread not only us. In this thread they suggest to add
value_input_option = 'USER_ENTERED'
(so that your code looks like this:
values = ['2021-08-11', '-', '-', 372, 373, 'Brayden', 'ChrisT', 'Chris', 'Dida', 'Darren', 'Ferdi', 'Bernard', 'Cal', 'Gavin', 'Conor']
ws.append_row(values, value_input_option = 'USER_ENTERED')
)
in order to remove that single quote. It worked for me and I hope that it works for you as well

Related

IMPORTXML To Return a Value from dividendhistory.org

I want to return the value of "Yield:" from a series of stocks from a URL dividenhistory.org, for example HDIF into a Google sheet using IMPORTXML, where F7 represents the user supplied ticker.
=IMPORTXML("https://dividendhistory.org/payout/TSX/"&F7, "/html/body/div/div[2]/div[2]/p[4]")
The problem with the above is the yield value is not always located in the same paragraph, depending on the ticker. It also returns with the word "Yield:" as part of the value.
I believe I should be using the XPATH parameter which should find and return the yield value only, but I am lost. I am open to all suggestions!
I tried with a few of the tickers there, and this should work. For example:
=IMPORTXML("https://dividendhistory.org/payout/ctas/", "//p[contains(.,'Yield')]/text()")
Output:
Yield: 1.05%
Obviously, you can change 'ctas' for any user input.
Try this and see if it works on all tickers.
EDIT:
To get only the number 1.05, you need to split the result and output the 2nd part:
=index(split(IMPORTXML("https://dividendhistory.org/payout/ctas/", "//p[contains(.,'Yield')]/text()"), ": "),2)
Output:
0.0105

Powerautomate Parsing JSON Array

I've seen the JSON array questions here and I'm still a little lost, so could use some extra help.
Here's the setup:
My Flow calls a sproc on my DB and that sproc returns this JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
Then I use a PARSE JSON action to get what looks like the same result, but now I'm told it's parsed and I can call variables.
Issue is when I try to call just, say, SiteConfigID, I get "The output you selected is inside a collection and needs to be looped over to be accessed. This action cannot be inside a foreach."
After some research, I know what's going on here. Table1 is an Array, and I need to tell PowerAutomate to just grab the first record of that array so it knows it's working with just a record instead of a full array. Fair enough. So I spin up a "Return Values to Virtual Power Agents" action just to see my output. I know I'm supposed to use a 'first' expression or a 'get [0] from array expression here, but I can't seem to make them work. Below are what I've tried and the errors I get:
Tried:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
Also Tried:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
Finally I tried
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
Here is a screenie of the setup:
To be clear: the end result i'm looking for is for the system to just return "SiteConfigID" as a string or an int so that I can pipe that into a virtual agent.
I believe this is what you need as an expression ...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
You can see I'm just traversing down to the object and through the array to get the value.
Naturally, I don't have your exact flow but if I use your JSON and load it up into Parse JSON step to get the schema, I am able to get the result. I do get a different schema to you though so will be interesting to see if it directly translates.

Fetch value from XML using dynamic tag in ESQL

I have an xml
<family>
<child_one>ROY</child_one>
<child_two>VIC</child_two>
</family>
I want to fetch the value from the XML based on the dynamic tag in ESQL. I have tried like this
SET dynamicTag = 'child_'||num;
SET value = InputRoot.XMLNSC.parent.(XML.Element)dynamicTag;
Here num is the value received from the input it can be one or two. The result should be value = ROY if num is one and value is VIC if num is two.
The chapter ESQL field reference overview describes this use case:
Because the names of the fields appear in the ESQL program, they must be known when the program is written. This limitation can be avoided by using the alternative syntax that uses braces ( { ... } ).
So can change your code like this:
SET value = InputRoot.XMLNSC.parent.(XMLNSC.Element){dynamicTag};
Notice the change of the element type as well, see comment of #kimbert.

Cypress - counting number of elements in an array that contain a specific string

Attempting to confirm that of all the schema in the head of a page exactly 3 of them should have a specific string within them. These schemas have no tags or sub classes to differentiate themselves from each other, only the text within them. I can confirm that the text exists within any of the schema:
cy.get('head > script[type="application/ld+json"]').should('contain', '"#type":"Product"')
But what I need is to confirm that that string exists 3 times, something like this:
cy.get('head > script[type="application/ld+json"]').contains('"#type":"Product"').should('have.length', 3)
And I can't seem to find a way to get this to work since .filter, .find, .contains, etc don't filter down the way I need them to. Any suggestions? At this point it seems like I either need to import a custom library or get someone to add ids to these specific schema. Thanks!
The first thing to note is that .contains() always yields a single result, even when many element match.
It's not very explicit in the docs, but this is what it says
Yields
.contains() yields the new DOM element it found.
If you run
cy.get('head > script[type="application/ld+json"]')
.contains('"#type":"Product"')
.then(console.log) // logs an object with length: 1
and open up the object logged in devtools you'll see length: 1, but if you remove the .contains('"#type":"Product"') the log will show a higher length.
You can avoid this by using the jQuery :contains() selector
cy.get('script[type="application/ld+json"]:contains("#type\": \"Product")')
.then(console.log) // logs an object with length: 3
.should('have.length', 3);
Note the inner parts of the search string have escape chars (\) for quote marks that are part of the search string.
If you want to avoid escape chars, use a bit of javascript inside a .then() to filter
cy.get('script[type="application/ld+json"]')
.then($els => $els.filter((index, el) => el.innerText.includes('"#type": "Product"')) )
.then(console.log) // logs an object with length: 3
.should('have.length', 3);

worksheet.format("A2:A", { "numberFormat": { "type": "DATE_TIME" }}) doesn't work for text

I'm trying to log temperature and humidity to a google spreadsheet using gspread and python.
That works, however when I insert a row using the following code:
worksheet.append_row((datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"), temp, humidity))
now for example cell 'A2' has the value: '12-05-2020 00:11:50 (Note the single quotation mark)
I want the data to be represented in a chart. This cannot be done with the above value so I have to convert it to a date_time value.
worksheet.format("A2:A", { "numberFormat": { "type": "DATE_TIME" }})
I expect the entire column to be converted to Date Time. This doesn't convert the values with a single quotation mark.
I spend the whole day trying to get this to work but for some reason I can't seem to find a way to have a 'normal' date_time value added that Google Sheets recognizes as a date_time...
If I enter a (numeric) value manually in a cell in column A. The code to set the format works just fine.
Also if I manually select the column and select he formatting from the menu it works fine with the gspread added date time rows.
I really want it to be done programmatically and not by hand of course.
Any help is greatly appreciated.
In that case, please use value_input_option as follows. By this, the date is put as the date object.
From:
worksheet.append_row((datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"), temp, humidity))
To:
worksheet.append_row((datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"), temp, humidity), value_input_option="USER_ENTERED")
Reference:
append_rows(values, value_input_option='RAW', insert_data_option=None, table_range=None)
ValueInputOption

Resources