Full-text search your own Mastodon posts with R

Uncategorized

Whether you have actually fully moved from Twitter to Mastodon, are simply checking out the “fediverse,” or have actually been a long time Mastodon user, you may miss out on being able to explore the full text of “toots” (also referred to as posts). In Mastodon, hashtags are searchable however other, non-hashtag text is not. The unavailability of full-text search lets users manage how much of their material is quickly discoverable by strangers. However what if you want to have the ability to search your own posts?Some Mastodon instances allow users to do full-text searches of their own toots however others don’t, depending upon the admin. Thankfully, it’s simple to full-text search your own Mastodon posts, thanks to R and the rtoot bundle established by David Schoch. That’s what this short article is about.Set up a full-text search First, install the rtoot bundle if it’s not already on your system with install.packages(“rtoot”). I’ll likewise be using the dplyr and DT packages. All 3 can be loaded with the following command: # install.packages( “rtoot”)# if required library(rtoot)library( dplyr)library(DT) Next, you’ll require your Mastodon ID,
which is not the like your user name and instance. The rtoot package includes a way to search throughout the fediverse for accounts. That’s a helpful tool if you wish to see if somebody has an account anywhere on Mastodon. However since it likewise returns account IDs, you can use it to find your own ID, too.To look for my own ID, I ‘d utilize: accounts > with the URL of the post, which I then include

to the end of each post’s content. That makes it easy to click through to the initial variation: tabledata filter (material!=” “)| > # filter(visibility== “public”)| > # If you want to make this public someplace. Default includes direct messages.mutate(url=paste0(“>>”), material= paste(material, url), created_at:= as.character(as.POSIXct(created_at, format =” %Y -%m -%d%H:%M UTC”) ))| > select (CreatedAt=created_at, Post = material, Responds= replies_count, Favorites=favourites_count, Boosts=reblogs_count) If I were sharing

this table publicly, I ‘d

make certain to uncomment filter(exposure==” public”) so only my public posts were offered. The data returned by get_account_statuses() for your own account includes posts that are unlisted(offered to anybody who discovers them however not on public timelines by default)as well as those that are set for fans just or direct messages.There are a great deal of methods to turn this data into a searchable table. One method is with the DT bundle. The code below creates an interactive HTML table with search filter boxes that can utilize routine expressions.(See Do more with R: Quick interactive HTML tables to get more information about utilizing DT.)

DT:: datatable(tabledata, filter =’ leading’, escape=FALSE, rownames=FALSE, options= list(search =list(regex=TRUE, caseInsensitive =TRUE), pageLength=20, lengthMenu=c

(25, 50, 100), autowidth=REAL, columnDefs=list (list

(width=’80% ‘, targets=list (2 ))) ))Here’s a screenshot of the resulting table:< img alt="Table revealing a few of my Mastodon posts filtered for the #rstats tag in a search box"width="1200"height ="917 "src="https://images.idgesg.net/images/article/2022/12/rtoot_table-100935223-large.jpg?auto=webp&quality=85,70"/ > Sharon Machlis An interactive table of my Mastodon posts. This table was created with the DT R package utilizing rtoot. How to pull in new Mastodon posts It’s easy to update

your data to pull brand-new posts, since the get_account_statuses () function consists of a since_id argument. To start, find the optimum ID from the existing data: max_id Information export. You should see an alternative to download an archive of your posts and media. You can only ask for an archive once every 7 days, though, and it will not consist of any engagement metrics.Once you download the archive, you can unload it by hand or, as I prefer, use the archive bundle (offered on CRAN)to draw out the files. I’ll likewise load the jsonlite, stringr, and tidyr plans before drawing out files from

the archive: library (archive)library( jsonlite)library(stringr )library (tidyr )archive_extract (“name-of-your-archive-file. tar.gz”)Next, you’ll wish to look at outbox.json’s orderItems. Here’s how I imported that into R: my_outbox

Leave a Reply

Your email address will not be published. Required fields are marked *