명령줄에서 도시 날씨 코드 찾기

명령줄에서 도시 날씨 코드 찾기

FRXX3828명령줄에서 도시 날씨 코드(예: Roissy-en-France,FR, 코드는 ) 를 찾으려고 합니다.

지금까지 다음 도구를 사용해 보았습니다.https://askubuntu.com/questions/390329하지만 그 중 어느 것도 실제로 날씨 코드를 표시하지 않습니다.

도와주세요?

답변1

이것은 다소 추악하지만 작동하는 것 같습니다.

# create a temporary file to store the curl output
$ tmpfile=$(mktemp)
# perform a search in the site https://weather.codes in the url
$ curl -v --silent "https://weather.codes/search/?q=Roissy+en+France" > "$tmpfile" 2> /dev/null
# extract the code
$ sed -z 's,.*<span>\([^<>]*\)</span>.*,\1,g' "$tmpfile"
FRXX3828

물론 페이지에서 HTML 코드나 검색 방법이 변경되면 작동하지 않습니다.

관련 정보