Struggling to import analyst share price to GoogleSheets - api

I am trying to create a column that imports the analyst price target from TipRanks website.
I uploaded two images:
Image 1: you can see the cell that I want to import.
Image 2: you can see my function that doesn't work.
What should I change in order to get this live info?
Thanks.

The site you are checking is actually "javascript" generated thus import functions won't properly work on them.
To check, just try to import the whole site data. If it returns a javascript function, then it is javascript generated.
Sample (tipranks.com)
What you can do is actually try to find other sites that provide the same data.
I did find one with the same data you are looking for, 50.38 for csiq. Link is "https://www.marketwatch.com/investing/stock/csiq/analystestimates". And since data is shown as table, it would be easier to import using importhtml.
Cell formula is:
=INDEX(IMPORTHTML("https://www.marketwatch.com/investing/stock/csiq/analystestimates", "table", 5), 2, 2)
Sample output:
The table is the fifth one in the DOM, and INDEX(table, 2, 2) means getting the 2nd row 2nd column of the table.
If the site is no good for you, you can try finding other sites that would suit your needs. And then use either importhtml or importxml depending on the site structure.

When you inspect the network when the website is loading you will see that the prices come when calling the forecast endpoint https://www.tipranks.com/stocks/tsla/forecast. This in turn returns an html response which is probably generated with Javascript on the client because they use React on the frontend, but you can still see the preview in the Network tab of the browser dev tools.
You can then copy the preview in VSCode and prettify it, to try and pin point the span holding the price. Of course it won't be exact science, because the html tags are generated with some media queries, but you will get close enough to some extent.
After you get the xml path but you get an empty error, you can delete some tags until you get some text. Use search in google sheets to search for highest price label, and than continue adding tags until you get the desired value.
Here is what I managed to get:
Lowest price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[5]/span[2]")
Average price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[3]/span[2]")
Highest price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[1]/span[2]")
In time these methods might change depending on their development process, but you could use the above steps to update the script.
P.S. I wasn't satisfied with the marketwatch analyst price targets. I think the wisdom of the crowd is better on tipranks.

Try this one. Works perfectly fine on my personal Stock Portfolio on Google Sheets:
Lowest Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A1,"/forecast"), "//*[#class='colorpurple-dark ml3 mobile_fontSize7 laptop_ml0']")
Average Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A4,"/forecast"), "//*[#class='colorgray-1 ml3 mobile_fontSize7 laptop_ml0']")
Highest Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A4,"/forecast"), "//*[#class='colorpale ml3 mobile_fontSize7 laptop_ml0']")

Related

Where do I enter moment.js code so a DataTables column appears in my chosen format?

I want to make data like 2022/12/15 (imported from Google Sheets at the moment of page load) display as "Dec 15" in one column, and as "Thu" in another column.
I found the format codes:
moment().format("MMM d"); // "Dec 15" and
moment().format("ddd"); // "Thu".
I read https://momentjs.com/docs/ and https://momentjs.com/guides/, but could not find:
Where do I enter that code?
Can I skip entering that code, and instead just enter this?:
$(document).ready(function () {
$('#example').DataTable({
columnDefs: [
{
targets: 4,
render: DataTable.render.datetime('MMM d'),
},
],
});
});
Perhaps I should separate my questions into different posted questions, but I imagine it will be more helpful for future readers to find the combined challenges asked and answered in a single thread.
I'm using the WordPress plugin "Inline Google Spreadsheet Viewer", which is built on DataTables.
[Edit: I realized I should not paste that code into inline_gdocs_viewer.php, and intended to paste it into igsv-datatables.js. I could not however figure out where to paste within that file. What should I look for to know where to insert it? (The author of that plugin publicly announced that no more support will be given.) Should I post the contents of the js file somewhere so you can see it?]
[Edit 2: Would entering that code make column 5 always displayed in MMM d format, even if I want column 5 to be displayed in a different format? Shouldn't specifying what format to apply to which column happen when I create a page / post and use the shortcode to embed the spreadsheet?]
(I read the plugin's documentation and I read DataTables documentation.)
If my table doesn't have a name, what do I use instead of #example? Do I need to name my table? If so, how? (I tried to find the answer at, for example, https://www.w3schools.com/html/html_tables.asp.)
The source for the longer code came from a live example where the dates were in column 5, but the code says "targets:4". To apply the code to column 3 (for example), should I enter targets:2? I read https://datatables.net/reference/option/columns.render, but bizarrely that didn't address this basic question.
If you're wondering if I upgraded DataTables from the old version that comes with Inline Google Spreadsheet Viewer, yes I did.
If you're wondering if I got the script array to call moment.js, I might have. Into the scripts array I added
,
'moment' => array(
'src' => plugins_url('moment.min.js', __FIL__),
'deps' => array( 'moment' )
)
I'm not sure about the "deps" part. Does it mean dependencies? Was I right to use "moment" twice in that code?
If you only know a possible answer to one of these questions, that's better than nothing, so please do share what you can.
I know the Moment team recommends you choose a different library than Moment for new projects, but DataTables to this day recommends Moment for sorting by Day of the week or sorting by Date.
Thanks
Using moment.js 2.29.2 and DataTables 1.13.1.
What I tried, and what I expected:
I read the documentation for all the programs, and I read forum discussions for all the programs, and I studied examples, expecting to find where to enter the code, but nowhere could I find what to do with it. It was always assumed that that part was already known.

calling RankToPosition() and _onMoveToPositionClicked

I have a situation where i'd like to enter a "3" into a textbox on a user story grid, call something like RankToPosition(3) to move that user story row to position 3 in the current rank. Within the same grid, the idea is to have a textbox on each row, so the row beneath may have a 4 in there, and when i click SUBMIT, the entire table would be processed by using the numbers in the row textbox and calling RankToPosition(#). This is like the Netflix queue. There have been similar questions on here, but my thought is to just call the underlying method alluded to here as "_onMoveToPositionClicked":
https://help.rallydev.com/apps/2.0rc3/doc/source/MoveToPositionMenuItem.html#Rally-ui-menu-item-MoveToPositionMenuItem-cfg-rankRecordHelper
If i could iterate through the table grid, store initial rank values (i realize they're not just integers), and pick the new text values up, run code to call the _onMoveToPositionClicked beneath the scenes, it may accomplish a bulk rank grid for when users have 200+ items to manage, for instance.
Any insight you have for just calling this in custom code would be helpful. Any solution for representing this functionality would be appreciated. I am currently using Rally 2.0rc3.
Thank you for your time
Is it possible to upgrade to a newer version of the App SDK? 2.0rc3 is a very old pre-release. The latest is 2.1: https://help.rallydev.com/apps/2.1/doc/
In any case, the way ranking is performed is relative to another object via the rankAbove or rankBelow parameters. So given the record you want to rerank:
record.save({
params: {
rankAbove: '/hierarchicalrequirement/12345'
}
});

Getting Steam Player's Inventory List (DOTA 2)

I read some answers from other pages and found http://steamcommunity.com/profiles//inventory/json/570/2 is how I can get the list of the player's inventory. After I went to that address, a lot of data came up. However, the problem is that the data is not presented properly. I got something like this.
{"success":true,"rgInventory":{"7905269096":{"id":"7905269096","classid":"771158876","instanceid":"782509058","amount":"1","pos":1},"7832200468":{"id":"7832200468","classid":"626495772","instanceid":"1463199080","amount":"1","pos":2},"7832199378":{"id":"7832199378","classid":"626495770","instanceid":"1463199082","amount":"1","pos":3},"7832197795":{"id":"7832197795","classid":"626495773","instanceid":"1463199083","amount":"1","pos":4},"7832127932":{"id":"7832127932","classid":"771156290","instanceid":"1463199085","amount":"1","pos":5},"7832128369":{"id":"7832128369","classid":"626495771","instanceid":"1463199086","amount":"1","pos":6},"7832128042":{"id":"7832128042","classid":"466386035","instanceid":"1463199087","amount":"1","pos":7},"7830087148":{"id":"7830087148","classid":"536091705","instanceid":"1463199088","amount":"1","pos":8},"7822471023":{"id":"7822471023","classid":"771179852","instanceid":"782509058","amount":"1","pos":9},"7797472279":{"id":"7797472279","classid":"771410455","instanceid":"782509058","amount":"1","pos":10},"7782683766":{"id":"7782683766","classid":"771181072","instanceid":"782509058","amount":"1","pos":11},"7631976019":{"id":"7631976019","classid":"771157018","instanceid":"782509058","amount":"1","pos":12}},"rgCurrency":[],"rgDescriptions":{"771158876_782509058":{"appid":"570","classid":"771158876","instanceid":"782509058","icon_url":"W_I_5GLm4wPcv9jJQ7z7tz_l_0sEIYUhRfbF4arNQkgGQGKd3kMuVpMgCwRZrh6GdUmV2uVefqzZAxsqDpH8eVO4Nb2CyAaiWsVUbt1mBngc3Zm32FdEXSSFBuQVD4Z97J3LgwOxDlDHfjc9z40ChfLKg86GW_CBqRXhIgJ1zaQ3WkhKx3uK","icon_url_large":"W_I_5GLm4wPcv9jJQ7z7tz_l_0sEIYUhRfbF4arNQkgGQGKd3kMuVpMgCwRZrh6GdUmV2uVefqzZAxsqDpH8eVO4Nb2CyAaiWsVUbt1mBngc3Zm32CZOBWOAUKgdCoUqtJKW0Q7rCFKTLTVowoQBhPHGhMOGCK_YrRq1JVAm2rA7CM1GhVgPNerBnXLi","icon_drag_url":"","name":"Ogre's
Caustic Steel Choppers","market_hash_name":"Ogre's Caustic Steel
Choppers","market_name":"Ogre's Caustic Steel
Choppers","name_color":"D2D2D2","background_color":"","type":"Uncommon
Swords","tradable":0,"marketable":0,"commodity":0,"market_tradable_restriction":"7","market_marketable_restriction":"7","descriptions":[{"type":"html","value":"Used
By: Alchemist"}
Is there any way to make it more neater so I can read the data? Or can anyone give me any ideas about how to process these data? Thanks heaps
This data is in JSON format(http://www.json.org/). It is suited to be consumed by applications. So you should write a little program that will read this data, parse it and query more elements. For example (just guessing here) that there an API where you can get an item by its ID (something like http://steamcommunity.com/items/7832200468).
The output of this program could be a list (text or HTML) of items with their names, values, rarity, etc
Edit: also this: Getting someone's Steam inventory

Obtain Deviantart Deviation ID / UUID from page URL

I was looking at the Deviantart API to see what you can do with it .
A lot of requests require you to provide a deviation id to work with.
Take for instance adding a deviation to favorites ( in Collections -> Add deviation to favorites above, I cannot post more than 2 links... )
Now I looked through the API to figure out how to obtain that id, but I did not find out how to do so.
If I only have the deviation URL, for instance http://kennyklent.deviantart.com/art/Pinkie-Pie-Dancing-296143815 , how can I tell its deviation-id?
It is not the number at the end 296143815, I would've thought so, but it's not.
If it helps, here's one example from the api's /browse/dailydeviations endpoint
"deviationid": "27FD366A-30CB-FC3E-DE54-9621E90FCE60",
"printid": "E984FC87-8B57-239C-FE7C-E2674A0DDFC4",
"url": "http://mudimba.deviantart.com/art/SF-Botanical-Gardens-57879397",
So this deviation SF-Botanical-Gardens-57879397 has the id 27FD366A-30CB-FC3E-DE54-9621E90FCE60 - but how would I find out if it wasn't listed in the examples?
Update 06/2017:
For anyone stumbling across this 2 years later, the answer below still works but there is now another way to get the UUID. Every Deviation now has a meta property da:appurl showing the UUID value on the deviation page itself.
To stay with the SF-Botanical-Gardens-57879397 example from above, looking at the page source at http://mudimba.deviantart.com/art/SF-Botanical-Gardens-57879397 reveals:
<meta property="da:appurl" content="DeviantArt://deviation/27FD366A-30CB-FC3E-DE54-9621E90FCE60">
Which contains exactly the UUID value 27FD366A-30CB-FC3E-DE54-9621E90FCE60
Original answer
I got an answer from a Deviantart dev directly, http://comments.deviantart.com/1/492518964/3755610860
You cannot convert integer IDs into UUID format, you have to query the api to find the correct uuid. So for your example, you would query the /gallery/folders endpoint and then the gallery/{folderid} endpoint to get the list of deviations in that folder.
There's no easier way to obtain the UUID for a given URL for now.

Use custom function to populate gSpreadsheet cell based on a XML/JSON response

Ok, this one has become a little tricky for me and I really need some assistance to work through it.
Problem
I have a GSpreadsheet which has a list of data, in this case Twitter usernames. Using the API of a service provider (in this case the Klout API), I would like to retrieve information about that user to populate a cell within a spreadsheet.
Based on what I can work out so far, I would need to write a custom function to do this but I have no idea where to start, how I might construct it, or if there are any examples of doing this.
Scenario
The Klout API can return either an XML or JSON response (see http://developer.klout.com/docs/read/api/API), based on the string passed. For example, the URL:
http://api.klout.com/1/users/show.xml?key=SECRET&users=thewinchesterau
would return the following XML response:
<users>
<user>
<twitter_id>17439480</twitter_id>
<twitter_screen_name>thewinchesterau</twitter_screen_name>
<score>
<kscore>56.63</kscore>
<slope>0</slope>
<description>creates content that is spread throughout their network and drives discussions.</description>
<kclass_id>10</kclass_id>
<kclass>Socializer</kclass>
<kclass_description>You are the hub of social scenes and people count on you to find out what's happening. You are quick to connect people and readily share your social savvy. Your followers appreciate your network and generosity.</kclass_description>
<kscore_description>thewinchesterau has a low level ofinfluence.</kscore_description>
<network_score>58.06</network_score>
<amplification_score>29.16</amplification_score>
<true_reach>90</true_reach>
<delta_1day>0.3</delta_1day>
<delta_5day>0.5</delta_5day>
</score>
</user>
</users>
Based on this response, I would like to be able to populate different cells with the values returned within the XML (or JSON if easier) packet.
So, for example, I would have a spreadsheet like the following which would have custom functions to go out and retrieve the value of the relevant XML element response to populate the cell:
Cell A B C D E
1 Username kscore Network score Amplification score True reach
2 thewinchester =kscore(A2) =nscore(A2) =ascore(A2) =tscore(A2)
Questions
Are there any gSpreadsheet examples you know of that use an API to pull data in from an external source?
How would one write a custom function to fetch the result from the API and populate a cell with a result of a specific element?
Any information, examples or helpers you have are greatly appreciated.
You want the importXML function, documented here. The formula you want will look something like this:
=importXML("http://api.klout.com/1/users/show.xml?key=SECRET&users=" + A1, "//users/user/score/kscore")
You could write a custom script with Google AppScript, but there's a simple solution to this similar to what Nick Johnson posted. I've tested this against the score function, but it could be easily adapted to the show endpoint with different XPath.
=importXML("http://api.klout.com/1/klout.xml?users="&A1&"&key=YOUR_API_KEY", "//users/user/kscore")
This presumes your Twitter IDs are in the A column.
Note, Google Docs limits the number of such importXML functions to 50 per spreadsheet. You could concatenate groups of 5 userids for each importXML call, effectively putting your limit to 250 a sheet.
This could also be adapted to a similar call in Excel that doesn't have that limit. Keep in mind the Klout ToS, though, using proper attribution and rate limits.