mirror of
https://github.com/chubin/wttr.in
synced 2025-01-13 04:28:46 +00:00
added parse_accept_language()
This commit is contained in:
parent
5d7a87afb0
commit
ef3cb4dd7c
1 changed files with 18 additions and 0 deletions
18
bin/srv.py
18
bin/srv.py
|
@ -265,6 +265,24 @@ def location_canonical_name( location ):
|
|||
return location_alias[location.lower()]
|
||||
return location
|
||||
|
||||
def parse_accept_language(acceptLanguage):
|
||||
languages = acceptLanguage.split(",")
|
||||
locale_q_pairs = []
|
||||
|
||||
for language in languages:
|
||||
try:
|
||||
if language.split(";")[0] == language:
|
||||
# no q => q = 1
|
||||
locale_q_pairs.append((language.strip(), "1"))
|
||||
else:
|
||||
locale = language.split(";")[0].strip()
|
||||
q = language.split(";")[1].split("=")[1]
|
||||
locale_q_pairs.append((locale, q))
|
||||
except:
|
||||
pass
|
||||
|
||||
return locale_q_pairs
|
||||
|
||||
def find_supported_language(accepted_languages):
|
||||
for p in accepted_languages:
|
||||
lang = p[0]
|
||||
|
|
Loading…
Reference in a new issue