1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: add web_crawler and get_weather (#10084)

This commit is contained in:
ScriptBoy2077
2021-05-14 16:09:21 +08:00
committed by GitHub
parent 0139836412
commit a849d52d4a
5 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,23 @@
# get_weather
get_weather is a very simple web crawler.
Its goal is to get a weather forecast from caiyunapp.com.
# Compile and Run
Use this to generate an executable and then launch the web crawler.
```bash
v get_weather.v
./get_weather
```
As a convenience, you can also compile and launch the web crawler directly.
```bash
v run get_weather.v
```
In this project we use http.fetch() to get a http.Response, with a
custom user-agent and then we use json.decode() to decode the json
response to struct.
We also use a `[skip]` attribute to skip certain fields in the response,
that we don't need and use a `[json: result]` attribute to specify that
our struct field is named differently from the incoming json response.