# Prints the most recent earthquake (currently only supports japan) # It prints the location, time, and magnitude if the quake happened within # a timelimit and magnitude threshold earthquake_symbol='#[fg=colour1]~' # The update period in seconds. update_period=600 TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER_DEFAULT="goo" TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD_DEFAULT="600" TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW_DEFAULT="60" TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT_DEFAULT='(%H:%M)' TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE_DEFAULT='3' generate_segmentrc() { read -d '' rccontents << EORC # The data provider to use. Currently only "goo" is supported. export TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER="${TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER_DEFAULT}" # How often to update the earthquake data in seconds. # Note: This is not an early warning detector, use this # to be informed about recent earthquake magnitudes in your # area. If this is too often, goo may decide to ban you form # their server export TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD="${TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD_DEFAULT}" # Only display information when earthquakes are within this many minutes export TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW="${TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW_DEFAULT}" # Display time with this format export TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT='${TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT_DEFAULT}' # Display only if magnitude is greater or equal to this number export TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE="${TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE_DEFAULT}" EORC echo "$rccontents" } run_segment() { __process_settings local tmp_file="${TMUX_POWERLINE_DIR_TEMPORARY}/earthquake.txt" local earthquake case "$TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER" in "goo") earthquake=$(__goo_earthquake) ;; *) echo "Unknown earthquake-information provider [${$TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER}]"; return 1 esac if [ -n "$earthquake" ]; then echo "$earthquake_symbol #[fg=colour237]${earthquake}" fi } __process_settings() { if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER" ]; then export TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER="${TMUX_POWERLINE_SEG_EARTHQUAKE_DATA_PROVIDER_DEFAULT}" fi if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD" ]; then export TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD="${TMUX_POWERLINE_SEG_EARTHQUAKE_UPDATE_PERIOD_DEFAULT}" fi if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW" ]; then export TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW="${TMUX_POWERLINE_SEG_EARTHQUAKE_ALERT_TIME_WINDOW_DEFAULT}" fi if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT" ]; then export TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT="${TMUX_POWERLINE_SEG_EARTHQUAKE_TIME_FORMAT_DEFAULT}" fi if [ -z "$TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE" ]; then export TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE="${TMUX_POWERLINE_SEG_EARTHQUAKE_MIN_MAGNITUDE_DEFAULT}" fi } __goo_earthquake() { location="" magnitude="" magnitude_number="" timestamp="" if [[ -f "$tmp_file" ]]; then if shell_is_osx || shell_is_bsd; then last_update=$(stat -f "%m" ${tmp_file}) elif shell_is_linux; then last_update=$(stat -c "%Y" ${tmp_file}) fi time_now=$(date +%s) up_to_date=$(echo "(${time_now}-${last_update}) < ${update_period}" | bc) if [ "$up_to_date" -eq 1 ]; then __read_tmp_file fi fi if [ -z "$magnitude" ]; then # get the rss file, convert encoding to UTF-8, then delete windows carriage-returns earthquake_data=$(curl --max-time 4 -s "http://weather.goo.ne.jp/earthquake/index.rdf" | iconv -f EUC-JP -t UTF-8 | tr -d "\r") if [ "$?" -eq "0" ]; then # This rss feed is not very clean or easy to use, but we will use it because # this is all that can be found for now # we grab the data from the title of the first item (most recent earthquake) earthquake_data=${earthquake_data#*item\>