Initial commit
Same as what's on PyPI, just the working version
This commit is contained in:
commit
72dce18c5c
70
PKG-INFO
Normal file
70
PKG-INFO
Normal file
|
@ -0,0 +1,70 @@
|
|||
Metadata-Version: 2.1
|
||||
Name: stockquotes
|
||||
Version: 1.0.5
|
||||
Summary: A simple module for retreiving stock data
|
||||
Home-page: UNKNOWN
|
||||
License: UNKNOWN
|
||||
Description: `stockquotes` is a simple Python module for collecting stock quotes and historical data from Yahoo! Finance. It's perfect for developers who can't afford the (often steep) prices charged by many stock data APIs.
|
||||
# Requirements
|
||||
* Python 3.6+
|
||||
* Beautiful Soup 4
|
||||
# Installation
|
||||
pip3 install stockquotes
|
||||
# Usage
|
||||
First, import the `stockquotes` module.
|
||||
|
||||
import stockquotes
|
||||
|
||||
To get a stock quote, instantiate a `stockquotes.Stock` object. The only parameter is the ticker symbol to look up.
|
||||
|
||||
kroger = stockquotes.Stock('KR')
|
||||
|
||||
## Basic data
|
||||
To get the current price of a share, get the `Stock`'s `currentPrice`.
|
||||
|
||||
krogerPrice = kroger.currentPrice
|
||||
|
||||
To get the day gain in dollars, get the `Stock`'s `increaseDollars`.
|
||||
|
||||
krogerGainDollars = kroger.increaseDollars
|
||||
|
||||
The same value as a percent is available in the `increasePercent` property. To indicate losses, these values are negative.
|
||||
|
||||
## Historical data
|
||||
The historical data for a stock can be accessed through the `Stock`'s `historical` property. This is an array of `dict`s, with the first item representing the most recent quote. The `dict`'s `date` property is a `datetime` object representing the date the quote is from. `open` is the opening price for that day. `high` and `low` are the high and low prices, respectively, for that day. `close` and `adjClose` are the closing price. The difference is that `adjClose` is adjusted for splits and dividends, whereas `close` is adjusted only for splits. `volume` is the stock's volume for that day.
|
||||
# Exceptions
|
||||
`stockquotes.StockDoesNotExistError` is raised when the stock does not exist.
|
||||
`stockquotes.NetworkError` is raised when a connection to Yahoo! Finance cannot be established.
|
||||
# License
|
||||
Copyright (c) 2019 ScoopGracie. All rights reversed.
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org/>
|
||||
|
||||
|
||||
Platform: UNKNOWN
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Operating System :: OS Independent
|
||||
Requires-Python: >=3.0
|
||||
Description-Content-Type: text/markdown
|
58
README.md
Normal file
58
README.md
Normal file
|
@ -0,0 +1,58 @@
|
|||
`stockquotes` is a simple Python module for collecting stock quotes and historical data from Yahoo! Finance. It's perfect for developers who can't afford the (often steep) prices charged by many stock data APIs.
|
||||
# Requirements
|
||||
* Python 3.6+
|
||||
* Beautiful Soup 4
|
||||
# Installation
|
||||
pip3 install stockquotes
|
||||
# Usage
|
||||
First, import the `stockquotes` module.
|
||||
|
||||
import stockquotes
|
||||
|
||||
To get a stock quote, instantiate a `stockquotes.Stock` object. The only parameter is the ticker symbol to look up.
|
||||
|
||||
kroger = stockquotes.Stock('KR')
|
||||
|
||||
## Basic data
|
||||
To get the current price of a share, get the `Stock`'s `currentPrice`.
|
||||
|
||||
krogerPrice = kroger.currentPrice
|
||||
|
||||
To get the day gain in dollars, get the `Stock`'s `increaseDollars`.
|
||||
|
||||
krogerGainDollars = kroger.increaseDollars
|
||||
|
||||
The same value as a percent is available in the `increasePercent` property. To indicate losses, these values are negative.
|
||||
|
||||
## Historical data
|
||||
The historical data for a stock can be accessed through the `Stock`'s `historical` property. This is an array of `dict`s, with the first item representing the most recent quote. The `dict`'s `date` property is a `datetime` object representing the date the quote is from. `open` is the opening price for that day. `high` and `low` are the high and low prices, respectively, for that day. `close` and `adjClose` are the closing price. The difference is that `adjClose` is adjusted for splits and dividends, whereas `close` is adjusted only for splits. `volume` is the stock's volume for that day.
|
||||
# Exceptions
|
||||
`stockquotes.StockDoesNotExistError` is raised when the stock does not exist.
|
||||
`stockquotes.NetworkError` is raised when a connection to Yahoo! Finance cannot be established.
|
||||
# License
|
||||
Copyright (c) 2019 ScoopGracie. All rights reversed.
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org/>
|
||||
|
16
setup.py
Normal file
16
setup.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import setuptools
|
||||
with open('README.md', 'r') as fh:
|
||||
long_description = fh.read()
|
||||
setuptools.setup(
|
||||
name='stockquotes',
|
||||
version='1.0.5',
|
||||
description='A simple module for retreiving stock data',
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
packages=setuptools.find_packages(),
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"Operating System :: OS Independent"
|
||||
],
|
||||
python_requires='>=3.0'
|
||||
)
|
70
stockquotes.egg-info/PKG-INFO
Normal file
70
stockquotes.egg-info/PKG-INFO
Normal file
|
@ -0,0 +1,70 @@
|
|||
Metadata-Version: 2.1
|
||||
Name: stockquotes
|
||||
Version: 1.0.5
|
||||
Summary: A simple module for retreiving stock data
|
||||
Home-page: UNKNOWN
|
||||
License: UNKNOWN
|
||||
Description: `stockquotes` is a simple Python module for collecting stock quotes and historical data from Yahoo! Finance. It's perfect for developers who can't afford the (often steep) prices charged by many stock data APIs.
|
||||
# Requirements
|
||||
* Python 3.6+
|
||||
* Beautiful Soup 4
|
||||
# Installation
|
||||
pip3 install stockquotes
|
||||
# Usage
|
||||
First, import the `stockquotes` module.
|
||||
|
||||
import stockquotes
|
||||
|
||||
To get a stock quote, instantiate a `stockquotes.Stock` object. The only parameter is the ticker symbol to look up.
|
||||
|
||||
kroger = stockquotes.Stock('KR')
|
||||
|
||||
## Basic data
|
||||
To get the current price of a share, get the `Stock`'s `currentPrice`.
|
||||
|
||||
krogerPrice = kroger.currentPrice
|
||||
|
||||
To get the day gain in dollars, get the `Stock`'s `increaseDollars`.
|
||||
|
||||
krogerGainDollars = kroger.increaseDollars
|
||||
|
||||
The same value as a percent is available in the `increasePercent` property. To indicate losses, these values are negative.
|
||||
|
||||
## Historical data
|
||||
The historical data for a stock can be accessed through the `Stock`'s `historical` property. This is an array of `dict`s, with the first item representing the most recent quote. The `dict`'s `date` property is a `datetime` object representing the date the quote is from. `open` is the opening price for that day. `high` and `low` are the high and low prices, respectively, for that day. `close` and `adjClose` are the closing price. The difference is that `adjClose` is adjusted for splits and dividends, whereas `close` is adjusted only for splits. `volume` is the stock's volume for that day.
|
||||
# Exceptions
|
||||
`stockquotes.StockDoesNotExistError` is raised when the stock does not exist.
|
||||
`stockquotes.NetworkError` is raised when a connection to Yahoo! Finance cannot be established.
|
||||
# License
|
||||
Copyright (c) 2019 ScoopGracie. All rights reversed.
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org/>
|
||||
|
||||
|
||||
Platform: UNKNOWN
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Operating System :: OS Independent
|
||||
Requires-Python: >=3.0
|
||||
Description-Content-Type: text/markdown
|
8
stockquotes.egg-info/SOURCES.txt
Normal file
8
stockquotes.egg-info/SOURCES.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
README.md
|
||||
setup.py
|
||||
stockquotes/__init__.py
|
||||
stockquotes/script.py
|
||||
stockquotes.egg-info/PKG-INFO
|
||||
stockquotes.egg-info/SOURCES.txt
|
||||
stockquotes.egg-info/dependency_links.txt
|
||||
stockquotes.egg-info/top_level.txt
|
1
stockquotes.egg-info/dependency_links.txt
Normal file
1
stockquotes.egg-info/dependency_links.txt
Normal file
|
@ -0,0 +1 @@
|
|||
|
1
stockquotes.egg-info/top_level.txt
Normal file
1
stockquotes.egg-info/top_level.txt
Normal file
|
@ -0,0 +1 @@
|
|||
stockquotes
|
76
stockquotes/__init__.py
Normal file
76
stockquotes/__init__.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env python3
|
||||
#stockquotes - Python module to pull stock quotes from Yahoo! Finance
|
||||
#Copyright 2019 ScoopGracie. All rights reversed.
|
||||
#This is free and unencumbered software released into the public domain.
|
||||
|
||||
#Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
#distribute this software, either in source code form or as a compiled
|
||||
#binary, for any purpose, commercial or non-commercial, and by any
|
||||
#means.
|
||||
|
||||
#In jurisdictions that recognize copyright laws, the author or authors
|
||||
#of this software dedicate any and all copyright interest in the
|
||||
#software to the public domain. We make this dedication for the benefit
|
||||
#of the public at large and to the detriment of our heirs and
|
||||
#successors. We intend this dedication to be an overt act of
|
||||
#relinquishment in perpetuity of all present and future rights to this
|
||||
#software under copyright law.
|
||||
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
#MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
#IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
#OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
#ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
#OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from bs4 import BeautifulSoup as bs
|
||||
import requests, datetime
|
||||
class StockDoesNotExistError(Exception):
|
||||
pass
|
||||
class NetworkError(Exception):
|
||||
pass
|
||||
class Stock:
|
||||
def __init__(self, ticker):
|
||||
try:
|
||||
r=requests.get('https://finance.yahoo.com/quote/' + ticker + '/history', headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3941.4 Safari/537.36'})
|
||||
except:
|
||||
raise NetworkError()
|
||||
if r.status_code is 302:
|
||||
raise StockDoesNotExistError(ticker)
|
||||
try:
|
||||
soup = bs(r.text, features="lxml")
|
||||
self.symbol = soup.h1.string.split('(')[1].split(')')[0]
|
||||
self.name = soup.h1.string.split('(')[0].strip()
|
||||
rows = soup.table.tbody.find_all('tr')
|
||||
self.historical=[]
|
||||
for i in rows:
|
||||
row=i.find_all('td')
|
||||
try:
|
||||
parsed = {
|
||||
"date" : datetime.datetime.strptime(
|
||||
row[0].span.string,
|
||||
'%b %d, %Y'
|
||||
),
|
||||
"open" : float(row[1].span.string.replace(',', '')),
|
||||
"high" : float(row[2].span.string.replace(',', '')),
|
||||
"low" : float(row[3].span.string.replace(',', '')),
|
||||
"close" : float(row[4].span.string.replace(',', '')),
|
||||
"adjClose": float(row[5].span.string.replace(',', '')),
|
||||
"volume" : int(row[6].span.string.replace(',', ''))
|
||||
}
|
||||
except:
|
||||
continue
|
||||
self.historical.append(parsed)
|
||||
topData = soup.find(id='quote-header-info')
|
||||
try:
|
||||
self.currentPrice = float(topData.findAll('span')[11].string.replace(',', ''))
|
||||
rawChange = topData.findAll('span')[12].string
|
||||
except IndexError:
|
||||
self.currentPrice = float(topData.findAll('span')[3].string.replace(',', ''))
|
||||
rawChange = topData.findAll('span')[4].string
|
||||
|
||||
self.increaseDollars = float(rawChange.split(' ')[0].replace(',', ''))
|
||||
self.increasePercent = float(rawChange.split(' ')[1].replace(',', '').replace('(', '').replace(')', '').replace('%', ''))
|
||||
except AttributeError as error:
|
||||
raise StockDoesNotExistError(ticker) from error
|
Loading…
Reference in New Issue
Block a user