chubin/cheat.sh

cht.sh/:sheets endpoint

abitrolly opened this issue · 1 comments

A reminder to add https://cht.sh/:sheets endpoint with the information about used sheets. JSON should help request the data from the main page to format into stats. The data can include upstream repos, descriptions and revisions.

dotcs commented

I would like to add some support to this issue. I've worked on a small bash script that uses jq to create a json file with information about the latest upstream repo information. It's not perfect yet and can be improved in various ways. I'd be interested to learn if that information is sufficient to feed the planned endpoint? If yes, we could improve the script and make it part of the update process of the upstream repositories. What do you think?

#!/bin/bash

UPSTREAM_PATH="/home/$USER/.cheat.sh/upstream"

SET=()
for upstream in $(find $UPSTREAM_PATH -mindepth 1 -maxdepth 1 -type d); do
    cd $upstream
    JSON=$(jq -c --null-input \
        --arg hash $(git log -n 1 --pretty=format:"%H") \
        --arg upstream_url $(git remote get-url origin) \
        --arg last_updated $(git log -n 1 --pretty=format:"%aI") \
        '{"hash": $hash, "upstream_url": $upstream_url, "last_updated": $last_updated}')
    SET+=("$JSON")
    cd ..
done
echo "${SET[@]}" | jq -s '.'

The current result looks like this:

[
  {
    "hash": "835d077573fea060406ca6e5096779526ae96760",
    "upstream_url": "https://github.com/adambard/learnxinyminutes-docs",
    "last_updated": "2022-04-08T20:06:22+08:00"
  },
  {
    "hash": "f5bab6da9d3b8cf51333d1b4ffb54377002d2216",
    "upstream_url": "https://github.com/chubin/late.nz",
    "last_updated": "2019-04-25T20:40:45+02:00"
  },
  {
    "hash": "d8dd242f9fe057b934856a4b6aec04395c55adde",
    "upstream_url": "https://github.com/cheat/cheatsheets",
    "last_updated": "2022-04-15T15:01:50-04:00"
  },
  {
    "hash": "a5dae0e111c106ace07bb207e02814bf00fd6b74",
    "upstream_url": "https://github.com/chubin/cheat.sheets",
    "last_updated": "2022-04-17T07:33:46+02:00"
  },
  {
    "hash": "9ad63ea473a958506c041077f1d810c0c7c8c18d",
    "upstream_url": "https://github.com/acmeism/RosettaCodeData",
    "last_updated": "2020-02-17T23:21:07-08:00"
  },
  {
    "hash": "991f974b9e7816d0a33750a0963dba5df897a06d",
    "upstream_url": "https://github.com/tldr-pages/tldr",
    "last_updated": "2022-05-02T21:00:37+10:00"
  }
]