From 67d17c4a3f5d0dcfa39d22ccdbc0a780f311a8a9 Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Mon, 3 Aug 2020 23:39:10 -0600 Subject: [PATCH] add extremely overdetailed gender script --- fish/gender-swap | 7 +++ text/gender-swap | 131 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 fish/gender-swap create mode 100755 text/gender-swap diff --git a/fish/gender-swap b/fish/gender-swap new file mode 100644 index 0000000..1855192 --- /dev/null +++ b/fish/gender-swap @@ -0,0 +1,7 @@ +#!/usr/bin/env fish + +function gender-swap -d 'Swaps gender' + "$_agw_dir_rc"/text/gender-swap $args +end + +## EOF diff --git a/text/gender-swap b/text/gender-swap new file mode 100755 index 0000000..6c43a23 --- /dev/null +++ b/text/gender-swap @@ -0,0 +1,131 @@ +#!/usr/bin/env ruby + +require 'erb' +require 'net/http' +require 'uri' +require 'json' +require 'cgi' + +# Flattens any data structure to URL parameters, recursively. Because +# apparently the standard library just doesn't fucking provide this. +# Oh well. At least it isn't something as simple as *recursively +# copying an array* (looking at you Lua.) +def url_params param, key, output = {} + case + when param.is_a?(Array) + param.map.with_index do |v, k| + url_params(v, key + "[" + k.to_s + "]", output) + end + when param.is_a?(Hash) + param.map do |k, v| + url_params(v, key + "[" + k.to_s + "]", output) + end + else + output[key] = CGI.unescapeHTML param.to_s.gsub /<\/?[^>]*>/, "" + end + output +end + +CLIENT_KEY = ENV["_agw_secret_gender_swap_client_key"] +CLIENT_SECRET = ENV["_agw_secret_gender_swap_client_secret"] +ACCESS_TOKEN = ENV["_agw_secret_gender_swap_access_token"] + +ALIGNMENT = ARGV.pop +PRESENTATION = ARGV.pop +PRONOUNS = ARGV.pop.split("/").map do |pro| + path = if pro == "they" then "they/.../themself" else pro end + %(#{pro}) +end + +Net::HTTP.start("social.greyserv.net", use_ssl: true) do |http| + auth = { + "Authorization" => "Bearer " + ACCESS_TOKEN, + } + status = <<_end_ +pronouns: #{PRONOUNS.join "/"} +presentation: #{PRESENTATION} +alignment: #{ALIGNMENT} +_end_ + fields = http.get( + "/api/v1/accounts/verify_credentials", + auth, + ).body + fields = JSON.parse(fields)["fields"].map do |field| + if field["name"] == "current pronouns" + field["value"] = PRONOUNS.join "/" + end + field.delete "verified_at" + field + end + http.patch( + "/api/v1/accounts/update_credentials", + URI.encode_www_form(url_params(fields, "fields_attributes")), + auth, + ) + http.post( + "/api/v1/statuses", + URI.encode_www_form( + "status" => status, + "in_reply_to_id" => "104612572584164654", + "spoiler_text" => "current gender", + "visibility" => "unlisted", + "language" => "en" + ), + auth, + ) +end + +template = ERB.new < + + + + + + Gender + + + +

Current

+ + + + + + + + + + + + + +
Pronouns +
    + <% PRONOUNS.each do |pro| %> +
  • <%= pro %>
  • + <% end %> +
+
Presentation<%= PRESENTATION %>
Alignment<%= ALIGNMENT %>
+

Explanation

+

I am genderflux, + and my gender identity changes often. The information on this + page will be up to date with my Mastodon account, so please + check either of them if you're wondering how to most correctly + address me at a given time! Please note that it is always fine + to use they/them for + me, and I don't usually mind if pronouns other than what I'm + currently using are used.

+ + +html + +Net::HTTP.post( + URI("https://fuck.greyserv.net/gender.cgi"), + template.result, + "Content-Type" => "text/html", +) + +# EOF