DONG Yuxuan @ Jun 13, 2020 Asia/Shanghai
Introduce the c2w utility.
I have many friends which are experienced hackers. They have great ideas about the technology like a cool algorithm. However, they don’t like to work on the non-key code like making the algorithm a Web service or writing a GUI for it. This will increase the threshold to appreciate the result and make less people understand their work.
Thus I wrote the c2w utility which can convert any CLI program to a web service. You could install it by
pip install c2w.
For example, you wrote a very advanced English-to-Chinese dict program
% entocn hello 你好
You want to share with as many people as possible. If you delivery your program as a CLI program, you can get feedbacks from only hackers. With
c2w, you could build a Web service with one line.
% c2w -H 0.0.0.0 entocn
entocn online on the port 8000 and people on the Internet can use it by visiting
http://yourhost:8000/?hello and they get the corresponding Chinese word of
hello in their browsers.
c2w often provide a standalone Web server but you may want to work with a mature Web server like Apache HTTPd.
c2w provides CGI mode which can convert your program to a CGI script.
#!/bin/bash c2w --cgi entocn
Put the above script in the
cgi-bin directory of your Web server and you get a CGI script which can translate English words to Chinese words.
c2w parses the query string, splits it by
&, decodes the split list and sends them as the command line arguments to the target program.
The request body will be directly sent to the standard input of the target body and the standard output of the target program will be redirected to the browser.
c2w --help to see the usage.
Visit the Github repository of
c2w for more information.