# 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 2
# self = https://watcher.sour.is/conv/i6zhaoa
I just rotated my feed and found out that my script is not working properly. Had to fix something by hand.
Alright, found the bug. This time I ran the archive script in the directory where my main feed is located and hence specified a relative path to it, so just the filename twtxt.txt. Getting the directory with os.path.dirname("twtxt.txt") resulted in an empty string that was passed to os.listdir("") which then raised FileNotFoundError: [Errno 2] No such file or directory: ''. That in turn was transformed to None, indicating that there is no previous archive feed available. Hence no prev metadata field was generated for my main feed. os.path.abspath(…) to the rescue!

If I had used ./twtxt.txt in the command line argument, I would not have run into this problem. This is basically what I did the last times. Ran the script from another directory, so the relative path still contained some directory component when cutting off the filename at the end.

For the unit test I stumbled across [contextlib.chdir(…)](https://docs.python.org/3/library/contextlib.html#contextlib.chdir). This is very neat! Unfortunately, no Python 3.11 for me, yet. :-(