I suck this stuff down like squishy-ripe hachiya persimmons. So yummy. I certainly don't understand all the details clearly, but I get the general #gist, and knowing the people sit around thinking about this makes me incredibly #happy. I'm not sure why. Maybe I'm just thrilled by this kind of #curiosity.
I am busy with testing for my next #MastoBot implementation, for a remindMe bot idea.
The main idea is to allow users to mention it and say @remindMe 2 weeks 3 days 2 hours 5 minutes, which would then in turn message them, reminding them of the post which they replied to with this comment.
Such functionality can sometimes be difficult, and regex gets its hate for speed, complexity, and readibility. But this just works great in #Python for a problem like this.
Here is the #Gist of an early prototype and example for those interested!
The bot is also at @remindMe, but it isn't operational yet. You can follow it for updates.
The best solution is to proably make an ABC class of dict and then parse the JSON and throw your own exceptions.
I recently did something similar with the config files for my bots. I have a ConfigAccessor class, which reads a YAML file to a dict. What I found was, that if a user miss-configured their file, everything crashed due to missing keys etc.
So I made this class which handled it for me, and I just treat it like a normal dictionary. Here is the #gist
#puzzle for #python fans:
where does this error come from?
In my opinion, one of the great things about #python is that it's simple and straightforward - you don't get unexpected surprises. But there are a few exceptions, as this example shows.😉
Recently, as I've worked on #MastoBot, I have enountered many situations where my code waits, takes a long time to execute, and my main loop is blocked.
With my @3dprinting bot, this only happens on the first run of a clean config, where all previous posts are fetched from the #Mastodon API and stored in a #Redis database The reason is irrelevant, but basically for metrics.
Thus, when the bot starts, it makes about 1.3k requests, one for every post by the bot. This can take about 10 minutes, with the API, paging, network speed, and rate limiting.
During this time, no mentions, new followers, or any other notifications are processed. Then BAM! Everything goes through, and WOW, we are back on track.
I got it to work now. Seems because you need to use asyncio.run() you need to wrap al the functions with async, then have another function which you then call.
I am busy messing around with #Python#async, for API consumption, but the API library isn't implemented with asyncio.
I can either fork the library and possibly switch its request object with an async version, but often we might not be able to do this and we need to work with blocking functions.
I struggled to get this working in my current code, so I tried it in another file and got it to work. There are still a few things I could change, allowing for more threads and using an executor, but here is the #gist