yfinance-exporter 1.0.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: yfinance-exporter
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary:
5
5
  Author: François Schmidts
6
6
  Author-email: francois@schmidts.fr
@@ -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("Collecting for %r", stock.name)
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,30 +77,32 @@ 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
 
91
94
  def update_state(result: bool, key: str, states: dict, labels: dict):
95
+ logger.debug("%r: updating current state with result %r", key, result)
92
96
  previous = states.get(key)
93
- states[key] = "ok" if result else "ko"
94
- if previous == "ko" and not result or previous == "ok" and result:
97
+ states[key] = result
98
+ if previous == result:
95
99
  return
96
- if result:
97
- DAEMON.labels(status="items-ok", **labels).inc()
98
- if previous:
99
- DAEMON.labels(status="items-ko", **labels).dec()
100
- else:
101
- DAEMON.labels(status="items-ko", **labels).inc()
102
- if previous:
103
- DAEMON.labels(status="items-ok", **labels).dec()
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()
104
106
 
105
107
 
106
108
  def main():
@@ -1,4 +0,0 @@
1
- yfinance_exporter.py,sha256=TJrHG5ykq-UlkZv8B81dWmAMuZzvyASftKOFvgWZi7o,4038
2
- yfinance_exporter-1.0.6.dist-info/METADATA,sha256=G96Au8wscW9S9gqLFIAHdkMutW0kqUjtvUWmD7af7NU,1525
3
- yfinance_exporter-1.0.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
4
- yfinance_exporter-1.0.6.dist-info/RECORD,,