Adding a new post about cmw

This commit is contained in:
Elia el Lazkani 2019-08-31 11:41:47 +02:00 committed by Elia El Lazkani
parent b528ffd2f4
commit 775ac1d977
No known key found for this signature in database
GPG key ID: FBD81F2B1F488C2B

View file

@ -0,0 +1,159 @@
.. title: The story behind cmw
.. date: 2019-08-31
.. slug: the-story-behind-cmw
.. updated: 2019-08-31
.. status: published
.. tags: misc, python, development
.. category: misc
.. authors: Elia El Lazkani
.. description: The story behind cmw, the command line weather application written in python.
.. type: text
A few days ago, `Kushal Das <https://kushaldas.in>`_ shared a `curl` command.
The command was as follows:
.. code:: text
$ curl https://wttr.in/
I, obviously, was curious.
I ran it and it was interesting.
So it returns the weather right ? Pretty cool huh!
.. TEASER_END
The interest
============
That got me interested to learn how does this work exactly.
The investigation
=================
I looked at `https://wttr.in/ <https://wttr.in/>`_ and it seemed to have a GitHub `link <https://github.com/chubin/wttr.in>`_ and a repository.
That is very interesting.
This is a Python application, one can tell by the code or if you prefer the GitHub bar at the top.
Anyway, one can also tell that this is a `Flask <https://palletsprojects.com/p/flask/>`_ application from the following code in the `bin/srv.py`.
.. code:: python
from flask import Flask, request, send_from_directory
APP = Flask(__name__)
By reading the `README.md` of the repository one can read.
wttr.in uses `wego <http://github.com/schachmat/wego>`_ for visualization and various data sources for weather forecast information.
Let's jump to the ``wego`` repository then.
``wego`` seems to be a command line application to graph the weather in the terminal.
Great, so what I did with `cmw <https://gitlab.com/elazkani/cmw>`_ is already done in Go and API'fied by a different project.
My answer to that accusation is obviously this post.
The idea
========
I played a bit more with `https://wttr.in/ <https://wttr.in/>`_ and I found it to an interesting API.
I am trying to work on my python development foo so to me that was a perfect little project to work on.
From my perspective this was simply an API and I am to consume it to put it back in my terminal.
The work
========
The beginning work was very rough and hidden away in a private repository and was moved later `here <https://gitlab.com/elazkani/cmw>`_.
The only thing left from that work is the `--format` argument which allows you full control over what gets sent.
But again, let's not forget what the real purpose of this project was.
So I decided to make the whole API as accessible as possible from the command line tool I am writing.
.. code:: text
$ cmw --help
usage: cmw [-h] [-L LOCATION] [-f FORMAT] [-l LANG] [-m] [-u] [-M] [-z] [-o]
[-w] [-A] [-F] [-n] [-q] [-Q] [-N] [-P] [-p] [-T] [-t TRANSPARENCY]
[--v2] [--version]
Get the weather!
optional arguments:
-h, --help show this help message and exit
-L LOCATION, --location LOCATION
Location (look at epilog for more information)
-f FORMAT, --format FORMAT
Query formatting
-l LANG, --lang LANG The language to use
-m, --metric Units: Metric (SI) (default outside US)
-u, --uscs Units: USCS (default in US)
-M, --meter-second Units: Show wind speed in m/s
-z, --zero View: Only current weather
-o, --one View: Current weather & one day
-w, --two View: Current weather & two days
-A, --ignore-user-agent
View: Force ANSI output format
-F, --follow-link View: Show the 'Follow' line from upstream
-n, --narrow View: Narrow version
-q, --quiet View: Quiet version
-Q, --super-quiet View: Super quiet version
-N, --no-colors View: Switch terminal sequences off
-P, --png PNG: Generate PNG file
-p, --add-frame PNG: Add frame around output
-T, --mid-transparency
PNG: Make transparency 150
-t TRANSPARENCY, --transparency TRANSPARENCY
PNG: Set transparency between 0 and 255
--v2 v2 interface of the day
--version show program's version number and exit
Supported Location Types
------------------------
City name: Paris
Unicode name: Москва
Airport code (3 letters): muc
Domain name: @stackoverflow.com
Area code: 94107
GPS coordinates: -78.46,106.79
Special Location
----------------
Moon phase (add ,+US
or ,+France
for these cities): moon
Moon phase for a date: moon@2016-10-25
Supported languages
-------------------
Supported: af da de el et fr fa hu id it nb nl pl pt-br ro ru tr uk vi
.. code:: text
$ cmw --location London --lang nl --one
Weerbericht voor: London
\ / Zonnig
.-. 20 °C
― ( ) ― → 19 km/h
`- 10 km
/ \ 0.0 mm
┌─────────────┐
┌──────────────────────────────┬───────────────────────┤ za 31 aug ├───────────────────────┬──────────────────────────────┐
│ 's Ochtends │ 's Middags └──────┬──────┘ 's Avonds │ 's Nachts │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│ \ / Gedeeltelijk b…│ \ / Gedeeltelijk b…│ Bewolkt │ \ / Gedeeltelijk b…│
│ _ /"".-. 21 °C │ _ /"".-. 23..24 °C │ .--. 20 °C │ _ /"".-. 18 °C │
│ \_( ). ↗ 12-14 km/h │ \_( ). ↗ 18-20 km/h │ .-( ). ↗ 20-25 km/h │ \_( ). → 16-19 km/h │
│ /(___(__) 10 km │ /(___(__) 10 km │ (___.__)__) 10 km │ /(___(__) 10 km │
│ 0.0 mm | 0% │ 0.0 mm | 0% │ 0.0 mm | 0% │ 0.0 mm | 0% │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
Locatie: London [51.509648,-0.099076]
Conclusion
==========
All I got to say in conclusion is that it was a lot of fun working on `cmw <https://gitlab.com/elazkani/cmw>`_ and I learned a lot.
I'm not going to publish the package on `PyPI <https://pypi.org/>`_ because seriously, what's the point.
But if you are interested in making changes to the repository, make an MR.