yfinance-exporter 1.0.5__py3-none-any.whl → 1.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
|
|
1
|
+
yfinance_exporter.py,sha256=2z-RR1kwyXqKnAsc_TmUJTGhvylMN6daNNMaSGxcsb0,4179
|
2
|
+
yfinance_exporter-1.0.7.dist-info/METADATA,sha256=xNxqoFlOunh-BktPy4mOFuQfq0mFJTqImCUh79_RLik,1525
|
3
|
+
yfinance_exporter-1.0.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
4
|
+
yfinance_exporter-1.0.7.dist-info/RECORD,,
|
yfinance_exporter.py
CHANGED
@@ -62,8 +62,8 @@ STOCK = Gauge(
|
|
62
62
|
)
|
63
63
|
|
64
64
|
|
65
|
-
def collect(stock):
|
66
|
-
logger.debug("
|
65
|
+
def collect(stock) -> bool:
|
66
|
+
logger.debug("%r: Collecting", stock.name)
|
67
67
|
labels = [
|
68
68
|
stock.ycode.split(".")[1] if "." in stock.ycode else "",
|
69
69
|
"stocks",
|
@@ -77,17 +77,34 @@ def collect(stock):
|
|
77
77
|
try:
|
78
78
|
value = ticker.fast_info["last_price"]
|
79
79
|
except KeyError:
|
80
|
+
logger.warning("%r: no value from yfinance", stock.name)
|
80
81
|
value = None
|
81
82
|
if not isinstance(value, (int, float)):
|
82
83
|
try:
|
83
84
|
STOCK.remove(*labels)
|
84
85
|
except KeyError:
|
85
86
|
pass
|
87
|
+
logger.debug("%r: found no value", stock.name)
|
86
88
|
return False
|
89
|
+
logger.debug("%r: found value %r", stock.name, value)
|
87
90
|
STOCK.labels(*labels).set(value)
|
88
91
|
return True
|
89
92
|
|
90
93
|
|
94
|
+
def update_state(result: bool, key: str, states: dict, labels: dict):
|
95
|
+
logger.debug("%r: updating current state with result %r", key, result)
|
96
|
+
previous = states.get(key)
|
97
|
+
states[key] = result
|
98
|
+
if previous == result:
|
99
|
+
return
|
100
|
+
inc_key, dec_key = "items-ok", "items-ko"
|
101
|
+
if not result:
|
102
|
+
inc_key, dec_key = "items-ko", "items-ok"
|
103
|
+
DAEMON.labels(status=inc_key, **labels).inc()
|
104
|
+
if previous is not None:
|
105
|
+
DAEMON.labels(status=dec_key, **labels).dec()
|
106
|
+
|
107
|
+
|
91
108
|
def main():
|
92
109
|
labels = {"name": conf.name, "section": "config"}
|
93
110
|
DAEMON.labels(status="loop-period", **labels).set(conf.loop.interval)
|
@@ -95,16 +112,15 @@ def main():
|
|
95
112
|
|
96
113
|
labels["section"] = "exec"
|
97
114
|
in_loop_interval = int(conf.loop.interval / (len(conf.stocks) + 1)) or 1
|
115
|
+
states = {}
|
98
116
|
while True:
|
99
117
|
start = datetime.now()
|
100
118
|
DAEMON.labels(status="items-ok", **labels).set(0)
|
101
119
|
DAEMON.labels(status="items-ko", **labels).set(0)
|
102
120
|
|
103
121
|
for stock in conf.stocks:
|
104
|
-
|
105
|
-
|
106
|
-
else:
|
107
|
-
DAEMON.labels(status="items-ko", **labels).inc()
|
122
|
+
result = collect(stock)
|
123
|
+
update_state(result, stock.isin, states, labels)
|
108
124
|
time.sleep(in_loop_interval)
|
109
125
|
|
110
126
|
exec_interval = (datetime.now() - start).total_seconds()
|
@@ -1,4 +0,0 @@
|
|
1
|
-
yfinance_exporter.py,sha256=PfVap2jhccZG5WW6kvyq-hnIBttIsQRhbh3D1NB0Q7Y,3569
|
2
|
-
yfinance_exporter-1.0.5.dist-info/METADATA,sha256=wXKHV5CgN65n99bWEwoY6CZLEsoIAA136Z7wu7PMxJc,1525
|
3
|
-
yfinance_exporter-1.0.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
4
|
-
yfinance_exporter-1.0.5.dist-info/RECORD,,
|
File without changes
|