chellow 1717422005.0.0__py3-none-any.whl → 1717489198.0.0__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.

Potentially problematic release.


This version of chellow might be problematic. Click here for more details.

chellow/e/bmarketidx.py CHANGED
@@ -1,9 +1,12 @@
1
1
  import atexit
2
- import collections
3
2
  import threading
4
3
  import traceback
4
+ from collections import deque
5
+ from datetime import datetime as Datetime
5
6
  from decimal import Decimal
6
7
 
8
+ from dateutil.relativedelta import relativedelta
9
+
7
10
  import requests
8
11
 
9
12
  from werkzeug.exceptions import BadRequest
@@ -73,7 +76,7 @@ class BmarketidxImporter(threading.Thread):
73
76
  def __init__(self):
74
77
  super().__init__(name="Bmarketidx Importer")
75
78
  self.lock = threading.RLock()
76
- self.messages = collections.deque(maxlen=100)
79
+ self.messages = deque(maxlen=1000)
77
80
  self.stopped = threading.Event()
78
81
  self.going = threading.Event()
79
82
 
@@ -145,7 +148,7 @@ class BmarketidxImporter(threading.Thread):
145
148
  self.global_alert = (
146
149
  f"There's a problem with the <a "
147
150
  f"href='/non_core_contracts/{contract.id}/"
148
- f"automatic_importer'>bmarketidx automatic "
151
+ f"auto_importer'>bmarketidx automatic "
149
152
  f"importer</a>."
150
153
  )
151
154
  finally:
@@ -164,24 +167,38 @@ def _process_month(log_f, sess, contract, latest_rs, month_start, month_finish):
164
167
  )
165
168
  rates = {}
166
169
  month_finish_ct = to_ct(month_finish)
170
+ base_url = "https://data.elexon.co.uk/bmrs/api/v1/balancing/pricing/market-index"
167
171
  for d in range(month_finish_ct.day):
168
- day_ct = ct_datetime(month_finish_ct.year, month_finish_ct.month, d + 1)
172
+ day_from_ct = ct_datetime(month_finish_ct.year, month_finish_ct.month, d + 1)
173
+ day_to_ct = day_from_ct + relativedelta(days=1)
169
174
  params = {
170
- "q": f"ajax/alldata/MID/Date,SP,Provider,Price,Volume/NULL/"
171
- f'{day_ct.strftime("%Y-%m-%d")}/ALL'
175
+ "from": f'{day_from_ct.strftime("%Y-%m-%d")}T00:00Z',
176
+ "to": f'{day_to_ct.strftime("%Y-%m-%d")}T00:00Z',
177
+ "settlementPeriodFrom": "1",
178
+ "settlementPeriodTo": "1",
172
179
  }
173
180
  sess.rollback()
174
- r = requests.get(
175
- "https://www.bmreports.com/bmrs/", params=params, timeout=60, verify=False
176
- )
181
+ q_str = "&".join(f"{k}={v}" for k, v in params.items())
182
+ log_f(f"Attempting to download {base_url}?{q_str}")
183
+ r = requests.get(base_url, params=params, timeout=60, verify=False)
177
184
  res = r.json()
178
- for h in res["arr"]:
179
- dt = to_utc(day_ct + (int(h["settlementPeriod"]) - 1) * HH)
180
- try:
181
- rate = rates[dt]
182
- except KeyError:
183
- rate = rates[dt] = {}
184
- rate[h["DataProviderId"]] = Decimal(h["MarketIndexPrice"]) / Decimal(1000)
185
+ for h in res["data"]:
186
+ # {
187
+ # "startTime":"2022-06-01T23:00:00Z",
188
+ # "dataProvider":"N2EXMIDP",
189
+ # "settlementDate":"2022-06-02",
190
+ # "settlementPeriod":1,
191
+ # "price":0.00,
192
+ # "volume":0.000
193
+ # },
194
+ settlement_date = Datetime.strptime(h["settlementDate"], "%Y-%m-%d")
195
+ if settlement_date.month == month_finish_ct.month:
196
+ dt = to_utc(settlement_date + (int(h["settlementPeriod"]) - 1) * HH)
197
+ try:
198
+ rate = rates[dt]
199
+ except KeyError:
200
+ rate = rates[dt] = {}
201
+ rate[h["dataProvider"]] = Decimal(h["price"]) / Decimal(1000)
185
202
 
186
203
  if month_finish in rates:
187
204
  log_f("The whole month's data is there.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: chellow
3
- Version: 1717422005.0.0
3
+ Version: 1717489198.0.0
4
4
  Summary: Web Application for checking UK energy bills.
5
5
  Project-URL: Homepage, https://github.com/WessexWater/chellow
6
6
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
@@ -15,7 +15,7 @@ chellow/views.py,sha256=eDvTQM_PUqRvrCQvBdlF5q7MEs7w2yJmRjcC8WDbHtE,79584
15
15
  chellow/e/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  chellow/e/aahedc.py,sha256=d2usudp7KYWpU6Pk3fal5EQ47EbvkvKeaFGylnb3NWw,606
17
17
  chellow/e/bill_importer.py,sha256=7UcnqNlKbJc2GhW9gy8sDp9GuqambJVpZLvbafOZztA,7411
18
- chellow/e/bmarketidx.py,sha256=lao_Azld-aaimEQLsTCpGTaZKI8iFpg2K6CDFOG0seM,7132
18
+ chellow/e/bmarketidx.py,sha256=C0BaHn2RxIuWH2QzA-OmSP0fbUGvW9tqEUhLnzOEdmA,7968
19
19
  chellow/e/bsuos.py,sha256=hdP9vnOJSuZl46OAkJeUg1XJYvYIBj4J6Sqce1Hy9Vs,15542
20
20
  chellow/e/ccl.py,sha256=30dh_SvlgzsTQPPAJNZWILaMvbeDsv9-P-S1JxS5_SQ,3184
21
21
  chellow/e/cfd.py,sha256=V1DTT5XBQbt8hO1gae1u3315fZ4iuYk3XC7J2sUbhKQ,14352
@@ -364,6 +364,6 @@ chellow/templates/g/supply_note_edit.html,sha256=6UQf_qbhFDys3cVsTp-c7ABWZpggW9R
364
364
  chellow/templates/g/supply_notes.html,sha256=WR3YwGh_qqTklSJ7JqWX6BKBc9rk_jMff4RiWZiF2CM,936
365
365
  chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
366
366
  chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
367
- chellow-1717422005.0.0.dist-info/METADATA,sha256=Htpjp-p18RGbhe8l7jpmEErcTO1aCFxezxhbSBeCG1c,12205
368
- chellow-1717422005.0.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
369
- chellow-1717422005.0.0.dist-info/RECORD,,
367
+ chellow-1717489198.0.0.dist-info/METADATA,sha256=ot9Lf-fyAnN_scgT4ordJTmGiv3CDAIOUQz3lmqiV28,12205
368
+ chellow-1717489198.0.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
369
+ chellow-1717489198.0.0.dist-info/RECORD,,