Nicolas Pierson commited on
Commit
2cfaed9
·
unverified ·
1 Parent(s): 26f9af2
Files changed (1) hide show
  1. src/pages/1_Historical_Prices.py +19 -19
src/pages/1_Historical_Prices.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import asyncio
4
- import aiobotocore
5
  import json
6
  import io
7
  import plotly.colors as pcolors
@@ -24,7 +24,7 @@ async def async_load_file_s3(object_key: str) -> pd.DataFrame:
24
  "AWS credentials or bucket name not set in environment variables."
25
  )
26
 
27
- session = aiobotocore.get_session()
28
  async with session.create_client(
29
  "s3",
30
  aws_access_key_id=AWS_ACCESS_KEY_ID,
@@ -47,23 +47,23 @@ async def async_load_geojson_from_s3(object_key: str) -> dict:
47
  with open(local_file_path, "r") as f:
48
  return json.load(f)
49
 
50
- session = aiobotocore.get_session()
51
- async with session.create_client(
52
- "s3",
53
- aws_access_key_id=AWS_ACCESS_KEY_ID,
54
- aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
55
- ) as s3_client:
56
- response = await s3_client.get_object(Bucket=AWS_S3_BUCKET, Key=object_key)
57
- status = response.get("ResponseMetadata", {}).get("HTTPStatusCode")
58
-
59
- if status == 200:
60
- async with response["Body"] as stream:
61
- content = await stream.read()
62
- os.makedirs(os.path.dirname(local_file_path), exist_ok=True)
63
- with open(local_file_path, "wb") as f:
64
- f.write(content)
65
- return json.loads(content.decode("utf-8"))
66
- raise ValueError(f"Unsuccessful S3 get_object response. Status - {status}")
67
 
68
 
69
  @st.cache_resource
 
1
  import streamlit as st
2
  import pandas as pd
3
  import asyncio
4
+ from aiobotocore.session import get_session # Corrected import
5
  import json
6
  import io
7
  import plotly.colors as pcolors
 
24
  "AWS credentials or bucket name not set in environment variables."
25
  )
26
 
27
+ session = get_session() # Corrected usage
28
  async with session.create_client(
29
  "s3",
30
  aws_access_key_id=AWS_ACCESS_KEY_ID,
 
47
  with open(local_file_path, "r") as f:
48
  return json.load(f)
49
 
50
+ # session = get_session() # Corrected usage
51
+ # async with session.create_client(
52
+ # "s3",
53
+ # aws_access_key_id=AWS_ACCESS_KEY_ID,
54
+ # aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
55
+ # ) as s3_client:
56
+ # response = await s3_client.get_object(Bucket=AWS_S3_BUCKET, Key=object_key)
57
+ # status = response.get("ResponseMetadata", {}).get("HTTPStatusCode")
58
+
59
+ # if status == 200:
60
+ # async with response["Body"] as stream:
61
+ # content = await stream.read()
62
+ # os.makedirs(os.path.dirname(local_file_path), exist_ok=True)
63
+ # with open(local_file_path, "wb") as f:
64
+ # f.write(content)
65
+ # return json.loads(content.decode("utf-8"))
66
+ # raise ValueError(f"Unsuccessful S3 get_object response. Status - {status}")
67
 
68
 
69
  @st.cache_resource