How APIs can help us with chemistry

You are probably familiar with taking results from a paper and using them to your advantage. Sadly, experiments are oftentimes hard to replicate, yield underwhelming results or the chemistry just does not work for your project. Well that’s at least my own experience. Oftentimes, there is just this one feeling you have: «Man, the developers of this protocol just did not want anyone to use it. Why the heck would they document their work in such obscure manner! Clearly they had not in mind that people would try to build upon it! »

As you might guess from the date of the post, we are in a bit of a downtime and have gained some time to experiment with ideas, rather than chemicals. One such “Gedankenspiel” was to improve our experiment notification system. You see, we have built a plethora (define plethora as 3) of automated setups that we and our lab students use for screenings or synthesis. Although it is very tempting, you cannot stick around all the time to watch the setups. On top of that, you need notifications for when a manual step has to be performed. So far, we have used simple email notification and Telegram Gmail Bots. In some cases, this is not elegant at all. For example, when you just want to check whether the parameters are alright or when your student forgets to put in his email, so you are forced to notify him personally to go and yield the fruits of their hard work!

Therefore, we thought about better solutions (again, downtime). It had to be simple, use python to collect data you get from the equipment (e.g. temperature or flow rate), look up what experiment or phase is currently running, display all information in a clear manner to everybody involved in the project. According to the almighty Internet, we had two simple solutions: Ether an own Telegram bot or just pushing the notifications to the website for everyone to see! And here is where the documentation comes in handy! Clearly the developers of this API wanted their system to be used and be improved by dear fellow scholars! It took astounding 15 minutes to find the documentation, copy-paste the couple of lines needed and it’s done! So…

Let’s check what our System is currently doing? (Click on the post below!)

WP api post update via python

Ahh, not burning down. At least for now… check it periodically, the status will change dynamically, when we are working again.

By the way, if you want to use this function yourself, this is how a minimal working example would look like:

# pip install python-wordpress-xmlrpc
# https://python-wordpress-xmlrpc.readthedocs.io/en/latest/overview.html#installation

# https://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/methods.html#wordpress_xmlrpc.methods.posts.EditPost

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import EditPost

# authenticate
wp_url = "https://Your-Domain.de/xmlrpc.php"
wp_username = "WP_Username"
wp_password = "WP_Password"
blog_id = 412
wp = Client(wp_url, wp_username, wp_password)

# post and activate new post
post = WordPressPost()
post.title = "Reactor Status"
post.content = "Smells funny?!"
post.post_status = "publish"
post.terms_names = {"post_tag": ["Reaktor Status"], "category": ["News"]}
wp.call(EditPost(blog_id, post))