Try accessing the YQL API directly from Python 3

import json
import urllib.parse
import urllib.request

def send(query, fmt='json'):
    """send query to yahoo api"""
    response = urllib.request.urlopen(__urlbuilder(query, fmt))
    data = json.loads(response.read().decode('utf-8'))
    return data

def __urlbuilder(yql_query, fmt):
    """urlencode yql query"""
    base_url = 'https://query.yahooapis.com/v1/public/yql?'
    query = {
        'q': yql_query,
        'format': fmt,
        'env': 'store://datatables.org/alltableswithkeys'
        }
    url = base_url + urllib.parse.urlencode(query)
    return url

if __name__ == '__main__':
    data = send(query = 'select * from yahoo.finance.historicaldata where symbol in ("EUR=X") and startDate = "2014-01-01" and endDate = "2014-12-31"')
    quotes = data['query']['results']['quote']
    print(quotes)

Recommended Posts

Try accessing the YQL API directly from Python 3
Use the Flickr API from Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try hitting the YouTube API in Python
Try using the DropBox Core API in Python
[Python] Get the text of the law from the e-GOV Law API
A little bit from Python using the Jenkins API
Try using the Twitter API
Try using the Twitter API
Call the API with python3.
Use e-Stat API from Python
Try hitting the Twitter API quickly and easily with Python
Get your heart rate from the fitbit API in Python!
Recursively copy files from the directory directly under the directory using Python
Hit the Sesami API in Python
Try the Python LINE Pay SDK
[Python] Hit the Google Translation API
Try using Pleasant's API (python / FastAPI)
Use kabu Station® API from Python
Hit the web API in Python
Get upcoming weather from python weather api
Try using Python argparse's action API
Notes on accessing dashDB from python
Try using the Python Cmd module
Access the Twitter API in Python
Use Google Analytics API from Python
Handle SOAP API from Python (Zeep)
Try using Amazon DynamoDB from Python
[Python] Try to graph from the image of Ring Fit [OCR]
How to get followers and followers from python using the Mastodon API
Let's touch Google's Vision API from Python for the time being
Collecting information from Twitter with Python (Twitter API)
[Python] Web application from 0! Hands-on (3) -API implementation-
Learning notes from the beginning of Python 1
Try the Microsoft Cognitive Services Face API
Try python
Tweet using the Twitter API in Python
Try using the Python web framework Django (1)-From installation to server startup
[Python] Try pydash of the Python version of lodash
I tried using UnityCloudBuild API from Python
Quickly try Microsoft's Face API in Python
Launch the Python interpreter from Git bash
Python amateurs try to summarize the list â‘ 
From Python 3.4, pip becomes the standard installer! ??
API explanation to touch mastodon from python
Learning notes from the beginning of Python 2
[Python] Get the main color from the screenshot
Try hitting the Spotify API in Django.
Connect to coincheck's Websocket API from Python
Region extraction method using cellular automaton Try region extraction from the image with growcut (Python)
Put the exchange rate obtained from Oanda REST API in Python into MongoDB
Try the python version of emacs-org parser orgparse
I tried hitting the Qiita API from go
Created a Python wrapper for the Qiita API
Try to solve the Python class inheritance problem
[Cloudian # 7] Try deleting the bucket in Python (boto3)
Try operating Studio Library from Python. [Anim Save]
Try to solve the man-machine chart with Python
Python: Try using the UI on Pythonista 3 on iPad
Try using the Python web framework Tornado Part 1