+35
-12
bsky_utils.py
+35
-12
bsky_utils.py
···
208
208
save_session(username, session.export())
209
209
210
210
def init_client(username: str, password: str) -> Client:
211
-
pds_uri = os.getenv("PDS_URI")
212
-
if pds_uri is None:
211
+
from config_loader import get_bluesky_config
212
+
try:
213
+
bluesky_config = get_bluesky_config()
214
+
pds_uri = bluesky_config.get('pds_uri', 'https://bsky.social')
215
+
except (ValueError, KeyError):
216
+
pds_uri = os.getenv("PDS_URI", "https://bsky.social")
213
217
logger.warning(
214
-
"No PDS URI provided. Falling back to bsky.social. Note! If you are on a non-Bluesky PDS, this can cause logins to fail. Please provide a PDS URI using the PDS_URI environment variable."
218
+
"Failed to load PDS URI from config. Using environment variable or default."
215
219
)
216
-
pds_uri = "https://bsky.social"
217
220
218
221
# Print the PDS URI
219
222
logger.debug(f"Using PDS URI: {pds_uri}")
···
235
238
236
239
237
240
def default_login() -> Client:
238
-
username = os.getenv("BSKY_USERNAME")
239
-
password = os.getenv("BSKY_PASSWORD")
241
+
from config_loader import get_bluesky_config
242
+
try:
243
+
bluesky_config = get_bluesky_config()
244
+
username = bluesky_config['username']
245
+
password = bluesky_config['password']
246
+
except (ValueError, KeyError) as e:
247
+
logger.error(f"Failed to load Bluesky configuration: {e}")
248
+
exit()
240
249
241
-
print(f"Username: {username}")
242
-
print(f"Password: {password}")
243
250
244
251
if username is None:
245
252
logger.error(
···
634
641
logger.error("Missing access token or DID from session")
635
642
return None
636
643
637
-
pds_host = os.getenv("PDS_URI", "https://bsky.social")
644
+
from config_loader import get_bluesky_config
645
+
try:
646
+
pds_host = get_bluesky_config().get('pds_uri', 'https://bsky.social')
647
+
except:
648
+
pds_host = os.getenv("PDS_URI", "https://bsky.social")
638
649
639
650
# Create acknowledgment record with null subject
640
651
now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
···
708
719
logger.error("Missing access token or DID from session")
709
720
return None
710
721
711
-
pds_host = os.getenv("PDS_URI", "https://bsky.social")
722
+
from config_loader import get_bluesky_config
723
+
try:
724
+
pds_host = get_bluesky_config().get('pds_uri', 'https://bsky.social')
725
+
except:
726
+
pds_host = os.getenv("PDS_URI", "https://bsky.social")
712
727
713
728
# Create acknowledgment record with stream.thought.ack type
714
729
now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
···
784
799
logger.error("Missing access token or DID from session")
785
800
return None
786
801
787
-
pds_host = os.getenv("PDS_URI", "https://bsky.social")
802
+
from config_loader import get_bluesky_config
803
+
try:
804
+
pds_host = get_bluesky_config().get('pds_uri', 'https://bsky.social')
805
+
except:
806
+
pds_host = os.getenv("PDS_URI", "https://bsky.social")
788
807
789
808
# Create tool call record
790
809
now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
···
861
880
logger.error("Missing access token or DID from session")
862
881
return None
863
882
864
-
pds_host = os.getenv("PDS_URI", "https://bsky.social")
883
+
from config_loader import get_bluesky_config
884
+
try:
885
+
pds_host = get_bluesky_config().get('pds_uri', 'https://bsky.social')
886
+
except:
887
+
pds_host = os.getenv("PDS_URI", "https://bsky.social")
865
888
866
889
# Create reasoning record
867
890
now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")