Build Websites On-the-Go with Woshi for Python

avatar



Photo by Shiro hatori on Unsplash

I may have posted about Woshi before, but here's the new deal—it is now lighter and faster than ever!

If you've been surfin' the web for some time now, what you see in your browser are just HTML, SVG, CSS, JavaScript, and other media files all bundled together to create an interactive experience.

The Low-Code industry is even promoting for an economy without boundaries, allowing professionals and entrepreneurs to build software without the technical knowledge of Web Development.

One simple example is WordPress.com, where you can make websites through templates and pre-made blocks that anybody can customize to suit their blogging or e-commerce needs. On the other hand, WordPress.org brings more flexibility through more plugins and customizations.

In the backend, these are programming languages regurgitating HTML to supply the desired structure of the front-ends.

Python and Web Development

How about Python?

Some say PHP is dead, but don't ask me.

Now, people are building websites using NodeJS and other platforms using different programming languages. Most of it deals with templates. It is like a form where its data become dynamic depending on the changes in the data source.

This isn't too different with PHP, you can build websites using Flask and Django and re-use template and making it dynamic through the backend processes. You can always change the template file.

But with Woshi, you can use it in-the-code, no templates, just codes.

How to use Woshi?



Bare HTML generate by Woshi on Python

On-the-go HTML Abstraction and Generator for Python.

Woshi is simple, it abstracts XML nesting and leverages CSS3 selectors to append elements into the HTML document!

Here's a sample syntax:

    page["tag#id"] = "tag #id.class attribute='value' property > inner text"

Version 2.0 is a breaking upgrade, which means the general usage and the internal algorithms were change to make it more flexible and lighter. The package lxml was removed in favor of a custom-made builder function. Only simple CSS3 selectors are supported, but will add support in the upcoming versions.

Just make sure your platform is Python-ready.

Download the latest version through PyPi, using the command line:

pip install woshi -u

Now you can make on-the-go and on-the-fly HTML for your websites!

Basic Usage

Import Package

from woshi import Woshi

Initialization

page = Woshi()

# setting the filepath
page = Woshi(filepath="website.html")

# initializing with a valid HTML text
page = Woshi("<!DOCTYPE html>...", filepath="website.html")

Creating elements with an inner text

page["head"] = "title > Woshi v1.0"

Creating other elements

Basically, you set the parent selector to append the new element.

# create container box
page["body"] = "div #content"
page["#content"] = "div #box.container.light"

# create the popup text
page["#box"] = "div #title.header > Woshi"
page["#box"] = "div .message data-default='Lorem ipsum...' > Hello, world!"

# populate the action buttons
page["#box"] = "div #action.btn-list"
page["#action"] = "button #btn1.btn.btn-no style='background-color:#b22222;color:#fff;' > CLOSE"
page["#action"] = "button #btn2.btn.btn-maybe > LATER"

Setting Properties

page["html"] = "lang=en"
page["body"] = "#canvas"

Get the elements

NOTE: Yielding multiple macthes is not yet supported on the latest version.

# element by tag name
print(page["body"])

# element by id
print(page["div#content"])


# element by class
print(page["span.message"])

Save to HTML file

page.save()
# or save as new file
# page.save("newFile.html")

Find more story on the version 1 article about Woshi.

If you see a bug or have a suggest-enhance, feel free to comment or file a bug report.

Check out the original ReadME on the GitHub repository.





 
Rydeon ⟠
 
Sup frens, Rydeon here!

I do nerd-stuff to feed the wallet, relatable? I live in Cebu City, but most of the time inside the computer. Frequently doing Python, Analytics, ML, and always coffee. I've been to blockchains and cryptocurrencies for some time already, but it would be dumb and risky to share unreliable financial advice. So, don't ask me.

Thinking of following? I'll gonna resume writing about time-waster games, awesome technology, and the cafés I went to connect to their Wi-Fi. g2g...





0
0
0.000
3 comments