Using txti.es + Python as a data dashboard
Have you ever heard about txti.es? It’s a basic web page creator. You can basically create a very simple website by typing content into a form. I thought it might be used as a very simple frontend.
I always dabbled with automation. An example would be a scraping script that gets the job postings from a specific website or one that checks when the bus I take every morning leaves and sends this information by e-mail.
While sending an e-mail is one way to go I’ve always thought about making a dashboard. What I didn’t want to do is to mess around with some crazy web frameworks and hosting the service on my own.
txti.es seemed like an interesting choice. It’s simple, free and hosted by someone else. It doesn’t need any API. Editing can be done by just pushing POST requests. By just editing the website through txti.es interface and observing the requests the browser makes, with Inspect elements functionality, it’s easy to figure out what requests need to be pushed. Editing can be limited by adding an edit code.
I went with Python for sending the request. The script starts with the only module that’s needed (yay for simplicity!):
import requests
To create website you can do:
"""Create txti.es web page.
Keyword arguments:
name - the name for the txti.es web page. Not the same as title.
edit_code - code used for the web page editing.
content - the content of the web page.
"""
def txti_create(name, edit_code, content):
post_data = {
'content' : content,
'custom_url' : name,
'custom_edit_code' : edit_code,
'form_level' : "2", # dunno - constant
'username' : "", # dunno
'submit' : "Save+and+done"
}
txti_req = requests.post("http://txti.es", post_data)
return " >> Create txti. Response: {} {}".format(txti_req.status_code, txti_req.reason)
To modify the website you can do:
"""Modify txti.es web page.
Keyword arguments:
name - the name for the txti.es web page. Not the same as title.
ID - unique ID for this specific website. You can get it by first editing the web page through
txti.es web interface.
edit_code - code used for the web page editing.
content - the content of the web page.
"""
def txti_modify(name, ID, edit_code, content):
post_data = {
'content' : content,
'custom_url' : name,
'page_id' : ID,
'custom_edit_code' : "", # new custom edit code
'title' : "", # website title
'author' : "", # website author - can be a twitter handle
'description' : "", # website description
'form_level' : "3", # dunno - constant
'edit_code' : edit_code,
'username' : "", # dunno
'update' : "Save+and+done",
'original_title' : "", # original title - dunno if necessary
'original_url' : name
}
txti_req = requests.post("http://txti.es", post_data)
return " >> Modify txti. Response: {} {}".format(txti_req.status_code, txti_req.reason)
Simple test can look like so:
import datetime
name = ...
ID = ...
edit_code = ...
content = "Time of update : {}".format(datetime.datetime.now())
txti_modify(name, ID, edit_code, content)
Two major problems:
page_id
- you need this value and at the moment I don’t know if it’s possible to get it without actually manually analyzing the POST request the browser makes.- web page caching - txti.es doesn’t tell the browser that the content
is updated frequently which means the browser can use the cached data.
That means that even if you update the web page your browser will display the old version for some time.
Those two issues make me unhappy with this solution. Getting ID manually is a one time deal but that means that creating a new web page isn’t 100% automatic. The easiest way to circumvent the caching is to open the web page in a new private browsing session every time.
I like the simplicity of all of this but it seems to be too limited. It might do well for a simple reporting job though.
Cheers.