How does Google Finance update stock prices? - ajax

If you use Google Finance, you see the stock price update in real time. However, I do not see ajax requests for each price change. How exactly is it receiving it's data? The ajax calls do happen every so often but not for every price change.
https://www.google.com/finance?q=aapl

It is true that the graph is supplied by flash, but the price of the stock is in HTML and updated in real time.
By looking at the connections, you'll notice that one of the connection stays open. My guess is that it provides the data:
https://www.google.com/finance/qs/channel?VER=8&RID=rpc&SID=628A5B4C83473350&CI=0&AID=0&TYPE=xmlhttp&zx=dcad1i8o61q8&t=1

The graph is supplied by Adobe Flash Player so I don't think you'd see any traffic via inspector for that. The rest though does generate calls:
https://www.google.com/finance/getprices?q=AAPL&x=NASD&i=120&p=25m&f=d,c,v,o,h,l&df=cpct&auto=1&ts=1368199239667&ei=jw-NUcivEsmrqQGT7wE
would be an example of what I'm seeing.
Here's is the response from the server:
EXCHANGE%3DNASDAQ
MARKET_OPEN_MINUTE=570
MARKET_CLOSE_MINUTE=960
INTERVAL=120
COLUMNS=DATE,CLOSE,HIGH,LOW,OPEN,VOLUME
DATA=
TIMEZONE_OFFSET=-240
a1368197880,452.2847,452.29,451.6,452.0101,35458
1,451.81,452.3,451.661,452.24,91267
2,452.2,452.3,451.8314,451.84,35767
3,451.91,452.3,451.8,452.3,89882
4,452.4575,452.61,451.88,451.88,45130
5,452.77,452.88,452.45,452.48,35866
6,453.626,453.9,453.27,453.3571,0
7,453.05,453.6599,453,453.61,0
8,452.9,453.17,452.83,453.09,0
9,452.58,453.15,452.4377,452.865,0
10,452.7568,453.068,452.45,452.475,0
11,452.53,452.8,452.302,452.75,0
The other call is makes is to:
https://www.google.com/finance/qs/channel?VER=8&SID=6C5BE78E1E7D9597&RID=82123&AID=500&zx=p0b0io9ifynn&t=1
which responds with something like:
10
[1,500,0]

This is an old answer but pops up on the first Google results. Since quite a few years passed since the question was asked, Google has changed quite a few things on its website.
Currently, the ticker price can be extracted with the CSS selector, which in this case is called descendant combinator selector:
In the screenshot above I'm using SelectorGadget Chrome extension which let's pick CSS selectors by clicking on the desired element in the browser, and returns a selector afterward.
Code and example in the online IDE:
from parsel import Selector
import requests
# https://docs.python-requests.org/en/master/user/quickstart/#passing-parameters-in-urls
params = {
"hl": "en" # displayed language
}
# https://docs.python-requests.org/en/master/user/quickstart/#custom-headers
# https://www.whatismybrowser.com/detect/what-is-my-user-agent
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
}
html = requests.get(f"https://www.google.com/finance/quote/{ticker}", params=params, headers=headers, timeout=30)
selector = Selector(text=html.text)
current_price = selector.css(".AHmHk .fxKbKc::text").get()
If you need to extract more data, there's a Scrape Google Finance Ticker Data in Python blog post of mine that shows you how to get output like this one:
{
"ticker_data": {
"current_price": "$138.98",
"quote": "AAPL:NASDAQ",
"title": "Apple Inc"
},
"about_panel": {
"previous_close": "$138.98",
"year_range": "$129.04 - $182.94",
"market_cap": "2.23T USD",
"avg_volume": "95.19M",
"p/e_ratio": "22.96",
"dividend_yield": "0.66%",
"primary_exchange": "NASDAQ",
"ceo": "Tim Cook",
"founded": "Apr 1, 1976",
"headquarters": "Cupertino, CaliforniaUnited States",
"website": "apple.com",
"employees": "154,000",
"description": "Apple Inc. is an American multinational technology company that specializes in consumer electronics, software and online services headquartered in Cupertino, California, United States. Apple is the largest technology company by revenue and, as of June 2022, is the world's biggest company by market capitalization, the fourth-largest personal computer vendor by unit sales and second-largest mobile phone manufacturer. It is one of the Big Five American information technology companies, alongside Alphabet, Amazon, Meta, and Microsoft.\nApple was founded as Apple Computer Company on April 1, 1976, by Steve Jobs, Steve Wozniak and Ronald Wayne to develop and sell Wozniak's Apple I personal computer. It was incorporated by Jobs and Wozniak as Apple Computer, Inc. in 1977 and the company's next computer, the Apple II, became a best seller and one of the first mass-produced microcomputers. Apple went public in 1980 to instant financial success. The company developed computers featuring innovative graphical user interfaces, including the 1984 original Macintosh, announced that year in a critically acclaimed advertisement. ",
"extensions": [
"Most active",
"Stock",
"US listed security",
"US headquartered"
]
},
"news": {
"items": [
{
"position": 1,
"title": "Meta's new VR headset will cost $1,500 as Zuckerberg sets up battle with \nApple",
"link": "https://www.marketwatch.com/story/metas-new-vr-headset-will-cost-1-500-as-zuckerberg-sets-up-battle-with-apple-11665511178",
"source": "MarketWatch",
"published": "18 hours ago",
"thumbnail": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRjGeMvNEiJhFMgpCM3ewmD0zEzUDJfXIqR8I5EXy3eEH0F7Jo75O0Gqe6N5S8"
},
{
"position": 2,
"title": "Apple (AAPL) in Focus for US Stocks Facing Brutal Earnings Season",
"link": "https://www.bloomberg.com/news/articles/2022-10-09/apple-aapl-in-focus-for-us-stocks-facing-brutal-earnings-season",
"source": "Bloomberg.com",
"published": "2 days ago",
"thumbnail": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSIZYapO5l-u2YS_D0x3T8WaC5YHibvnDgA-SNY6Csyf16R4nFTbgbkdpC861A"
}
]
},
"finance_perfomance": {
"table": []
},
"people_also_search_for": {
"items": [
{
"position": 1,
"ticker": "AMZN",
"ticker_link": "https://www.google.com/finance/quote/AMZN:NASDAQ",
"title": "Amazon.com, Inc.",
"price": "$112.21",
"price_change": "Changed by 0.00%",
"price_change_formatted": "0.00%"
}, ...
{
"position": 18,
"ticker": "RIVN",
"ticker_link": "https://www.google.com/finance/quote/RIVN:NASDAQ",
"title": "Rivian Automotive Inc",
"price": "$32.33",
"price_change": "Changed by 0.00%",
"price_change_formatted": "0.00%"
}
]
},
"interested_in": {
"items": [
{
"position": 1,
"ticker": "Index",
"ticker_link": "https://www.google.com/finance/quote/.DJI:INDEXDJX",
"title": "Dow Jones Industrial Average",
"price": "29,239.19",
"price_change": "Changed by 0.00%",
"price_change_formatted": "0.00%"
}, ...
{
"position": 18,
"ticker": "NFLX",
"ticker_link": "https://www.google.com/finance/quote/NFLX:NASDAQ",
"title": "Netflix Inc",
"price": "$214.29",
"price_change": "Changed by 0.00%",
"price_change_formatted": "0.00%"
}
]
}
}

Related

Yahoo finance symbol suggest no longer working?

result = requests.get('http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=tesla&callback=YAHOO.Finance.SymbolSuggest.ssCallback').json()
result
When I run the python code above, I get <Response [404]>, does anyone know why that might be? I am worried this API no longer works even though I saw posts from just a year ago talking about it working.
If it's not documented, you can't rely on it working. The only (relatively) sure bet is to use some official API instead (which usually comes at a cost).
That said, if you want to continue using undocumented stuff (with the same risk of it getting shut down or you getting blocked any day), give this a try:
https://query2.finance.yahoo.com/v1/finance/search?q=tesla
(I looked at what https://finance.yahoo.com/ uses.)
This delivers results like these:
{
"explains": [],
"count": 15,
"quotes": [
{
"exchange": "NMS",
"shortname": "Tesla, Inc.",
"quoteType": "EQUITY",
"symbol": "TSLA",
"index": "quotes",
"score": 2048451,
"typeDisp": "Equity",
"longname": "Tesla, Inc.",
"exchDisp": "NASDAQ",
"isYahooFinance": true
},
{
"exchange": "NEO",
"shortname": "TESLA, INC. CDR (CAD HEDGED)",
"quoteType": "EQUITY",
"symbol": "TSLA.NE",
"index": "quotes",
"score": 24083,
"typeDisp": "Equity",
"longname": "Tesla, Inc.",
"exchDisp": "NEO",
"isYahooFinance": true
},
// ...
],
"news": [
// Also delivers news here...
],
// Some meta stuff here
}
Use at your own risk.

ElasticSearch - how to edit a field inside an array of a document

I have a document in our ElasticSearch index which looks like this:
{
"_index": "nm_doc",
"_type": "nm_doc",
"_id": "JRPXqmQBatyecf67YEfq",
"_score": 0.86147696,
"_source": {
"text": "A 29-year-old IT professional from Bhopal was convicted and sentenced to life imprisonment by an Additional Sessions Court in Pune on Wednesday for the rape and brutal murder of a woman in 2008, after she had refused his advances. Watch What Else is Making News The court found Manu Mohinder Ebrol, who worked in the same firm as the girl, of raping and killing the woman after stabbing her 18 times on the night of October 20, 2008, in her rented apartment. After committing the crime, Ebrol had fled to Bhopal. He was arrested later by Pune Police. The prosecution examined 26 witnesses for the case and forensic evidence such as call details and medical records also proved crucial. For all the latest Pune News , download Indian Express App",
"entities": [
{
"name": "Mohinder Ebrol"
},
{
"name": "Sessions Court"
},
{
"name": "Pune Police"
},
{
"name": "Pune News"
},
{
"name": "Indian Express"
}
]
}
If I wanted to edit just the first name in that array (Mohinder Ebrol) to be Manu Ebrol, how would I accomplish this via API call? Do I need to pass in the entire array to update the one name?
I have figured it out via the documentation:
The call Url is:
POST http://elastichost:9200/indexname/_doc/JRPXqmQBatyecf67YEfq/_update?pretty
And the body simply looks like this (yes, you do have to provide the entire array):
{
"doc": { "entities": [
{
"name": "Manu Ebrol"
},
{
"name": "Sessions Court"
},
{
"name": "Pune Police"
},
{
"name": "Pune News"
},
{
"name": "Indian Express"
}
] }
}
Hope this can help someone in the future.

Skype not showing images recieved

I am trying to create a bot and deploy it onto different platforms, but when I return images in the carousel for the chatbot, Skype doesn't render them, while the same works for Facebook and even on the web widget provided by Gupshup.
If you want to know the chatbot platform i'm using it would be Gupshup with api.ai hooked for nlp , do you know the problem i am encountering?
I have tried different ways of getting the image. First I got it from the site I am making the chatbot for, then I tried shortening the url using google and finally I tried uploading the image on Google drive.The image format is jpg could that be the issue?
http://imgur.com/a/19aG3
[Update:7/5/2017] - Skype issue is now resolved. The carousel code that is working for Facebook Messenger will also work for Skype.
Sample JSON for Carousel on Skype:
{
"type": "catalogue",
"msgid": "cat_212",
"items": [{
"title": "White T Shirt",
"subtitle": "Soft cotton t-shirt \nXs, S, M, L \n$10",
"imgurl": "https://pixel.nymag.com/imgs/fashion/daily/2016/06/02/t-shirt/everlane.w710.h473.2x.jpg",
"options": [{
"type": "url",
"title": "View Details",
"url": "https://pixel.nymag.com/imgs/fashion/daily/2016/06/02/t-shirt/everlane.w710.h473.2x.jpg"
},
{
"type": "text",
"title": "Buy"
}
]
},
{
"title": "Grey T Shirt",
"subtitle": "Soft cotton t-shirt \nXs, S, M, L \n$12",
"imgurl": "https://cdn.shopify.com/s/files/1/0407/0829/products/Grey_t-shirt_front_1024x1024.jpg?v=1466588290",
"options": [{
"type": "url",
"title": "View Details",
"url": "https://cdn.shopify.com/s/files/1/0407/0829/products/Grey_t-shirt_front_1024x1024.jpg?v=1466588290"
},
{
"type": "text",
"title": "Buy"
}
]
}
]}
Result:
Images are not loading for the carousel on Skype because there have
been recent changes in Microsoft framework which are not yet
incorporated in Gupshup's bot platform. Although next week you should
be able to see those images load once we at Gupshup pushes the fix
into production. There will be no need of changing the code from your
end as the same code for carousel works across the supported
platforms.
I will update this answer once the fix is live into production.
PS: I work for Gupshup.

Google Places API: Get all the User's Reviews

We are working with google places api. we want to view all the user's reviews of a business in google place but we noticed that the documentation says that it only returns an array of five user's reviews.
Now, we want to know is there any way to get all user's reviews?
To get all the reviews of any place you would have to use a third party solution like SerpApi. It's a paid API with a free trial.
Each page fatches 10 results. To implement the pagination just use the start parameter which defines the result offset (e.g., 0 (default) is the first page of results, 10 is the 2nd page of results, 20 is the 3rd page of results, etc.).
Example python code (available in other libraries also):
require 'path/to/google_search_results';
$query = [
"engine" => "google_maps_reviews",
"place_id" => "0x89c259a61c75684f:0x79d31adb123348d2",
"api_key" => "SECRET_API_KEY"
];
$search = new GoogleSearch();
$results = $search->json($query);
$reviews = $result->reviews;
Example JSON output:
"reviews": [
{
"user": {
"name": "Waylon Bilbrey",
"link": "https://www.google.com/maps/contrib/107691056156160235121?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARAx",
"thumbnail": "https://lh3.googleusercontent.com/a-/AOh14GjOj6Wjfk1kSYjhvH7WIBNMdl4nPj6FvUhvYcR6=s40-c0x00000000-cc-rp",
"reviews": 1
},
"rating": 4,
"date": "a week ago",
"snippet": "I've been here multiple times. The coffee itself is just average to me. The service is good (the people working are nice). The aesthetic is obviously what brings the place some fame. A little overpriced (even for NY). A very small cup for $6 where I feel like the price comes from the top rainbow foam decor , when I'm going to cover it anyways. If it's for an insta pic then it may be worth it?"
},
{
"user": {
"name": "Amber Grace Sale",
"link": "https://www.google.com/maps/contrib/106390058588469541899?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARA7",
"thumbnail": "https://lh3.googleusercontent.com/a-/AOh14Gj84nHu_9V_0V4yRbZcr-8ZTYAHua6gUBP8fC7W=s40-c0x00000000-cc-rp-ba3",
"local_guide": true,
"reviews": 33,
"photos": 17
},
"rating": 5,
"date": "2 years ago",
"snippet": "They really take pride in their espresso roast here and the staff is extremely knowledgeable on the subject. It’s also a GREAT place to do work although a table is no guarantee; you might have to wait for a bit. My almond milk cappuccino was very acidic at the end which wasn’t expected but I could still tell the bean was high quality. Their larger lattés they put in a tall glass cup which looks really really cool. Would definitely go again.",
"likes": 2,
"images": [
"https://lh5.googleusercontent.com/p/AF1QipMup24_dHrWtNN4ZD70EPsiRMf_tykcUkPw6A1H=w100-h100-p-n-k-no"
]
},
{
"user": {
"name": "Kelvin Petar",
"link": "https://www.google.com/maps/contrib/100859090874785206875?hl=en-US&sa=X&ved=2ahUKEwiUituIlpTvAhVYCc0KHbvTCrgQvvQBegQIARBG",
"thumbnail": "https://lh3.googleusercontent.com/a-/AOh14GhdIvUDamzfPqbYIpwhnGJV2XWSi77iVXfEsiKS=s40-c0x00000000-cc-rp",
"reviews": 3
},
"rating": 4,
"date": "3 months ago",
"snippet": "Stumptown Cafe is the perfect place to work or catch up with friends. Never too loud, never too dead. Their lattes and deliciously addicting and the toasts are tasty as well. Wifi is always fast, which is a huge plus! The staff are the friendliest, I highly recommend this place!"
},
...
]
You can check out the documentation for more details.
Disclaimer: I work at SerpApi.

how to restrict price range in google shopping API

I'm using the Google Shopping API to try to retrieve products that have an "order" of magnitud of a certain number, or approximation to this. For example If I would to select products that are between th $40 - $60 price range : $50 +/- $10. What should I add in the URL search string?
I know I can rank by price like this (according to the API):
GET https://www.googleapis.com/shopping/search/v1/public/products?key=key&country=US&q=%22mp3+player%22%7Cipod&rankBy=price%3Adescending
Nevermind, the correct way to do this was using flask and jinja2 along with ajax. One has to be aware of using JSON and how it maps correctly to its equivalent python objects, when using the google shopping API main 'items' objects :
"product": {
"googleId": "9243781955569725518",
"author": {
"name": "CompUPlus.com",
"accountId": "1209120"
},
"creationTime": "2010-03-04T09:51:45.000Z",
"modificationTime": "2010-11-25T09:24:08.000Z",
"language": "en",
"country": "US",
"title": "Logitech Squeezebox Radio, black",
"description": "Logitech Squeezebox Radio brings a world of free Internet radio subscription
services and your personal digital music collection to any space in your home
over your Wi-Fi network.",
"link": "http://www.compuplus.com/Radios/LOGITECH-Squeezebox-Radio-BLK-930-1115160.html",
"gtin": "00097855063601",
"gtins": [
"00097855063601"
],
"brand": "Logitech",
"mpn": "930-000101",
"condition": "new",
"images": [
{ "link": "http://content.etilize.com/300/1014430207.jpg" }
]
"inventories": [
{
"channel": "online",
"availability": "inStock",
"currency": "usd",
"price": 183.19
}
],
}

Resources