home · login to get plonkin'

tangled-explore.R

@hrbrmstr.dev · 15d ago · plaintext · 99 loc · raw · 0 comments

1library(tidyverse)23get_tangled_repo <- function(host, did) {4  5  httr::GET(6    url = sprintf("%s/xrpc/com.atproto.repo.listRecords", host[1]),7    query = list(8      repo = did,9      collection = "sh.tangled.repo",10      limit = 10011    )12  ) |> 13    httr::content(as = "text") |> 14    jsonlite::fromJSON()15  16}1718msgs <- jsonlite::stream_in(file("tangled.json"))1920actors <- unique(msgs$did)2122msgs$commit |> 23  filter(24    collection == "sh.tangled.graph.follow"25  ) |>26  pull(record) |> 27  filter(!is.na(subject)) |> 28  pull(subject) |> 29  unique() -> followed3031msgs$commit |> 32  filter(33    collection == "sh.tangled.feed.star"34  ) |>35  pull(record) |> 36  filter(!is.na(subject)) |> 37  pull(subject) |>38  gsub("^at://|/sh.*", "", x = _) |> 39  unique() -> starred4041c(actors, followed, starred) |> 42  unique() |> 43  sprintf("https://plc.directory/%s", x = _) |> 44  map(httr::GET, .progress = TRUE) |> 45  map(httr::content, as = "text") |> 46  map(jsonlite::fromJSON) |> 47  map(\(.x) {48    tibble(49      did = .x$id[1],50      handle = .x$alsoKnownAs[1],51      pds = .x$service$serviceEndpoint[1]52    )53  }) |> 54  list_rbind() |> 55  mutate(56    repos = map2(pds, did, get_tangled_repo, .progress = TRUE),57    records = map(repos, "records")58  ) |> 59  select(-repos, -did) |> 60  filter(lengths(records) > 1) |> 61  unnest(records) |> 62  unnest(value) |> 63  janitor::clean_names() -> xdf6465xdf |> 66  pull(handle) |> 67  unique()6869xdf |> 70  pull(pds) |> 71  unique() |> 72  curlparse::domain() |>73  psl::apex_domain() |> 74  table(dnn = "domain") |> 75  sort() |> 76  as.data.frame.table(77    responseName = "ct"78  )7980xdf |> 81  pull(knot) |> 82  table(dnn = "knot") |> 83  sort() |> 84  as.data.frame.table(85    responseName = "ct"86  )8788xdf |> 89  distinct(90    handle, name, description91  ) |> 92  mutate(93    handle = sub("^at://", "@", handle),94    md = sprintf("- (`%s`) %s%s%s", handle, name, ifelse(is.na(description), "", ": "), ifelse(is.na(description), "", description))95  ) |> 96  arrange(md) |> 97  pull(md) |> 98  writeLines()99

login to post a comment