00:02.679 Introduction
00:28.823 What is Astrobotany?
00:48.914 What is Gemini?
01:25.337 How do you play Astrobotany?
03:37.000 Timers
06:37.792 The code
09:05.724 Managing the plant
13:09.560 Conclusion
This talk gives a brief introduction to Emacs timer functionality. I explain how I used Emacs timers to water and harvest my flower on the gemini Astrobotany service.
About the speaker:
Christopher Howard is a simulator technican and free software ethusiast living in Fairbanks, Alaska. Christopher explains how he uses Emacs timers to automatically water and harvest his flower on the Astrobotany gemini service.
\<lounge-502> Not exactly a browser but after yesterday\'s Emacs
timer talk, I installed elpher and browsed around some gemini
websites and that was a really good experience.
Welcome to Watering My Digital Plant with Emacs Timers,a talk by Christopher Howard for Emacs Conference 2024.The goal of this talk is to givea brief introduction to Emacs timersusing the illustration of how I createda bot for the Astrobotany service.
What is Astrobotany?Let me jump to the home page.Astrobotany is a botany game or a simulationthat is played using the Gemini protocoland gemtext documents.
What is Gemini?The Gemini protocol is a small web protocol,similar to the HyperText Transfer Protocol,but with differing goals of simplicity,non-extensibility, and protecting privacy.Gemtext is a simple hyperlinking document format,the analog of the HyperText Markup Language, or HTML.Much more could be saidabout the design and goalsof the Gemini project,but that is not the focus of this talk.
And how do you play Astrobotany?First, you need to get a Gemini clientor what you might call a browser.Many clients are available,but I am using Elpher, a Gemini client for Emacs.Once you have your client running,navigate to the home page for Astrobotany,which is shown in this window.You'll see the URL for the home pagedisplayed at the top of the window.On your first visit to Astrobotany,you will need to create a client certificate,which will be used instead of a password.Your Gemini client will help youto create the certificate.Then you will go to the Visit Your Plant pagein order to view your plant,to water it, and to collect things from it,including money. So here you seethe plant that I'm currently growingin glorious ASCII graphics.There's also a color version available from this page.Back at the home page,you can do other thingslike go to the item shop,to buy items like badges, fertilizer,or post on the message board.In Astrobotany, gardener bots are fully legal.And to do an action on your plant,like watering the plant,all your bot needs to do isto access the appropriate Gemini URL or pagewhile presenting the appropriate certificatefor your plant.
And this brings us to Emacs timers.So the main function of interest to usis the run-at-time function.Here is the help documentation,which is available in any recent Emacs installation.As you see, the purpose of the functionis to perform an action at a specific timeto repeat it after a specific number of seconds.And so basically, all you have to do ispass in a function to run-at-time,telling Emacs how soon you want to run the function,and then how often you want to run thefunction after that.The function has a variety of options forspecifying the time parameter,that is, how soon you want the function to run.For our application, in which we'll berunning our functionsonce or twice a day at specific times,it is most useful tospecify the number of seconds until the event.This does, however, requirecalculating the number of secondsuntil a specific time of day. I willprovide code for this shortly.The run-at-time function does allow you tospecify the time parameter as a string,representing the hours and minutes.For example, 05:40.However, there is an oddity in thedesign of run-at-time,such that if the specified time of day hasalready passed,then the timer will run immediately,rather than in the future,as you might expect.This can be problematic, for example,if run-at-time is being called from your init file,since the timer will run immediatelyevery time you restart Emacs for any reason.I noticed recently that run-at-timealso allows you to pass in a valuefrom encode-time, which maybe does what we want,but I never bothered with testing that.Actually, I have a vague memory ofonce looking into it and it didn't seem to do what Iwanted, but honestly I can't clearly remember,so you may want to look into that yourself.What I ended up using was justpassing in a number of seconds.
So now we'll move over to the code.So I'll skip down here firstto the code that I wrote for calculating the number ofseconds.It's a function that calculates the number of secondsuntil a particular time of day in the future.You can see that you pass in the hour as a number from0 to 23 and the minutes as a number from 0 to 59. Andhere's the code, which will also be available later.I wrote another function, secs-until-weekly,which we do not need for this talk,but which is useful if you're runningevents which need to happen once per week.This function also requires a target hourand a target minute, but also requires passing in atarget day. And while we're on the subject of timersspecifically, I should mention thatEmacs has a very useful function called list-timers.So if I call the interactive function list-timers,it will give me a list of all the timerscurrently running.This page shows not only which timers exist,but also how long it will be until they run again,along with the periodic repeat value that youspecified.Furthermore, any timer can be canceled by moving pointover the timer and running timer-list-cancel,which on my system is bound to the letter c by default.This is very helpful while you are developingsome timer function.So I could cancel the timer that I already have runningfor shaking the plant,as well as the one for watering the plant.and back to the code.
So now we'll talk about the actual code formanaging the plant.So you see I have a variable set up herethat specifies where the certificate file,the public certificate file, as well asthe secret key file is located.This is where it is in my system.Of course, depending on your specific Gemini client,it may be in a different space and will likely have adifferent name.And here is the code for watering the plant,which I can call interactively.And the core of it here is that it uses thegmni utility, a command line utility tocall a particular URL while also loading upor presenting the required certificate.So in this case, you can see it is the URL that isrequired for watering the plant.This idea is very simple and the gmni clientor gmni command line programmakes this very simple to do.Here's another function for shaking the plant.Again it is almost identical except that weuse a different URL,one for shaking the plant instead of watering it.And again we want to shake the plantin order to get money to fall off of it.You need to water your plant at least once per day orit'll die.I usually water mine twice and just in case somethinghappens where Emacs was turned off because ofpower outage or something like thatthat I'm more likely to get it watered,and I shake it once per day because there isn'tany purpose to shaking it more than that.If you try to shake it more than that,then money no more money will fall off,or not much.So you see down here, I have the code thatactually calls run-at-time.I left here commented my original forms of thiswhich used the just specify directly the time of day.As I mentioned the problem with thatwas that it would...these functions would also get calledwhenever I restarted Emacs for anyreason and that was kind of annoying.So instead we have here the functions down herewhich uses secs-until-dailyto water the plantand then secs-until-daily to shake the plant.You see, I've specified the plant to get wateredat 4 in the morning and then the function is run againafter that, every 43,200 seconds, which translates toevery 12 hours,and then I shake the plants, shake the plantevery morning at 4.15 a.m. and once every [24] hours.With a little bit moresophistication, a little bit more work on the code,I could actually have multiple plants be watering andshaking multiple plants with multiple certificates,but I never got around to that.Didn't seem worth the bother to me.
So thank you for watching my video,Watering My Digital Plant with Emacs Timers.You'll see at the bottom of this pagelinks to the code for this talkas well as other things that I mentionedlike the source code for theElpher Gemini client,the URL for the Astrobotany capsule,as well as a link to more information aboutProject Gemini and my own personal Gemini capsulethat's being run off my own server at home.Thank you very much.