Skip to content

Commit

Permalink
Add python based logging to extension.
Browse files Browse the repository at this point in the history
Add suppport to get historical quotes from the Intrinio service
  • Loading branch information
dhocker committed Jun 26, 2017
1 parent b1ce1d2 commit 9228094
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 97 deletions.
23 changes: 16 additions & 7 deletions README.md
@@ -1,10 +1,11 @@
SMF Extension for LibreOffice Calc
===
SMF Extension for LibreOffice Calc (Forked Version)
===================================================
The SMF extension allows you to create customized spreadsheets with stock market data directly from the web.
Currently supported online sources include
* [Morningstar](http://morningstar.com)
* [Yahoo Finance](http://finance.yahoo.com)
* [Google Historical Finance](http://www.google.com/finance/historical)
* [Intrinio](https://www.intrinio.com)

### Download
You can download the latest version of the SMF Extension [here](https://github.com/dhocker/SMF-Extension/releases/latest).
Expand All @@ -13,13 +14,14 @@ You can download the latest version of the SMF Extension [here](https://github.c

### Usage

The SMF Extension adds four new functions to Calc:
The SMF Extension adds several new functions to Calc:
```
GETYAHOO(Ticker,Datacode)
GETMORNINGKEY(Ticker,Datacode)
GETMORNINGFIN(Ticker,Datacode)
GETMORNINGQFIN(Ticker,Datacode)
GETHISTORICALQUOTE(Ticker, Date)
GETINTRINIOQUOTE(Ticker, Date)
```

Quotes **must** be used when entering the ticker directly ex: ```GETYAHOO("AAPL",1)```, but are **not** needed when referencing another cell ex: ```GETYAHOO(A1,1)```.
Expand All @@ -33,8 +35,16 @@ Dates should be in ISO format YYYY-MM-DD.
### Notes

Somewhere around 5/15/2017 Yahoo terminated its historical stock data service. As a result the Yahoo historical data
function was removed and partially replaced by a Google based function that can return the closing price
for a given stock on a given date.
function was removed and partially replaced by two new functions.

* A Google based function that can return the closing price for a given stock on a given date.
* An [Intrinio](https://www.intrinio.com) based function that can return the closing price for a given stock on a given date.

Intrinio is a relatively new service that can provide a vast amount of stock
market related data. Some data is free (like the API used to get historical stock quotes) but
has limitations on quantity. For example, with a free account you can request 500 data points
per day. While the free account has limitations, the service is reliable.
Refer to the web site for details.

### Support

Expand Down Expand Up @@ -63,9 +73,8 @@ The SMF Extension is released under the [![][shield:LGPL3]][License:3.0] which i
* Villeroy - conversion from string to float to make the extension useful
* karolus - optimization of keymapping code
* Corey Goldberg - Inspiration with the Yahoo portion of the extension
* Dave Hocker - Google Financial Historical data support
* Dave Hocker - Google Financial Historical data support, Intrinio historical data support.

[GIT:release]: http://github.com/madsailor/SMF-Extension/releases/latest
[License:3.0]: http://www.gnu.org/licenses/lgpl.html
[shield:release-latest]: http://img.shields.io/github/release/madsailor/SMF-Extension.svg
[shield:LGPL3]: http://img.shields.io/badge/license-LGPL%20v.3-blue.svg
3 changes: 2 additions & 1 deletion compile.sh
Expand Up @@ -7,7 +7,7 @@ export PATH=$PATH:/usr/lib/ure/bin/
#export PATH=$PATH:/usr/lib/libreoffice/sdk/bin/
# They were here...
#export PATH=$PATH:/usr/local/share/libreoffice/bin
export PATH=$PATH:/Users/dhocker/LibreOffice5.2_SDK/bin
export PATH=$PATH:/Users/dhocker/LibreOffice5.3_SDK/bin
# This addition was required to make the script work with
# SDK 5.2
export DYLD_LIBRARY_PATH=$OO_SDK_URE_LIB_DIR
Expand All @@ -28,6 +28,7 @@ cp -f "${PWD}"/src/yahoo.py "${PWD}"/SMF/
cp -f "${PWD}"/src/advfn.py "${PWD}"/SMF/
cp -f "${PWD}"/src/yahoo_hist.py "${PWD}"/SMF/
cp -f "${PWD}"/src/html_hist_quote.py "${PWD}"/SMF/
cp -f "${PWD}"/src/app_logger.py "${PWD}"/SMF/
cp -f "${PWD}"/src/description-en-US.txt "${PWD}"/SMF/
python "${PWD}"/src/generate_metainfo.py

Expand Down
5 changes: 5 additions & 0 deletions examples/intrinio.conf
@@ -0,0 +1,5 @@
{
"user":"intrinio-user-id",
"password":"intrinio-password",
"certifi":"/for/macOS/path/to/certifi/cacert.pem"
}
2 changes: 2 additions & 0 deletions idl/Xsmf.idl
Expand Up @@ -16,6 +16,8 @@ module com { module smf { module ticker { module getinfo {
any getYahooHist( [in] string a, [in] string b, [in] string c );
// ticker, date
any getHistoricalQuote( [in] string a, [in] any b );
// ticker, date
any getIntrinioQuote( [in] string a, [in] any b );
};

}; }; }; };
61 changes: 61 additions & 0 deletions src/app_logger.py
@@ -0,0 +1,61 @@
#
# Python logging for LO extension
# Copyright (C) 2017 Dave Hocker as TheAgency (AtHomeX10@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# See the LICENSE file for more details.
#

import logging
import logging.handlers
import os


########################################################################
# Enable logging for the extension
def EnableLogging():
# Default overrides
logformat = '%(asctime)s, %(module)s, %(levelname)s, %(message)s'
logdateformat = '%Y-%m-%d %H:%M:%S'

# Logging level override
loglevel = logging.DEBUG
# loglevel = logging.INFO
# loglevel = logging.WARNING
# loglevel = logging.ERROR

logger = logging.getLogger("smf-extension")
logger.setLevel(loglevel)

formatter = logging.Formatter(logformat, datefmt=logdateformat)

# Log to a file
# Make logfile location OS specific
if os.name == "posix":
# Linux or OS X
file_path = "{0}/libreoffice/intrinio/".format(os.environ["HOME"])
elif os.name == "nt":
# Windows
file_path = "{0}\\libreoffice\\intrinio\\".format(os.environ["HOMEPATH"])
logfile = file_path + "smf-extension.log"

fh = logging.handlers.TimedRotatingFileHandler(logfile, when='midnight', backupCount=3)
fh.setLevel(loglevel)
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.debug("Logging to file: %s", logfile)

def getAppLogger():
"""
Return an instance of the default logger for this app.
:return: logger instance
"""
return logging.getLogger("smf-extension")

# Controlled logging shutdown
def Shutdown():
getAppLogger().debug("Logging shutdown")
logging.shutdown()
2 changes: 1 addition & 1 deletion src/description-en-US.txt
@@ -1,2 +1,2 @@
The SMF Extension enables you to create spreadsheets with stock market data pulled directly from the web.
Currently supported sources include Yahoo Finance, Google Finance, Morningstar, and ADVFN.
Currently supported sources include Yahoo Finance, Google Finance, Intrinio, Morningstar, and ADVFN.
24 changes: 16 additions & 8 deletions src/generate_metainfo.py
Expand Up @@ -16,11 +16,13 @@

# A unique ID for the extension.
addin_id = "com.smf.ticker.getinfo"
addin_version = "0.8.7"
addin_displayname = "Forked Version of Stock Market Function Extension."
addin_version = "0.9.3"
addin_displayname = "Stock Market Function Extension (Forked Version)"
addin_publisher_link = "https://github.com/dhocker/SMF-Extension"
addin_publisher_name = "TheAgency"

print ("Generating extension files for version", addin_version)

# description.xml
#
#
Expand All @@ -30,27 +32,29 @@
desc_xml.write('<?xml version="1.0" encoding="UTF-8"?>\n')
desc_xml.write('<description xmlns="http://openoffice.org/extensions/description/2006" \n')
desc_xml.write('xmlns:d="http://openoffice.org/extensions/description/2006" \n')
desc_xml.write('xmlns:l="http://libreoffice.org/extensions/description/2011" \n')
desc_xml.write('xmlns:xlink="http://www.w3.org/1999/xlink"> \n' + '\n')
desc_xml.write('<dependencies> \n')
desc_xml.write(' <OpenOffice.org-minimal-version value="2.4" d:name="OpenOffice.org 2.4"/> \n')
desc_xml.write(' <l:LibreOffice-minimal-version value="5.0" d:name="LibreOffice 5.0" /> \n')
desc_xml.write('</dependencies> \n')
desc_xml.write('\n')
desc_xml.write('<identifier value="' + addin_id + '" /> \n')
desc_xml.write('<version value="' + addin_version + '" />\n')
desc_xml.write('<display-name><name lang="en">' + addin_displayname + '</name></display-name>\n')
desc_xml.write('<publisher><name xlink:href="' + addin_publisher_link + '" lang="en">' + addin_publisher_name + '</name></publisher>\n')
desc_xml.write('<extension-description><src xlink:href="description-en-US.txt" lang="en" /></extension-description>')
desc_xml.write('\n')
desc_xml.write('</description> \n')

desc_xml.close
desc_xml.close()

def add_manifest_entry(xml_file, file_type, file_name):
xml_file.write('<manifest:file-entry manifest:media-type="application/vnd.sun.star.' + file_type + '" \n')
xml_file.write(' manifest:full-path="' + file_name + '"/> \n')

# manifest.xml
#
# List of files in package and their types.
#

manifest_xml = open(cur_dir + '/SMF/META-INF/manifest.xml', 'w')

Expand All @@ -60,7 +64,7 @@ def add_manifest_entry(xml_file, file_type, file_name):
add_manifest_entry(manifest_xml, 'uno-component;type=Python', 'smf.py')
manifest_xml.write('</manifest:manifest> \n')

manifest_xml.close
manifest_xml.close()

# SMF.xcu
#
Expand Down Expand Up @@ -117,14 +121,18 @@ def define_function(xml_file, function_name, description, parameters):
[('a', 'The ticker symbol.'), ('b', 'The date.'), ('c', 'The data name or code.')])

define_function(smf_xml, \
'getHistoricalQuote', 'Fetches Historical Closing Quote', \
'getHistoricalQuote', 'Fetches Historical Closing Quote from Google', \
[('a', 'The ticker symbol.'), ('b', 'The date.')])

define_function(smf_xml, \
'getIntrinioQuote', 'Fetches Historical Closing Quote from Intrinio', \
[('a', 'The ticker symbol.'), ('b', 'The date.')])

smf_xml.write('</node>\n')
smf_xml.write('</node>\n')
smf_xml.write('</node>\n')
smf_xml.write('</oor:component-data>\n')

smf_xml.close
smf_xml.close()

# Done

0 comments on commit 9228094

Please sign in to comment.