chellow 1709805150.0.0__py3-none-any.whl → 1709887733.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/cfd.py CHANGED
@@ -7,7 +7,7 @@ from sqlalchemy import null, or_, select
7
7
 
8
8
  from werkzeug.exceptions import BadRequest
9
9
 
10
- from chellow.e.lcc import api_search, api_sql
10
+ from chellow.e.lcc import api_records
11
11
  from chellow.models import Contract, RateScript
12
12
  from chellow.utils import c_months_u, ct_datetime, hh_format, to_ct, to_utc
13
13
 
@@ -114,12 +114,9 @@ def lcc_import(sess, log, set_progress, s):
114
114
  import_advanced_forecast_ilr_tra(sess, log, set_progress, s)
115
115
 
116
116
 
117
- def _quarters(s):
117
+ def _quarters(log, s):
118
118
  quarter = {}
119
- res_j = api_search(
120
- s, "2fc2fad9-ad57-4901-982a-f92d4ef6c622", sort="Settlement_Date"
121
- )
122
- for record in res_j["result"]["records"]:
119
+ for record in api_records(log, s, "2fc2fad9-ad57-4901-982a-f92d4ef6c622"):
123
120
  settlement_date_str = record["Settlement_Date"]
124
121
  settlement_date_ct = to_ct(
125
122
  Datetime.strptime(settlement_date_str[:10], "%Y-%m-%d")
@@ -165,7 +162,7 @@ def import_in_period_tracking(sess, log, set_progress, s):
165
162
  sess, contract_name, "", {}, to_utc(ct_datetime(1996, 4, 1)), None, {}
166
163
  )
167
164
 
168
- for quarter in _quarters(s):
165
+ for quarter in _quarters(log, s):
169
166
  quarter_start = sorted(quarter.keys())[0]
170
167
  rs = sess.execute(
171
168
  select(RateScript).where(
@@ -206,12 +203,8 @@ def import_operational_costs_levy(sess, log, set_progress, s):
206
203
  sess, contract_name, "", {}, to_utc(ct_datetime(1996, 4, 1)), None, {}
207
204
  )
208
205
 
209
- res_j = api_search(s, "44f41eac-61b3-4e8d-8c52-3eda7b8e8517", sort="Period_Start")
210
- for record in res_j["result"]["records"][1:]: # skip title row
211
- period_start_str = record["Period_Start"]
212
- period_start = to_utc(
213
- to_ct(Datetime.strptime(period_start_str[:10], "%Y-%m-%d"))
214
- )
206
+ for record in api_records(log, s, "44f41eac-61b3-4e8d-8c52-3eda7b8e8517", skip=1):
207
+ period_start = _parse_date(record["Period_Start"])
215
208
 
216
209
  rs = sess.execute(
217
210
  select(RateScript).where(
@@ -231,16 +224,14 @@ def import_operational_costs_levy(sess, log, set_progress, s):
231
224
  RUN_TYPES = ("II", "SF", "R1", "R2", "R3", "RF", "DF")
232
225
 
233
226
 
234
- def _reconciled_days(s, search_from):
227
+ def _reconciled_days(log, s, search_from):
235
228
  runs = {}
236
- res_j = api_sql(
237
- s,
238
- f"""SELECT * from "e0e163cb-ba36-416d-83fe-976992d61516"
239
- WHERE "Settlement_Date" > '{search_from}' ORDER BY "Settlement_Date"
240
- """,
241
- )
242
-
243
- records = res_j["result"]["records"]
229
+
230
+ records = [
231
+ r
232
+ for r in api_records(log, s, "e0e163cb-ba36-416d-83fe-976992d61516")
233
+ if r["Settlement_Date"] > search_from
234
+ ]
244
235
  if len(records) > 0:
245
236
  prev_settlement_date = _parse_date(records[0]["Settlement_Date"])
246
237
  runs = {}
@@ -257,9 +248,9 @@ def _reconciled_days(s, search_from):
257
248
  yield settlement_date, runs
258
249
 
259
250
 
260
- def _reconciled_daily_quarters(s, search_from):
251
+ def _reconciled_daily_quarters(log, s, search_from):
261
252
  quarter = {}
262
- for settlement_date, lcc_runs in _reconciled_days(s, search_from):
253
+ for settlement_date, lcc_runs in _reconciled_days(log, s, search_from):
263
254
  try:
264
255
  runs = quarter[settlement_date]
265
256
  except KeyError:
@@ -317,7 +308,7 @@ def import_reconciled_daily_levy_rates(sess, log, set_progress, s):
317
308
  else:
318
309
  break
319
310
 
320
- for quarter in _reconciled_daily_quarters(s, search_from):
311
+ for quarter in _reconciled_daily_quarters(log, s, search_from):
321
312
  quarter_start = sorted(quarter.keys())[0]
322
313
  rs = sess.execute(
323
314
  select(RateScript).where(
@@ -377,10 +368,8 @@ def import_forecast_ilr_tra(sess, log, set_progress, s):
377
368
  sess, contract_name, "", {}, to_utc(ct_datetime(1996, 4, 1)), None, {}
378
369
  )
379
370
 
380
- res_j = api_search(s, "fbece4ce-7cfc-42b7-8fb2-387cf59a3c32", sort="Period_Start")
381
- for record in res_j["result"]["records"]:
382
- period_start_str = record["Period_Start"]
383
- period_start = _parse_varying_date(period_start_str)
371
+ for record in api_records(log, s, "fbece4ce-7cfc-42b7-8fb2-387cf59a3c32"):
372
+ period_start = _parse_varying_date(record["Period_Start"])
384
373
 
385
374
  rs = sess.execute(
386
375
  select(RateScript).where(
@@ -408,10 +397,8 @@ def import_advanced_forecast_ilr_tra(sess, log, set_progress, s):
408
397
  sess, contract_name, "", {}, to_utc(ct_datetime(1996, 4, 1)), None, {}
409
398
  )
410
399
 
411
- res_j = api_search(s, "e3ad6876-c1e9-46f9-b557-cb9bdae53885", sort="Period Start")
412
- for record in res_j["result"]["records"]:
413
- period_start_str = record["Period Start"]
414
- period_start = _parse_varying_date(period_start_str)
400
+ for record in api_records(log, s, "e3ad6876-c1e9-46f9-b557-cb9bdae53885"):
401
+ period_start = _parse_varying_date(record["Period Start"])
415
402
 
416
403
  rs = sess.execute(
417
404
  select(RateScript).where(
chellow/e/lcc.py CHANGED
@@ -19,10 +19,11 @@ from chellow.utils import ct_datetime_now, hh_format, utc_datetime_now
19
19
  importer = None
20
20
 
21
21
 
22
- def api_sql(s, sql):
23
- url = "https://dp.lowcarboncontracts.uk/api/3/action/datastore_search_sql"
24
- params = {"sql": sql}
22
+ def api_records(log, s, resource_id, skip=0):
23
+ url = f"https://dp.lowcarboncontracts.uk/datastore/dump/{resource_id}"
24
+ params = {"format": "json"}
25
25
  res = s.get(url, params=params)
26
+ log(f"Requested URL {res.url}")
26
27
  try:
27
28
  res_j = res.json()
28
29
  except requests.exceptions.JSONDecodeError as e:
@@ -34,27 +35,10 @@ def api_sql(s, sql):
34
35
  if "success" in res_j and not res_j["success"]:
35
36
  raise BadRequest(res_j)
36
37
 
37
- return res_j
38
+ field_titles = [f["id"] for f in res_j["fields"]]
38
39
 
39
-
40
- def api_search(s, resource_id, sort=None):
41
- url = "https://dp.lowcarboncontracts.uk/api/3/action/datastore_search"
42
- params = {"resource_id": resource_id}
43
- if sort is not None:
44
- params["sort"] = sort
45
- res = s.get(url, params=params)
46
- try:
47
- res_j = res.json()
48
- except requests.exceptions.JSONDecodeError as e:
49
- raise BadRequest(
50
- f"Couldn't parse as JSON the content from {url} with error {e}: "
51
- f"{res.text}"
52
- )
53
-
54
- if "success" in res_j and not res_j["success"]:
55
- raise BadRequest(res_j)
56
-
57
- return res_j
40
+ for record in res_j["records"][skip:]:
41
+ yield {k: v for k, v in zip(field_titles, record)}
58
42
 
59
43
 
60
44
  def run_import(sess, log, set_progress):
@@ -72,6 +56,7 @@ GLOBAL_ALERT = (
72
56
  "There's a problem with a <a href='/e/lcc'>Low Carbon Contracts import</a>."
73
57
  )
74
58
  LCC_STATE_KEY = "lcc"
59
+ DELAY_DAYS = 7
75
60
 
76
61
 
77
62
  class LowCarbonContracts(threading.Thread):
@@ -113,7 +98,9 @@ class LowCarbonContracts(threading.Thread):
113
98
  sess.rollback()
114
99
 
115
100
  last_run = lcc_state.get(LAST_RUN_KEY)
116
- if last_run is None or utc_datetime_now() - last_run > timedelta(days=1):
101
+ if last_run is None or utc_datetime_now() - last_run > timedelta(
102
+ days=DELAY_DAYS
103
+ ):
117
104
  self.going.set()
118
105
 
119
106
  if self.going.is_set():
@@ -143,7 +130,8 @@ class LowCarbonContracts(threading.Thread):
143
130
  else:
144
131
  self.log(
145
132
  f"The importer was last run at {hh_format(last_run)}. There will "
146
- f"be another import when 24 hours have elapsed since the last run."
133
+ f"be another import when {DELAY_DAYS} days have elapsed since the "
134
+ f"last run."
147
135
  )
148
136
  self.going.wait(60 * 60)
149
137
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chellow
3
- Version: 1709805150.0.0
3
+ Version: 1709887733.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)
@@ -18,7 +18,7 @@ chellow/e/bill_importer.py,sha256=y1bpn49xDwltj0PRFowWsjAVamcD8eyxUbCTdGxEZiE,73
18
18
  chellow/e/bmarketidx.py,sha256=0JCBBnP3xfLq2eFjXO_u-gzHyTizab4Pp6PRK6OZLcw,7134
19
19
  chellow/e/bsuos.py,sha256=aqteIr0YdkWDLlfJIQ8bW4mDsUxffi5zhsUAzykkqtk,15442
20
20
  chellow/e/ccl.py,sha256=CYeFrg0TNF7Av49nqxa0guA8CMcJhdMpBRmOq8PH6G0,564
21
- chellow/e/cfd.py,sha256=3yRchycC-WZwgqryGQK3B59OcMGVIWgbxrkekUOy-9k,14914
21
+ chellow/e/cfd.py,sha256=WdrnV15AX34bj__u66cLgq_LgzXBYjSzpHsGlsXfRKI,14418
22
22
  chellow/e/computer.py,sha256=YL1JFUYfFW-i9DODfvSnp6gTL_MwIfwoWj1TWtOsxPg,67105
23
23
  chellow/e/dno_rate_parser.py,sha256=5MYEbcYngh7n6Szn2h9zLTwQKXH-WHKy6c80PYwNLLQ,20983
24
24
  chellow/e/duos.py,sha256=ISTcNqe9KNjVNM2Qs8IBoQxnmSXOt5W_G7tZxp4T78M,28870
@@ -29,7 +29,7 @@ chellow/e/hh_parser_bg_csv.py,sha256=W5SU2MSpa8BGA0VJw1JXF-IwbCNLFy8fe35yxLZ7gEw
29
29
  chellow/e/hh_parser_df2.py,sha256=ynNNRMpLm9qs23tJjfm0vGSaAduXfPMw_7-WfQHXliQ,4209
30
30
  chellow/e/hh_parser_simple_csv.py,sha256=RN4QOLvTQeoPrpvXvQ9hkOBZnR5piybLfjCiSJdjpjs,2112
31
31
  chellow/e/laf_import.py,sha256=aqkcbjnvfBPszBLSNg6getP7iW1uWiTVHy6N5Z5x39U,5514
32
- chellow/e/lcc.py,sha256=K84sKH4eEZNDQysT1KmsL833X2OYhPxjGuz3EKYXgmw,4965
32
+ chellow/e/lcc.py,sha256=OkpynN8_iAdHRlu-yyU6BhRUqYYOZsUnl0HbHULYo_4,4670
33
33
  chellow/e/mdd_importer.py,sha256=9GN-at0DC3vOjd-0N2U856O3hInnjkMWWcRfxzQ5DjA,32042
34
34
  chellow/e/rcrc.py,sha256=92CA1uIotIHd1epQ_jEPdJKzXqDFV-AoJOJeRO6MEyA,4274
35
35
  chellow/e/ro.py,sha256=dZKZv_9wXSWuwcb3jiKavoD_9ot-PZseNVeEEe0siLo,596
@@ -363,6 +363,6 @@ chellow/templates/g/supply_note_edit.html,sha256=6UQf_qbhFDys3cVsTp-c7ABWZpggW9R
363
363
  chellow/templates/g/supply_notes.html,sha256=WR3YwGh_qqTklSJ7JqWX6BKBc9rk_jMff4RiWZiF2CM,936
364
364
  chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
365
365
  chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
366
- chellow-1709805150.0.0.dist-info/METADATA,sha256=HEpyPr9kzZdaC_dUL5VE8TgT4fb4A6pCzEFebhseQsU,12203
367
- chellow-1709805150.0.0.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
368
- chellow-1709805150.0.0.dist-info/RECORD,,
366
+ chellow-1709887733.0.0.dist-info/METADATA,sha256=KWA1a2icFUtb2cVmZqyg5vJtVMw9VCqogcAguScl6iQ,12203
367
+ chellow-1709887733.0.0.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
368
+ chellow-1709887733.0.0.dist-info/RECORD,,