tangled
alpha
login
or
join now
zenfyr.dev
/
xpost
2
fork
atom
social media crossposting tool. 3rd time's the charm
mastodon
misskey
crossposting
bluesky
2
fork
atom
overview
issues
1
pulls
pipelines
chore: clean-up bsky output
zenfyr.dev
1 month ago
f2b23c64
a7238685
verified
This commit was signed with the committer's
known signature
.
zenfyr.dev
SSH Key Fingerprint:
SHA256:TtcIcnTnoAB5mqHofsaOxIgiMzfVBxej1AXT7DQdrTE=
1/1
run-tests.yml
success
15s
+31
-37
2 changed files
expand all
collapse all
unified
split
atproto
models.py
bluesky
output.py
+11
atproto/models.py
reviewed
···
1
1
+
import json
1
2
from abc import ABC, abstractmethod
2
3
from dataclasses import dataclass, field
3
4
from typing import Any
···
5
6
6
7
URI = "at://"
7
8
URI_LEN = len(URI)
9
9
+
10
10
+
11
11
+
def cid_from_json(data: str | None) -> str | None:
12
12
+
if not data:
13
13
+
return None
14
14
+
15
15
+
try:
16
16
+
return str(json.loads(data)["cid"])
17
17
+
except (json.JSONDecodeError, AttributeError, KeyError):
18
18
+
return None
8
19
9
20
10
21
class AtUri:
+20
-37
bluesky/output.py
reviewed
···
14
14
SelfLabel,
15
15
SelfLabels,
16
16
StrongRef,
17
17
+
cid_from_json,
17
18
)
18
19
from atproto.store import get_store
19
20
from bluesky.client import BlueskyClient
···
224
225
self.log.error("Skipping '%s': failed to fetch parent posts from db")
225
226
return
226
227
227
227
-
try:
228
228
-
root_cid_data = root_post["extra_data"]
229
229
-
root_cid = (
230
230
-
json.loads(root_cid_data).get("cid", "") if root_cid_data else ""
231
231
-
)
232
232
-
reply_cid_data = reply_post["extra_data"]
233
233
-
reply_cid = (
234
234
-
json.loads(reply_cid_data).get("cid", "") if reply_cid_data else ""
235
235
-
)
236
236
-
except (json.JSONDecodeError, AttributeError, KeyError):
228
228
+
root_cid = cid_from_json(root_post["extra_data"])
229
229
+
reply_cid = cid_from_json(reply_post["extra_data"])
230
230
+
231
231
+
if not root_cid or not reply_cid:
237
232
self.log.error("Skipping '%s': failed to parse CID from db")
238
233
return
239
234
···
318
313
)
319
314
if not quoted_post:
320
315
self.log.error("Skipping '%s': quoted post not found in db!")
321
321
-
else:
322
322
-
quoted_mappings = self._get_mappings(
323
323
-
quoted_post["id"], self.url, self.did
324
324
-
)
325
325
-
if not quoted_mappings:
326
326
-
self.log.error(
327
327
-
"Skipping '%s': failed to find mappings for quoted post"
328
328
-
)
329
329
-
else:
330
330
-
bluesky_quoted_post = self._get_post(
331
331
-
self.url, self.did, quoted_mappings[0]["identifier"]
332
332
-
)
333
333
-
if not bluesky_quoted_post:
334
334
-
self.log.error(
335
335
-
"Skipping '%s': Failed to find Bluesky quoted post!"
336
336
-
)
337
337
-
else:
338
338
-
quoted_cid_data = bluesky_quoted_post["extra_data"]
339
339
-
quoted_cid = (
340
340
-
json.loads(quoted_cid_data).get("cid", "")
341
341
-
if quoted_cid_data
342
342
-
else ""
343
343
-
)
344
344
-
quoted_uri = quoted_mappings[0]["identifier"]
316
316
+
return
317
317
+
318
318
+
quoted_mappings = self._get_mappings(quoted_post["id"], self.url, self.did)
319
319
+
if not quoted_mappings:
320
320
+
self.log.error("Skipping '%s': failed to find mappings for quoted post")
321
321
+
return
322
322
+
323
323
+
quoted_cid = cid_from_json(quoted_mappings[0]["extra_data"])
324
324
+
if not quoted_cid:
325
325
+
self.log.error("Skipping '%s': failed to parse CID from db")
326
326
+
return
327
327
+
328
328
+
quoted_uri = quoted_mappings[0]["identifier"]
345
329
346
330
splitter = TokenSplitter(max_chars=300, max_link_len=30)
347
331
token_blocks = splitter.split(tokens)
···
583
567
if not mappings:
584
568
return
585
569
586
586
-
try:
587
587
-
cid = json.loads(mappings[0]["extra_data"])["cid"]
588
588
-
except (json.JSONDecodeError, AttributeError, KeyError):
570
570
+
cid = cid_from_json(mappings[0]["extra_data"])
571
571
+
if not cid:
589
572
self.log.exception("Skipping '%s': failed to parse CID from extra_data")
590
573
return
591
574