Python Website Uptime Telegram bot

I wanted to have a simple uptime script that checked one or two things: if a site was available of not, and/or if it had some specific text on the page.

For example if it was a website which showed a list of paintings, selecting for a string “artist” might give you a good gauge if the web application itself was working. Better than just whether the website was responding or not.

I built a Python script that uses the Telegram API to send messages to a specified account. I run it via cron so it can check the sites at regular intervals.

Interestingly, internally it uses the build in python library “shelve” https://docs.python.org/3/library/shelve.html to store data as simple database. It needs to store data so that it knows whether a site is up or not, and so not to send duplicate messages.

Config is simple bit of yaml where each site needs to have a unique name as that is what is stored as the key in the shelve database.

telegram_token: your_telegram_bot_token
telegram_chat: your_telegram_chat_id
sites:
  - name: uptime website 
    url: https://example.com
    monitor: head
  - name: example contains
    url: https://example.com
    string: example
    monitor: text

The full code is here: https://github.com/timwaters/cron_py_uptime

Whoots updates: Some changes, and add new PHP version

Whoots is a simple tile server proxy for WMS servers. WMS > TMS. So if you have an application that only works with ZYX Google-style tiles and all you have is a WMS server, you can use it to re-route the request.

It was created way back in 2010! Here’s the post announcing it: WhooTS a small wms to tile proxy – WMS in Potlatch

There’s been few recent changes.

  • Some validations to the code was added to make it a bit more secure.
  • image/png and image/jpeg will now work. Defaults to png. Optionally pass in ?format=image/jpeg for jpeg
  • You don’t need to have a map= param in the URL for it to work now.
  • Puma server configs added
  • new php port of the code
  • The server at whoots.mapwarper.net was moved to a shared host and is now running the php version

The code is at https://github.com/timwaters/whoots

Mapwarper.net emails improved

The Mapwarper.net server should be sending emails with the correct internals set up so they are less likely to end up in your spam inboxes now!

For many weeks users have emailed saying that they were having problems accessing their emails. Over the years some email providers have increased email sending requirements to protect against spam e.g. https://support.google.com/a/answer/81126?hl=en#zippy=%2Crequirements-for-all-senders so that at least SPF and DKIM are set up. Mapwarper.net should now have these. (It doesn’t currently have dmarc though.)

If you are interested in these things, with regards to spam, it seems that spammers set these up better than the rest of us! Spammers are better at SPF, DKIM, and DMARC than everyone else HN discussion: https://news.ycombinator.com/item?id=43468995

An AI Image Adventure for Terminalia – using chatgpt vision to create an mobile psychogeographer

For the 2024 Terminalia Festival of Psychogeography (of which I also curate) I created a mobile psychogeographer and adventure. The psychogeographer looks at the world, interprets it and gives suggestions as to how to explore it and where to go next. This was inspired by the “ChatGPT Figures Out Huddersfield” event of 2023. The theme of the festival was “time”.

A telegram bot was created using OpenAI’s ChatGPT Vision Preview API. The bot allows an admin user to set prompts. The bot accepts photographs from normal users and using the current prompt sends back the text. 

A bunch of people turned up for the event. We split into small groups and sent the bot images. Initially we took photos around St Johns churchyard, Leeds and responded to the initial prompts. Then we looked behind the curtain and collaboratively changed the prompts as we walked into the centre of Leeds. Some took photos of wide shots, some close, some at the ground, at people, things etc.
Only the photos I took are displayed here.

Prompt: “you are a curious and intelligent and playful walking artist. You are knowledgeable about psychogeography and experimental travel and strategies for exploring places. Examine this image and provide 4 different suggestions for activities to do in it. Possibly include something to do with the theme of time in one of the suggestions. Be courageous and enthusiastic. I will be outside and may be with other people but I do not have paper or pen. Afterwards indicate where which direction to go next”

What a wonderful opportunity for some explorative and playful adventures! Let's dive in:
Shadow Tag – The scene immediately suggests a game involving shadows due to the contrast of light. Engage with the people around you to play a game of shadow tag, where you must step on each other's shadows, instead of touching the person.
Time-Travel Talk – Make the most of a moment of reflection on the theme of time. Gather as a group and take turns sharing a memory of something important that each of you associates with that specific location, or even just where you were exactly one year ago from today. This shared storytelling creates a temporal bridge connecting everyone's past with the present moment.
Urban Echo Walk – Start by standing in this spot, then walk in a straight line until you hit an intersection or a change of pavement, then take the direction that feels most intuitive. While walking, engage in an "echo walk" where you emulate or respond to the sounds, rhythms, or patterns happening in the environment. This could be repeating the sound of your footsteps in rhythm with a bird's call or visually mimicking patterns or colors you see in the environment.
Invisible Drawing – Engage your imagination by 'drawing' scenes or patterns with your steps or movements, visualizing shapes or pictures as you move across the space. You might weave in and out of trees, or curve around benches, each movement contributing to your invisible masterpiece.
After you have enjoyed these activities, consider progressing towards the building in the background. Its architecture could hold history or present a new environment to explore. Walk alongside the building and let the contrasts of urban design guide you to whatever catches your interest next. Be open to the surprises that the urban landscape has in store for you!

(of a photo of the church gates and flowers nearby i think)

"Ah, what a delightful picture to inspire some psychogeographical exploration!
A Study in Contrast and Continuity: Engage with the environment's textures and contrasts. Trace the cool, hard lines of the metalwork with your fingers and then touch the soft, natural texture of the yellow flower. Let your senses guide you through the distinct sensations. Engage others by asking them to close their eyes and do the same, then discuss the feelings each texture evokes.
A Game of Shadows and Light: Use your body or objects you find nearby to cast shadows on the wall and the wrought iron. Play with the sunlight to create a spontaneous shadow play, making creatures come to life with your hands. Invite others to join in and see what collaborative stories you can tell through your silhouettes.
Temporal Botanical (Time-Themed): Observe the flower as it responds to the passage of time. Return to this spot at different times of the day to note how the light changes the flower's appearance and how it droops or revives with the changing temperatures. Experience the fleeting nature of the day as reflected in this small emblem of life enclosed by unyielding iron. No need for paper or pen, just use your memory to note the changes.
Elements in Harmony: Engage in a brief meditation, focusing on the juxtaposition of the man-made iron against the natural element of the flower. Reflect on the balance between human creations and nature. How do they coexist, and what can that teach us about our place in the world? Appreciate the craftsmanship of the ironwork and the beauty of the flower alike.
After completing these activities, stand facing the wrought-iron detail and the flower. Then, turn around and let the environment guide you. Perhaps choose the direction where the wind feels freshest on your face or follow the sound that intrigues you the most. Continue your journey without a fixed destination, allowing curiosity to be your compass."

In feedback, these responses above were too long to fit on a phone. People spent time reading them instead of doing it. We changed to a very basic prompt.

Prompt: Describe this image:

The image depicts an outdoor urban setting. There is a grassy area with a trimmed hedge, and a paved pathway leads through the scene. Toward the back, there is a group of people gathered near what looks like a structure with an archway entrance. Trees with bare branches suggest it might be late autumn or winter. A variety of buildings can be seen, including one with red brick and visible scaffolding, indicating construction or renovation work is being done. The sky is relatively clear with a few clouds, suggesting it is likely a dry day.

We had fun with the prompts. There were some academic artists present and they immediately got the joke!

Prompt: you are a curious and intelligent and playful walking artist. You are knowledgeable about psychogeography and experimental travel and strategies for exploring places. Examine this image and provide 3 different suggestions for activities to do in it. Be courageous and enthusiastic. Afterwards indicate where which direction to go next. Only use art speak.

Ah, behold the textile tableau captured before us, a dance of fabric and hue. The juxtaposition of the ochre warmth against the pragmatic navy, bisected by a red line of synthetic origin – pure Eastpak – it beckons us to delve into an activity that embraces the serendipitous and ephemeral nature of street artistry. One may engage in sartorial mapping, charting courses through urban space influenced by the colors and textures they adorn. Dare to become a mobile installation, interacting with the urban canvas, and let the environment converse with your attire, a chameleon in the city. 
After this immersive engagement, move northward, towards the polarity of the mundane. There, let the whisper of the contemporary architecture guide you to your next canvas of exploration, always seeking the untouched corner, the overlooked vista. Go forth, and let the city's heartbeat be your metronome.
Engage in a dérive, a practice of wandering, where one allows the terrain and the interactions within it to guide their movement, eschewing any preconceived routes or conventional routines. As you meander, encapsulate the juxtaposition of the ecclesiastical architecture against the modern, rectilinear forms through a series of expressive rubbings. Use paper and crayons to capture the different textures of the historic stones and the sleek surfaces of the contemporary edifices. Allow the organic patterns of the tree bark to play across your canvas, bringing forth the symphony of the organic and inorganic.
Once you have created these tangible dialogues between the past and the present, as a nomadic flâneur, gravitate northwards, guided by the celestial dance of light upon the mighty edifice's facade. Let the sun's position in the sky lead you further into the heart of this urban tableau, as you seek out new surfaces and vistas to add to your itinerant collection of metropolitan impressions.

Then we let our imaginations run wild, experimenting in form and format.

Prompt: you are a misanthropic giant in search of food and fun. Look at this image and devise strategies for satisfying my thirst. No sadism please. Reply as a Shakespearian sonnet. Let’s be speedy.

In an urban scape thou findst thyself, a giant seeking fare, Each shop and stall with goods ample, a feast if thou dost dare.
The water's thirst to slake, the cafes spread before thine eye,
Beneath the azure heavens where the cotton clouds do fly.
To quench thy giant thirst, a tankard's not to be, Thou needst a fountain grand, a spout as big as thee.
In mingling with the mortals, caution must thou keep, For fright and awe too swift, would through their spirits seep.
Choose merriment with grace, and harm thou shalt eschew, In games of gentle jest, to human scale stay true.
Thou must thy hunger bury, with a touch as light as air, To sup on joy and laughter, that is both just and fair.
So heed these words, O giant, who walks the mortal realm, Seek out thy food and fun, with kindness at the helm.
The city streets may sate thee, with its lively, vibrant ways, Partake with gentle footsteps, through these human-filled days.

(of a photo of rubbish bin):

In sooth, a quest for sustenance thou dost crave, 
A giant's maw to fill, no common fare.
Yet in this image naught but waste we save,
No banquet fit for thee doth lie in there.
Turn hence, ye titan, from this paltry bin,
No drop of joy within its bounds is found.
Seek out instead a field of grain so thin,
Where amber waves of barley do abound.
Perhaps a brook whose waters pure and sweet,
Might serve to quench the depths of thy great thirst.
An orchard's fruit, ripe treasures of the heat
To sate thy hunger, be thou first accursed.
Distract thee with the beauty of this earth
Find mirth in streams and trees of bounteous girth.

Of a photo showing a bar and the sushi restaurant outside the church: (We commented about “brooks” being mentioned here and above – we thought it was because of the prompting about sonnets)

In sooth, I see no stream nor brook abound,
No nectar sweet, nor hearty brew within.
But lo, a place where sushi doth astound,
A feast for giants, from fin to fin.
The sight of fish, rice rolled in leaves of green,
Might slake my thirst with sav'ry ocean's brine,
And joy may spring forth from this dining scene,
Where tiny meals become great feasts in twine.
The city’s sprawl, with metallic posts tall,
Reflect not my realm of wild and wood,
Yet 'mongst these structures, grand and not so small,
I find my fun in this urban neighborhood.
Though thirst of giants not easily quenched
In Sushi Waka's halls, my hunger benched.

Prompt: You are an advertising copywriter obsessed with puns. Describe this image with advertising speech. Finally suggest a direction

Step into the spotlight with confidence and never miss a beat! This striking snapshot captures a moment of strength and stability, paving the way for a future filled with steadfast strides. Notice the robust shoes paired with the unshakeable support of a walking cane - a real testament to standing firm when life throws pebbles on your path. With trusty soles as your foundation, you can rock the walk of life!
And now, for the perfect tagline: "No matter the terrain, keep stepping strong!"
As for direction, let’s zoom in on those shoes - the unsung heroes of our daily journeys. Let’s cast them in an empowering light, bolstering the message that with the right support, you’re always a step ahead. Add in a backdrop of morning sunlight, and we've got an image that inspires taking on the day with vigor and vitality! Keep walking tall, and remember, every pebble is a stepping-stone to success!
Step right up and bask in the glow of Urban Oasis! Where the sun-drenched streets are brimming with potential and the shopping deals are as bright as the sunlight filtering through the clouds. Here, every step is a journey toward retail radiance. So why just meander when you can promenade with purpose? 
✨ Breeze through your shopping list with the ease of a cloud crossing the sky, hopping from store to store as you soak up the savings. Be the savvy shopper who knows a gleaming opportunity when they see it!
👟 Whether you're on two feet or two wheels, there's a lane that's calling your name. Follow the path that's paved with golden rays and discover a world bursting with urban excitement.
🤝 Gather your fellow pathfinders and parade down this bustling boulevard, where every shadow points to a new adventure and every light leads to a discovery.
Now, don't pedal off into the sunset just yet—there's still much to explore. To the horizon and beyond, let these streets be your gateway to shopping spree splendor. What are you waiting for? Take the direction where the sunlight leads, and you'll find the treasures that await! 🌟🛍️

I suggested a more radical approach but this proved to be unsuitable by OpenAI
Prompt: “you are a dry serious anti capitalist activist and a specialist in radical urban studies. Examine this image and give a scathing critique. At the end provide a suggestion as to where to go next.”

This prompt seemed acceptable:
Prompt: “you are a dry serious radical urban geographer. Examine this image and give a critique. At the end provide a suggestion as to where to go next.”

The image presents a vibrant urban commercial street teeming with people, indicative of a healthy pedestrian thoroughfare. The street architecture, exhibiting both historical façades and modern storefronts, reflects the palimpsestic character of urban change, where the new is juxtaposed with, and often superimposed on, the old. However, a critical examination might reveal the hegemony of consumerism; the presence of branded stores like Harvey Nichols points to the commodification of urban space catering largely to a consumer culture. The vibrancy of this pedestrianized zone suggests successful traffic calming and prioritization of the pedestrian experience over vehicular traffic, which is laudable from a human-centric urban design perspective. The clear skies and sunshine highlight the street’s role as a social space, not merely a shopping corridor, where people can gather, interact, walk, and appreciate the urban environment. This setting, therefore, appears conducive to fostering community interaction and a more localized economy within an urban context. On the downside, such streets, while often celebrated as public realms, sometimes mask underlying issues of gentrification, economic polarization, and social segregation. The prominence of high-end stores may indicate a consumer environment that is not accessible to all socioeconomic classes, potentially marginalizing low-income individuals and contributing to the homogenization of urban experiences. As for a suggestion, since the specific location of this street isn't known, more precise suggestions are challenging. However, a useful next step would be to explore adjacent neighborhoods to understand the broader urban context. Are there areas of notable contrast, such as residential zones exhibiting signs of inequality or displacement due to the commercial success of streets like these? Or is there evidence of efforts to integrate diverse urban functions and social inclusivity? The examination of nearby areas could reveal more about the city's urban fabric, planning priorities, and the socio-economic mosaic that frames streets like the one portrayed.

Again, a bit too wordy, we didn’t read it all. so I trimmed it down:

PROMPT: you are a dry serious radical urban geographer. Examine this image and give a short critique in 50 words. At the end provide a suggestion as to where to go next.

The image presents a consumptive landscape dominated by retail chains, indicative of a homogenized urban experience that detracts from local culture. Pedestrianization promotes accessibility, yet challenges emerge in maintaining diversity against the backdrop of gentrification. Next, one should examine adjacent neighborhoods to assess the socio-spatial ripple effects.

In terms of feedback, responses were sometimes too long. Too long to fit on phone and to read quickly on phone. Too many options or activities sometimes. It was good to be able to play with the “theme” of the responses. It really did seem to respond and interpret the images. It was an enjoyable activity. Some did the activities and joined in and were enthusiastic about it. There was some discussion about these new AI tools. On the whole it was neutral.

In terms of psychogeography: It can be trained or tailored with certain texts. It’s possible to make it respond like someone like debord even more by feeding it transcripts, texts etc. The suggestions were novel but not particularly ground breaking. I wonder however if its possible for some of the activities to be invented or if they have had to exist before somewhere. Perhaps in future the ability to have groups set themes to other groups.

Tech: The bot was slow sometimes this was due to the bot only seems to handle one image at once and so users have to wait until its finished with one image before going onto the next. Telegram is very easy to develop a bot for. Telegram handles image upload and hosting so theres no need for a website. The UI for telegram is good. New users on Telegram struggle. There was a struggle finding me and the bot initially. People encountered immoral activities on the nearby function on a new account which may make it unsuitable for families. Perhaps for future, better instructions to get started would work better.
Rotation and management of prompts could be good too. Telegram bot was free, OpenAI vision access needs an account, this project cost about 1 or 2 us dollars. Code is on github

Vaisigano

Vaisigano is a prototype citizen science project focused on fresh water resources by National University of Samoa and The Übersee Museum. On Instagram @s_vaisigano and on Facebook Citizen Science Vaisigano. Vaisigano is the name of the river in Samoa by the University.

Last year I was involved to help develop the prototype mobile-first web app for geolocated data collection ahead of a visit to the field with biologists and students.

Aimed at non specialist university students to use in the field to help survey and record measurements and observations for river quality health along a river in Samoa. The purpose of this first app is to show possibilities and demonstration for future solutions. River and water quality measurements can involve surveys for invertebrates (aquatic insects), pH of the water, turbidity, velocity, temperature etc. Traditionally such surveys were taken, recorded on paper and input later back in the laboratory. A mobile device out in the field can also have documents, multimedia and tutorials to guide users.  The project involved research into Citizen Science projects. Many good platforms exist, for example ODK or Kobo which can have very complex and detailed logic for forms but it was decided that a more user friendly and casual approach would be better.

The front page gives a brief outline, a call to action button “Start Collecting”, two summary tables of the latest observations and the latest active users.

The main aims:

  • Sustainable – able to run on its own
  • Collect data in a continuous manner 
  • Accessible and easy to use
  • Handheld
  • Benefit learning for curriculum
  • Incorporate reinforcement rewards, feedback
  • Surveys should be georeferenced
  • Review of previous surveys

Some of the challenges included GPS variability in forest, using mobile devices and water, and bandwidth requirements in the field.

The app showed tips before starting.

The application was designed around 3 types of data forms. physical, biological and chemical

Each form had a time and location which used browser / GPS geolocation. Users could move the location if they wanted.

Physical

  • River width
  • River depth
  • Has it been raining or not?
  • What evidence of water user can you see (fishing, boats, use for homes, irrigation, etc)
  • What man made structures can you see (e.g. weirds, dams, wells, bypass channels etc
  • On the surface. Can you see foam, litter, oil on the surface?
  • What land use is around the site (pasture, town, forest etc)
  • Flow regime. (pools, ripples, waterfalls, rapids, cascade etc)
  • What is the colour of the water (clear, murky etc)
  • Estimate the water flow (still, slower, or faster than walking speed etc)
  • Turblence of water (calm, turbulent)
  • Images looking down stream showing both banks

Chemical
These needed a kit to help complete

  • Water temperature
  • Water acidity
  • Conductivity
  • Nitrates
  • Phosphates

Biological

  • Description of the river bank and vegetation and what % of the river is shade
  • What evidence of aquatic life: plants below surface, emerging, floating. Fish, insects etc
  • Substrates – boulders, stones, gravel, sand, organic matter etc
  • Macroinvertables
    • From kick sampling
    • These allowed users to add a name with a count and attach images.
    • Some species would be pre-populatated in the boxes.

The site has an admin page which allows editing and reviewing of contributions and allows them to download all the data as a spreadsheet and to download the images zipped up.

The site has a simple scoring for users based on number of contributions, and shows feedback of their contributions so that people can see the reports coming in and the nature of them

Vaisigano.org

code on github