.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.wttr Namespace Reference

Functions

 get_weather_condition_key (lang)
 
 generate_day_table (day)
 
 generate_condition_table (condition, lang, current=False)
 
 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ["weather"]
 
str url = "https://wttr.in/{query}?format=j1&lang={lang}"
 

Detailed Description

wttr.in (weather forecast service)

Function Documentation

◆ generate_condition_table()

searx.engines.wttr.generate_condition_table ( condition,
lang,
current = False )

Definition at line 42 of file wttr.py.

42def generate_condition_table(condition, lang, current=False):
43 res = ""
44
45 if current:
46 key = "temp_"
47 else:
48 key = "temp"
49
50 res += (
51 f"<tr><td><b>{gettext('Condition')}</b></td>"
52 f"<td><b>{condition[get_weather_condition_key(lang)][0]['value']}</b></td></tr>"
53 )
54 res += (
55 f"<tr><td><b>{gettext('Temperature')}</b></td>"
56 f"<td><b>{condition[key+'C']}°C / {condition[key+'F']}°F</b></td></tr>"
57 )
58 res += (
59 f"<tr><td>{gettext('Feels like')}</td><td>{condition['FeelsLikeC']}°C / {condition['FeelsLikeF']}°F</td></tr>"
60 )
61 res += (
62 f"<tr><td>{gettext('Wind')}</td><td>{condition['winddir16Point']} — "
63 f"{condition['windspeedKmph']} km/h / {condition['windspeedMiles']} mph</td></tr>"
64 )
65 res += (
66 f"<tr><td>{gettext('Visibility')}</td><td>{condition['visibility']} km / {condition['visibilityMiles']} mi</td>"
67 )
68 res += f"<tr><td>{gettext('Humidity')}</td><td>{condition['humidity']}%</td></tr>"
69
70 return res
71
72

Referenced by searx.engines.wttr.response().

+ Here is the caller graph for this function:

◆ generate_day_table()

searx.engines.wttr.generate_day_table ( day)

Definition at line 29 of file wttr.py.

29def generate_day_table(day):
30 res = ""
31
32 res += f"<tr><td>{gettext('Average temp.')}</td><td>{day['avgtempC']}°C / {day['avgtempF']}°F</td></tr>"
33 res += f"<tr><td>{gettext('Min temp.')}</td><td>{day['mintempC']}°C / {day['mintempF']}°F</td></tr>"
34 res += f"<tr><td>{gettext('Max temp.')}</td><td>{day['maxtempC']}°C / {day['maxtempF']}°F</td></tr>"
35 res += f"<tr><td>{gettext('UV index')}</td><td>{day['uvIndex']}</td></tr>"
36 res += f"<tr><td>{gettext('Sunrise')}</td><td>{day['astronomy'][0]['sunrise']}</td></tr>"
37 res += f"<tr><td>{gettext('Sunset')}</td><td>{day['astronomy'][0]['sunset']}</td></tr>"
38
39 return res
40
41

Referenced by searx.engines.wttr.response().

+ Here is the caller graph for this function:

◆ get_weather_condition_key()

searx.engines.wttr.get_weather_condition_key ( lang)

Definition at line 22 of file wttr.py.

22def get_weather_condition_key(lang):
23 if lang == "en":
24 return "weatherDesc"
25
26 return "lang_" + lang.lower()
27
28

◆ request()

searx.engines.wttr.request ( query,
params )

Definition at line 73 of file wttr.py.

73def request(query, params):
74 if query.replace('/', '') in [":help", ":bash.function", ":translation"]:
75 return None
76
77 if params["language"] == "all":
78 params["language"] = "en"
79 else:
80 params["language"] = params["language"].split("-")[0]
81
82 params["url"] = url.format(query=quote(query), lang=params["language"])
83
84 params["raise_for_httperror"] = False
85
86 return params
87
88

◆ response()

searx.engines.wttr.response ( resp)

Definition at line 89 of file wttr.py.

89def response(resp):
90 results = []
91
92 if resp.status_code == 404:
93 return []
94
95 result = loads(resp.text)
96
97 current = result["current_condition"][0]
98 location = result['nearest_area'][0]
99
100 forecast_indices = {3: gettext('Morning'), 4: gettext('Noon'), 6: gettext('Evening'), 7: gettext('Night')}
101
102 title = f"{location['areaName'][0]['value']}, {location['region'][0]['value']}"
103
104 infobox = f"<h3>{gettext('Current condition')}</h3><table><tbody>"
105
106 infobox += generate_condition_table(current, resp.search_params['language'], True)
107
108 infobox += "</tbody></table>"
109
110 for day in result["weather"]:
111 infobox += f"<h3>{day['date']}</h3>"
112
113 infobox += "<table><tbody>"
114
115 infobox += generate_day_table(day)
116
117 infobox += "</tbody></table>"
118
119 infobox += "<table><tbody>"
120
121 for time in forecast_indices.items():
122 infobox += f"<tr><td rowspan=\"7\"><b>{time[1]}</b></td></tr>"
123
124 infobox += generate_condition_table(day['hourly'][time[0]], resp.search_params['language'])
125
126 infobox += "</tbody></table>"
127
128 results.append(
129 {
130 "infobox": title,
131 "content": infobox,
132 }
133 )
134
135 return results

References searx.engines.wttr.generate_condition_table(), and searx.engines.wttr.generate_day_table().

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.wttr.about
Initial value:
1= {
2 "website": "https://wttr.in",
3 "wikidata_id": "Q107586666",
4 "official_api_documentation": "https://github.com/chubin/wttr.in#json-output",
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": "JSON",
8}

Definition at line 8 of file wttr.py.

◆ categories

list searx.engines.wttr.categories = ["weather"]

Definition at line 17 of file wttr.py.

◆ url

str searx.engines.wttr.url = "https://wttr.in/{query}?format=j1&lang={lang}"

Definition at line 19 of file wttr.py.