-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadPrices.py
93 lines (70 loc) · 2.69 KB
/
LoadPrices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
###########################################################################
# logging
# https://docs.python.org/3/howto/logging.html#logging-advanced-tutorial
###########################################################################
import sys
import logging
import platform
LOGNAME = 'LoadPrices'
LOGFILE = 'out.log'
LOGFORMAT = '%(asctime)s %(levelname)5s [%(filename)-15s %(lineno)4s %(funcName)-25s] %(message)s'
LOGLEVEL = logging.DEBUG
LOGENABLED = True # set to False to disable logfile
def createLogger(logname, logfile, logformat, loglevel, enabled):
Logger = logging.getLogger(logname)
Logger.setLevel(loglevel)
if enabled:
tmp = logging.FileHandler(logfile)
tmp.setFormatter(logging.Formatter(logformat))
Logger.addHandler(tmp)
return Logger
Logger = createLogger(LOGNAME, LOGFILE, LOGFORMAT, LOGLEVEL, LOGENABLED)
Logger.info("Start")
Logger.info("Platform: " + ' '.join(platform.uname()))
Logger.info("Python: " + str(sys.version))
###########################################################################
# embedded zip archive pythonpath
###########################################################################
PYTHONPATH = '/Scripts/python/pythonpath'
def prependPath(newpath):
import uno
doc = XSCRIPTCONTEXT.getDocument()
pythonpath = uno.fileUrlToSystemPath(doc.URL) + newpath
if pythonpath not in sys.path:
sys.path.insert(0, pythonpath)
prependPath(PYTHONPATH)
Logger.info("Path: " + str(sys.path))
# import embedded
from sites import Yahoo
from spreadsheet.api.factory import spreadsheet_api
###########################################################################
# the macros
###########################################################################
API = spreadsheet_api('libreoffice', docroot=XSCRIPTCONTEXT)
def get_yahoo_stocks(*args):
get = Yahoo(API)
try:
get.stock(sheet='Sheet1', keyrange='A1:A200', datacols=['B', 'C'])
API.show_box("Processing finished", "Status")
except Warning as e:
API.show_box(str(e), "Web error")
def get_yahoo_fx(*args):
get = Yahoo(API)
try:
get.fx(sheet='Sheet1', keyrange='E1:G200', datacols=['F'])
API.show_box("Processing finished", "Status")
except Warning as e:
API.show_box(str(e), "Web error")
def get_yahoo_indices(*args):
get = Yahoo(API)
try:
get.index(sheet='Sheet1', keyrange='H1:H200', datacols=['I', 'J'])
API.show_box("Processing finished", "Status")
except Warning as e:
API.show_box(str(e), "Web error")
g_exportedScripts = (
get_yahoo_stocks,
get_yahoo_fx,
get_yahoo_indices,
)
###########################################################################