# I am the Watcher. I am your guide through this vast new twtiverse.
# 
# Usage:
#     https://watcher.sour.is/api/plain/users              View list of users and latest twt date.
#     https://watcher.sour.is/api/plain/twt                View all twts.
#     https://watcher.sour.is/api/plain/mentions?uri=:uri  View all mentions for uri.
#     https://watcher.sour.is/api/plain/conv/:hash         View all twts for a conversation subject.
# 
# Options:
#     uri     Filter to show a specific users twts.
#     offset  Start index for quey.
#     limit   Count of items to return (going back in time).
# 
# twt range = 1 18
# self = https://watcher.sour.is/conv/u4bhkvq
@mckinley I believe you can manage from here https://ttm.sh/eb8.tgz
@adi @mckinley Run it with pp index.upphtml < twtxt.txt > index.html
@adi Thank you very much for your help, I'll take a look at it in a few minutes.
@mckinley You don't need help, I believe you could have done it yourself. 😎
@adi If I stuck with that shell script abomination I have no doubt I could have hacked something together but it was already taking half a second to process my feed and nearly a minute to process @prologic's feed, although that one completely broke the script and mangled the output.
@prologic @mckinley Meaning you could learned awk. @prologic feed is a special case 😋. Ok, optimized it some:\n\nhttps://clbin.com/MCzFb\n\n\nHow does it run on your side?
@mckinley @prologic \n\n> although that one completely broke the script and mangled the output.\n\nI assumed all lines start with a date, so lines starting with '#' break the script. You're required to delete those lines.
@adi\n> I assumed all lines start with a date\n\nSo did I in my attempt, but even after a quick grep -v '^#' it would still break everything.\nI'm trying out the newer version now. Will report back.
@adi
> I assumed all lines start with a date

So did I in my attempt, but even after a quick grep -v '^#' it would still break everything.
I'm trying out the newer version now. Will report back.
I don't see much a difference between the new version and the old version. There are a couple of small bugs I've seen. "2021: January-April" is hard-coded into the twt page template as well as the date "27 April 2021 01:04" for each twt. The timestamps are also printed along with the twt because it just copies the line through. What is smu used for?
My template (most recent copy) attempts to solve the latter two problems, but I think it's another job for awk to avoid the dumpster fire below.

timestamp=$(echo "$line" | grep -Eo '^[0-9]{4}-[01][0-9]-[0-3][0-9][Tt][0-2][0-9]:[0-5][0-9]:[0-5][0-9](\.[0-9]+)?([+-][0-2][0-9]:[0-5][0-9]|Zz)')
twt=$(echo "$line" | sed -e 's/"/\"/g; s/
/\ -) hyperlinked=$(echo "$twt" | sed 's|http://[^ ]*[^ ,.;:)>}!]|<a href="&">&</a>|g; s|https://[^ ]*[^ ,.;:)>}!]|<a href="&">&</a>|g')
My template (most recent copy) attempts to solve the latter two problems, but I think it's another job for awk to avoid the dumpster fire below. \n
\ntimestamp=$(echo "$line" | grep -Eo '^[0-9]{4}-[01][0-9]-[0-3][0-9][Tt][0-2][0-9]:[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?([+-][0-2][0-9]:[0-5][0-9]|Zz)')\ntwt=$(echo "$line" | sed -e 's/"/\\"/g; s/
/\\/g' | cut -f 2- -)\nhyperlinked=$(echo "$twt" | sed 's|http://[^ ]*[^ ,.;:)>}!]|<a href="&">&</a>|g; s|https://[^ ]*[^ ,.;:)>}!]|<a href="&">&</a>|g')\n
It looks like I just have no idea what I'm doing, and that's partially true, but those are the best solutions I was able to get while conforming to POSIX (without awk). I'll take the time at some point to learn more about awk and come up with a better solution for this.
I'm an awk noob myself (@adi wrote the script that parses my twtxt feed) but if I've learned anything, is that it is one little powerhouse of a language.
@eldersnake I've seen a lot of very impressive things done with awk.
@mckinley You don't have to sanitize the twt, in pp you are required to sanitized template strings not variable values. You can just output unsanitezed, it's safe.
@mckinley @eldersnake Wrong tool for the job, but still fun I guess.
@eldersnake I'm not that great with it either, but until now I realized how powerful it is.