Title: | Utilities for Promoting rOpenSci on Twitter |
---|---|
Description: | Utility functions for accessing GitHub and twitter data. |
Authors: | Steffi LaZerte [aut, cre] (ORCID: <https://orcid.org/0000-0002-7690-8360>) |
Maintainer: | Steffi LaZerte <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.4.3 |
Built: | 2025-05-26 10:30:01 UTC |
Source: | https://github.com/ropensci-org/promoutils |
Based on a name and a repository, fetch the usernames
all_users(name, owner = "ropensci", pkg)
all_users(name, owner = "ropensci", pkg)
name |
Character. Full name |
owner |
Character. Repository owner. |
pkg |
Character. Repository name (package name). |
Data frame of user names: gh_user and masto_user
all_users(name = "Steffi LaZerte", pkg = "weathercan")
all_users(name = "Steffi LaZerte", pkg = "weathercan")
The week before, prepare the slides and coworking document, then use this draft text to invite the cohost(s) to review via Slack or Email.
cw_checkin(which = "next", names = NULL, notes_link, slides_link)
cw_checkin(which = "next", names = NULL, notes_link, slides_link)
which |
Character/Date. "next" to fetch details on the next coworking session, "last" to fetch details on the last scheduled (in future) coworking session, or a Date fetch details for a specific coworking session. |
names |
Character. Names of cohost if overriding those in the event listing. |
notes_link |
Character. Link to the Google doc with coworking notes. |
slides_link |
Character. Link to the Google slides. |
Fetch details about coworking sessions
cw_details(which = "next")
cw_details(which = "next")
which |
Character/Date. "next" to fetch details on the next coworking session, "last" to fetch details on the last scheduled (in future) coworking session, or a Date fetch details for a specific coworking session. |
Data frame with coworking event details
cw_details() cw_details("2023-11")
cw_details() cw_details("2023-11")
Creates a draft coworking event for the roweb3 website. All details pulled
from the coworking todo list issue in rosadmin/comms
.
cw_event(date, dry_run = FALSE)
cw_event(date, dry_run = FALSE)
date |
Character/Date. Date of the coworking event (local) |
dry_run |
Logical. Whether to really create the event or just return the text. |
Create an issue listing the coworking todos. If no date or timezone, picks the next appropriate date (first Tuesday in the month following an existing coworking issue) and next appropriate timezone (cycling through America, Europe, and Australia) automatically.
cw_issue( date = NULL, tz = NULL, theme = "XXXX", cohost = "XXXX", dry_run = FALSE )
cw_issue( date = NULL, tz = NULL, theme = "XXXX", cohost = "XXXX", dry_run = FALSE )
date |
Character. Date of next event (if NULL picks next first Tuesday). |
tz |
Character. Timezone of next event (if NULL picks next in order). |
theme |
Character. Name of theme, if unknown, uses XXXX placeholder |
cohost |
Character. Name of cohost, if unknown, uses XXXX placeholder |
dry_run |
Logical. Whether to do a dry run (i.e. don't post) |
Creates draft posts for Mastodon and LinkedIn (by opening issues on rosadmin/scheduled_socials) and Slack (by printing the post text and schedule).
cw_socials( date, who_masto, who_slack, who_linkedin, who_main_masto = "@[email protected]", who_main_slack = "@Steffi LaZerte", who_main_linkedin = "Steffi LaZerte", posters_tz = "America/Winnipeg", dry_run = FALSE )
cw_socials( date, who_masto, who_slack, who_linkedin, who_main_masto = "@[email protected]", who_main_slack = "@Steffi LaZerte", who_main_linkedin = "Steffi LaZerte", posters_tz = "America/Winnipeg", dry_run = FALSE )
date |
Character/Date. Date of the coworking event (local) |
who_masto |
Character. The full mastodon handle for the cohost (i.e. [email protected]) |
who_slack |
Character. The full Slack handle for the cohost (i.e. @XXXX) |
who_linkedin |
Character. The full LinkedIn handle for the cohost (i.e. @XXXX) |
who_main_masto |
Character. The full mastodon handle for the rOpenSci staff organizer. |
who_main_slack |
Character. The full Slack handle for the rOpenSci staff organizer. |
who_main_linkedin |
Character. The full LinkedIn handle for the rOpenSci staff organizer. |
posters_tz |
Character. Timezone of poster. Required for getting the time at which to post Slack messages as these are posted in the local timezone |
dry_run |
Logical. Whether to do a dry run (i.e. don't post) |
## Not run: cw_socials("2023-07-04", who_masto = "@[email protected]", who_slack = "@cohost") ## End(Not run)
## Not run: cw_socials("2023-07-04", who_masto = "@[email protected]", who_slack = "@cohost") ## End(Not run)
Using the Discourse username id, return the full name of that discourse user.
discourse_user(user)
discourse_user(user)
user_id |
Integer. Discourse user id. |
Character
# discourse_user(1) # Requires authentication
# discourse_user(1) # Requires authentication
Extract mentions from forum text
forum_mention(x)
forum_mention(x)
x |
Forum text |
Character of metions
Fetch post text from by topic id
forum_post(topic_id)
forum_post(topic_id)
x |
Topic id |
HTML of the post
# forum_post(3920) # Needs auth
# forum_post(3920) # Needs auth
Extract resources from forum text
forum_resource(x)
forum_resource(x)
x |
Forum text |
Character vector of resources
# forum_post(3920) |> # Needs auth # forum_resource() # > weatherOz
# forum_post(3920) |> # Needs auth # forum_resource() # > weatherOz
Create a cached version of the GH api calls
gh_cache( endpoint, ..., per_page = NULL, .per_page = NULL, .token = NULL, .destfile = NULL, .overwrite = FALSE, .api_url = NULL, .method = "GET", .limit = NULL, .accept = "application/vnd.github.v3+json", .send_headers = NULL, .progress = TRUE, .params = list(), .max_wait = 600, .max_rate = NULL )
gh_cache( endpoint, ..., per_page = NULL, .per_page = NULL, .token = NULL, .destfile = NULL, .overwrite = FALSE, .api_url = NULL, .method = "GET", .limit = NULL, .accept = "application/vnd.github.v3+json", .send_headers = NULL, .progress = TRUE, .params = list(), .max_wait = 600, .max_rate = NULL )
memoise::memoise(gh::gh)
Fetch issues from a GH repository
gh_issue_fetch( state = "open", labels = NULL, since = NULL, owner = "rosadmin", repo = "scheduled_socials", issue = NULL, verbose = FALSE )
gh_issue_fetch( state = "open", labels = NULL, since = NULL, owner = "rosadmin", repo = "scheduled_socials", issue = NULL, verbose = FALSE )
state |
Character. Which issues to fetch: "open", "closed", "all" |
labels |
Character vector. Fetch only issues with these labels. (Optional) |
since |
Character/Date/datetime. Fetch only issues since this date/time. (Optional) |
owner |
Character. Owner of the repository |
repo |
Character. Name of the repository (name of the package) |
issue |
Numeric. Specific Issue number to fetch. |
verbose |
Logical. Show progress messages. |
List of issues
i <- gh_issue_fetch()
i <- gh_issue_fetch()
Format issues list from GH
gh_issue_fmt( i, which = c("title", "number", "body", "labels", "url", "created", "updated", "gh_user_issue") )
gh_issue_fmt( i, which = c("title", "number", "body", "labels", "url", "created", "updated", "gh_user_issue") )
i |
List of issues from |
which |
Which fields to includ |
Issues formated as a data frame
i <- gh_issue_fetch() i <- gh_issue_fmt(i, which = "title")
i <- gh_issue_fetch() i <- gh_issue_fmt(i, which = "title")
Extract information on help-wanted labels for issues
gh_issue_labels( i, labels_help = "(help)|(help wanted)|(help-wanted)|(help_wanted)", labels_first = "(good first issue)|(beginner)|(good-first-issue)" )
gh_issue_labels( i, labels_help = "(help)|(help wanted)|(help-wanted)|(help_wanted)", labels_first = "(good first issue)|(beginner)|(good-first-issue)" )
i |
Data frame of issues from |
labels_help |
Character. Regular expression to match help-wanted labels. |
labels_first |
Character. Regular expression to meatch good-first-issue labels. |
data frame with added label details
i <- gh_issue_fetch(owner = "ropensci", repo = "weathercan") i <- gh_issue_fmt(i) i <- gh_issue_labels(i)
i <- gh_issue_fetch(owner = "ropensci", repo = "weathercan") i <- gh_issue_fmt(i) i <- gh_issue_labels(i)
Find Mastodon username from GitHub profile
gh_masto(gh_user)
gh_masto(gh_user)
gh_user |
Character. GH username |
Character URL to mastodon profile if it exists, NA otherwise.
gh_masto("steffilazerte")
gh_masto("steffilazerte")
Fetch full name of GitHub user
gh_name(gh_user)
gh_name(gh_user)
gh_user |
Character. GitHub username/handle |
Character, full name of the user or NA
gh_name("steffilazerte")
gh_name("steffilazerte")
Look up users of a repository and match to a name. Try with and without initials.
gh_user(name, owner = "ropensci", pkg, .max_rate = NULL)
gh_user(name, owner = "ropensci", pkg, .max_rate = NULL)
name |
Character. Full or partial name of the person for whom you want to fetch the GitHub username. |
owner |
Character. Owner of the repository. |
pkg |
Character. Repository name (package name). |
.max_rate |
Numeric. Passed through to |
Data frame with names attempted and usernames found
gh_user(name = "Steffi E. LaZerte", owner = "ropensci", pkg = "weathercan") gh_user(name = "Steffi", owner = "ropensci", pkg = "weathercan")
gh_user(name = "Steffi E. LaZerte", owner = "ropensci", pkg = "weathercan") gh_user(name = "Steffi", owner = "ropensci", pkg = "weathercan")
This authorizes the rOpenSci client with your credentials (and you must be part of the rOpenSci organization as an admin). Make sure to take note of the 'refresh_token' as that is what you'll add to your .Renviron file for local work, or the GitHub secrets for the comms/scheduled_socials workflow.
li_auth()
li_auth()
This function authorizes with a redirect url of "http://localhost:1444/", this must be the same as that listed in the LinkedIn Developer App, https://www.linkedin.com/developers/apps.
If you retrieve a new token, you will have to put it in the .Renviron and the re-start your R session to continue
This function authorizes with the scopes:
w_member_social (default)
w_organization_social (special request)
r_organization_social (special request)
r_organization_admin (special request)
httr2 authorization
Refresh tokens API: https://learn.microsoft.com/en-us/linkedin/shared/authentication/programmatic-refresh-tokens
## Not run: # Only run if you need to update the scopes or get a new token (otherwise # you'll have to replace all your tokens) t <- li_auth() t$refresh_token ## End(Not run)
## Not run: # Only run if you need to update the scopes or get a new token (otherwise # you'll have to replace all your tokens) t <- li_auth() t$refresh_token ## End(Not run)
Get a list of recent posts by rOpenSci
li_posts_read(author)
li_posts_read(author)
author |
Character. LinkedIn URN id (e.g., rOpenSci's is "urn:li:organization:77132573") |
list of posts
https://learn.microsoft.com/en-us/linkedin/shared/api-guide/concepts/urns
https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/posts-api
li_posts_read(ro_urn)
li_posts_read(ro_urn)
Post to LinkedIn
li_posts_write(author, body, dry_run = FALSE)
li_posts_write(author, body, dry_run = FALSE)
author |
Character. URN. Either yours (see |
body |
Character. The body of the post as you would like it to appear. |
dry_run |
Logical. TRUE to show what would be sent to the server without actually sending it. |
A string of the URN for the post id.
# Dry-run id <- li_posts_write( author = ro_urn, # Post on behalf of rOpenSci body = "Testing out the LinkedIn API via R and httr2!", dry_run = TRUE) ## Not run: # Real post id <- li_posts_write( author = ro_urn, # Post on behalf of rOpenSci body = "Testing out the LinkedIn API via R and httr2!") ## End(Not run)
# Dry-run id <- li_posts_write( author = ro_urn, # Post on behalf of rOpenSci body = "Testing out the LinkedIn API via R and httr2!", dry_run = TRUE) ## Not run: # Real post id <- li_posts_write( author = ro_urn, # Post on behalf of rOpenSci body = "Testing out the LinkedIn API via R and httr2!") ## End(Not run)
This is required to post on LinkedIn to your personal account (for rOpenSci, use the organization urn, "urn:li:organization:77132573"
li_urn_me()
li_urn_me()
A string with your URN in the format of "urn:li:person:XXXX"
## Not run: li_urn_me() ## End(Not run)
## Not run: li_urn_me() ## End(Not run)
Using the GH username or the Full name, check rOpenSci author pages and then GitHub for references to the person Mastodon account.
masto_user(gh_user = NULL, name = NULL)
masto_user(gh_user = NULL, name = NULL)
gh_user |
Character. GH user name. |
name |
Character. Full/Partial name |
Character url to Mastodon profile
masto_user("steffilazerte")
masto_user("steffilazerte")
Convert a mastodon user link to handle
masto2user(x)
masto2user(x)
x |
Character. Link to user's profile |
Character user handle @user@instance
masto2user("https://fosstodon.org/@steffilazerte") masto2user("steffi") masto2user("@[email protected]") masto2user(NA)
masto2user("https://fosstodon.org/@steffilazerte") masto2user("steffi") masto2user("@[email protected]") masto2user(NA)
Given a date and a day of the week, Given a date return the next month's first Tuesday
next_date(month, which = "Tues", n = 1)
next_date(month, which = "Tues", n = 1)
month |
Character/Date. The current month. Date returned is the next month. |
which |
Character/Numeric. Which week day to return. Either number or abbreviated English weekday. |
n |
Numeric. The nth week to return (i.e. the 1st Tuesday if |
A date
# Get the next first Tuesday next_date("2023-11-01") next_date("2023-11-30") # Get the next 3rd Tuesday next_date("2023-11-01", n = 3) # Oops ## Not run: next_date("2023-11-01", n = 5) ## End(Not run)
# Get the next first Tuesday next_date("2023-11-01") next_date("2023-11-30") # Get the next 3rd Tuesday next_date("2023-11-01", n = 3) # Oops ## Not run: next_date("2023-11-01", n = 5) ## End(Not run)
Get package author names
pkg_authors(x, pkgs)
pkg_authors(x, pkgs)
x |
Character. Package name |
pkgs |
Data frame. Packages returned by |
Character name of maintainer
Return a data frame of rOpenSci packages
pkgs( url = "https://ropensci.github.io/roregistry/registry.json", which = "active", return = "sub" )
pkgs( url = "https://ropensci.github.io/roregistry/registry.json", which = "active", return = "sub" )
url |
Character. Registry url |
which |
Character. Status of packages to return ("all" or "active") |
return |
Character. Return a subset ("sub") or all ("all") package fields. |
data frame
pkgs() pkgs(which = "all", return = "all")
pkgs() pkgs(which = "all", return = "all")
Replaces emoji codes like :tada: with unicode like 🎉.
replace_emoji(x)
replace_emoji(x)
x |
Character. Text string within which to replace codes |
Text string with emoji unicodes
x <- replace_emoji("hi :tada: testing \n\n\n Whow ! 🔗 \n\n\n :smile:") x
x <- replace_emoji("hi :tada: testing \n\n\n Whow ! 🔗 \n\n\n :smile:") x
Find Mastodon username from rOpenSci author pages
ro_masto(name)
ro_masto(name)
name |
Character. Full name as on RO author pages |
Character URL to mastodon profile if it exists, NA otherwise.
ro_masto("Steffi LaZerte")
ro_masto("Steffi LaZerte")
Extract YAML keys from block
yaml_extract(yaml, trim = "~~~")
yaml_extract(yaml, trim = "~~~")
yaml |
Character. String from which to extract YAML keys |
trim |
Character. Text to remove from the YAML block before processing. Usually the text that defines the block. |
data frame of yaml keys
yaml_extract("~~~start: 2023-11-12\nauthor: Steffi\n~~~")
yaml_extract("~~~start: 2023-11-12\nauthor: Steffi\n~~~")
Create a draft issue to post to Mastodon and LinkedIn
Description
Formats the body and title of an issue and posts it on "rosadmin/scheduled_socials". The issue will bed opened in a browser for editing and confirmation. Note that issues will not be posted until the labels "draft" and "needs-review" have been removed.
Usage
Arguments
time
Date/time. Date and time at which the post should be made
tz
Character. Timezone (from
OlsonNames()
) in which to posttitle
Character. Title of the post (
[Post]
and the date will be prepended and appendedbody
Character. Text to be posted (omit the YAML for posting info; #RStats and @[email protected] will be appended for Mastodon, #RStats for LinkedIn), or link to text file with both Mastodon and LinkedIn body text, headed by by —- Mastodon —– and — LinkedIn —–.
where
Character vector. Either
mastodon
and/orlinkedin
to specify which platforms this should be posted on.avoid_dups
Logical. Don't post an issue if any open issue has the same title.
add_hash
Logical. Whether to automatically add the RStats hashtags.
dry_run
Logical. Whether to perform a dry run (do not post, but display draft if
verbose = TRUE
).open_browser
Logical. Whether to open the issue in the browser.
over_char_limit
Function. Stop or warn if over the character limit?
verbose
Logical. If dry run, displace draft?