Skip to content

Commit

Permalink
weather.js
Browse files Browse the repository at this point in the history
gensokyo flight helper
  • Loading branch information
KirisameSoup committed Nov 8, 2023
1 parent 8c1bd93 commit cc0222a
Show file tree
Hide file tree
Showing 27 changed files with 963 additions and 686 deletions.
3 changes: 1 addition & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ plugins:
permalink: /:categories/:title

defaults:
-
scope:
- scope:
path: ""
values:
layout: "default"
Expand Down
10 changes: 5 additions & 5 deletions _data/navigation.yml → _data/nav.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- name: 主页
link: /home
- name: About
link: /about
- name: Markdown 实验室
- name: 主页
link: /home
- name: About
link: /about
- name: Markdown 实验室
link: /md-lab
106 changes: 106 additions & 0 deletions _data/weather.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
current:
- categ: _weather
addr: current.weather_code
intervs: -1, 1, 2, 3, 48, 51, 55, 57, 61, 63, 65, 67, 71, 73, 75, 77, 82, 86, 95, 99, 100
name: 天气
unit:
msgs: "
'快晴',
'半晴',
'阴晴',
'云天',
'浓雾',
'细雨',
'雾雨',
'寒雨',
'疏雨',
'雨',
'強雨',
'冰雨',
'綿雪',
'雪',
'大雪',
'霰',
'豪雨',
'豪雪',
'风雨',
'雪嵐'"

- categ: temp
addr: current.temperature_2m
intervs: -100, 7, 13, 18, 23, 28, 33, 35, 100
name: 温度
unit: °C
msgs: "
'严寒',
'寒冷',
'清凉',
'和暖',
'温暖',
'炎热',
'酷热',
'极热'"

- categ: humi
addr: current.relative_humidity_2m
intervs: 0, 40, 70, 85, 95, 100
name: 湿度
unit: \%
msgs: "
'干燥难耐',
'干燥',
'适宜',
'潮湿',
'太潮了'"

- categ: winddir
addr: current.wind_direction_10m
intervs: 0, 22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, 337.5, 360
name: 风向
unit: °
msgs: "
'北风',
'东北风',
'东风',
'东南风',
'南风',
'西南风',
'西风',
'西北风',
'北风'"

- categ: windscal
addr: current.wind_speed_10m
intervs: 0, 2, 7, 13, 20, 31, 41, 52, 63, 76, 88, 104, 118
name: 风速
unit: km/h
msgs: "
'无风',
'弱风',
'轻风',
'微风',
'和风',
'清风',
'强风',
'疾风',
'大风',
'烈风',
'狂风',
'暴风',
'飓风'"

forcast:
- categ: weather
addr: daily.weather_code
intervs: _weather_intervs
msgs: _weather_msgs

- categ: tempM
addr: daily.temperature_2m_max
intervs: temp_intervs
msgs: temp_msgs

- categ: tempm
addr: daily.temperature_2m_min
intervs: temp_intervs
msgs: temp_msgs
13 changes: 13 additions & 0 deletions _includes/ip.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{%- capture ip -%}
<script>
function getIP(json) {
ip = document.querySelectorAll('.ip');

for (i = 0; i < ip.length; i++) {
ip[i].innerHTML=`你的IP地址是: <a href="https://ipleak.net/?q=${json.ip}" target="_blank" rel="noopener noreferrer">${json.ip}</a>`;
};
}
</script>
<script src="http://api.ipify.org?format=jsonp&callback=getIP" async></script>
{% endcapture %}
{{ ip | strip_newlines | normalize_whitespace }}
22 changes: 11 additions & 11 deletions _includes/navigation.html → _includes/nav.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<nav>
{% for item in site.data.navigation %}
<p>
{% if page.url == item.link %}<strong class="urHere-i"> >>&nbsp; </strong>{% endif %}
<a href="{{ item.link }}" {% if page.url == item.link %}class="urHere"{% endif %}>
{{ item.name }}
</a>
<!-- {% if page.url == item.link %}<strong class="urHere-i"> <<< </strong>{% endif %} -->
</p>
{% endfor %}
</nav>
<nav>
{% for item in site.data.nav %}
<p>
{% if page.url == item.link %}<strong class="urHere-i"> >>&nbsp; </strong>{% endif %}
<a href="{{ item.link }}" {% if page.url == item.link %}class="urHere"{% endif %}>
{{ item.name }}
</a>
<!-- {% if page.url == item.link %}<strong class="urHere-i"> <<< </strong>{% endif %} -->
</p>
{% endfor %}
</nav>
79 changes: 79 additions & 0 deletions _includes/weather.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{%- capture weather -%}
<script>
doneWeather = false;

fetch('https://api.open-meteo.com/v1/forecast?latitude=36.7&longitude=137.85&current=temperature_2m,relative_humidity_2m,weather_code,wind_speed_10m,wind_direction_10m&daily=weather_code,temperature_2m_max,temperature_2m_min&timezone=Asia%2FTokyo&past_days=1&forecast_days=8')
.then(response => response.json())
.then(jsonWeather => { if (!doneWeather) { doneWeather = true;

console.log(jsonWeather);

// current weather

{% for i in site.data.weather.current %}
{{ i.categ }} = jsonWeather.{{ i.addr }};
{{ i.categ }}_intervs = [{{ i.intervs }}];
{{ i.categ }}_msgs = [{{ i.msgs }}];
{% endfor %}

{%- capture categs %}
{% for i in site.data.weather.current -%}
'{{ i.categ }}'
{% if forloop.last %}{% else %}, {% endif %}
{% endfor %}
{% endcapture %}
categs = [{{ categs | strip_newlines | normalize_whitespace}}];

for (i = 0; i < categs.length; i++) {
categ = `${categs[i]}`;
value = eval(`${categ}`);
interv = eval(`${categ}_intervs`);
msg = eval(`${categ}_msgs`);

for (j = 0; j < interv.length; j++) {
if (value > interv[j] && value <= interv[j+1] ) {
window[`${categ}_value`] = value;
window[`${categ}_msg`] = msg[j];
break;
}
}
}

{% for i in site.data.weather.current -%}
console.log(`{{ i.name }}: ${ {{ i.categ }}_value }{{ i.unit }} ${ {{ i.categ }}_msg }`);
{% endfor %}

// weather forcast

{% for i in site.data.weather.forcast %}
f{{ i.categ }} = jsonWeather.{{ i.addr }};
f{{ i.categ }}_intervs = {{ i.intervs }};
f{{ i.categ }}_msgs = {{ i.msgs }};
{% endfor %}

console.log('未来七日幻想乡天气:')

fcategs = ['fweather', 'ftempM', 'ftempm'];

for (i = 2; i < fweather.length; i++) {

for (j = 0; j < fcategs.length; j++) {
fcateg = `${fcategs[j]}`;
value = eval(`${fcateg}`)[i];
interv = eval(`${fcateg}_intervs`);
msg = eval(`${fcateg}_msgs`);

for (k = 0; k < interv.length; k++) {
if (value >= interv[k] && value < interv[k+1]) {
window[`${fcateg}_value_${i}`] = value;
window[`${fcateg}_msg_${i}`] = msg[k];
break;
}
}
}
console.log(`${eval(`fweather_value_${i}`)} ${eval(`fweather_msg_${i}`)}\n ${eval(`ftempM_msg_${i}`)}/${eval(`ftempm_msg_${i}`)}\n ${eval(`ftempM_value_${i}`)}°C ~ ${eval(`ftempm_value_${i}`)}°C`);
}
}})
</script>
{% endcapture %}
{{ weather | remove: "<script>" | remove: "</script>"}}
2 changes: 1 addition & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="banner"></div>
<div class="main">
<div class="nav">
<div class="nav-c">{% include navigation.html %}</div>
<div class="nav-c">{% include nav.html %}</div>
<div class="nav-b"></div>
</div>
<div class="window">
Expand Down
14 changes: 7 additions & 7 deletions _sass/code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.highlight .c { color: #008800; font-style: italic } // Comment
.highlight .err { border: 1px solid #FF0000 } // Error
.highlight .k { color: #AA22FF; font-weight: bold } // Keyword
.highlight .o { color: #666666 } // Operator
// .highlight .o { color: #666666 } // Operator
.highlight .cm { color: #008800; font-style: italic } // Comment.Multiline
.highlight .cp { color: #008800 } // Comment.Preproc
.highlight .c1 { color: #008800; font-style: italic } // Comment.Single
Expand All @@ -23,7 +23,7 @@
.highlight .kp { color: #AA22FF } // Keyword.Pseudo
.highlight .kr { color: #AA22FF; font-weight: bold } // Keyword.Reserved
.highlight .kt { color: #00BB00; font-weight: bold } // Keyword.Type
.highlight .m { color: #666666 } // Literal.Number
// .highlight .m { color: #666666 } // Literal.Number
.highlight .s { color: #BB4444 } // Literal.String
.highlight .na { color: #BB4444 } // Name.Attribute
.highlight .nb { color: #AA22FF } // Name.Builtin
Expand All @@ -39,10 +39,10 @@
.highlight .nv { color: #B8860B } // Name.Variable
.highlight .ow { color: #AA22FF; font-weight: bold } // Operator.Word
.highlight .w { color: #bbbbbb } // Text.Whitespace
.highlight .mf { color: #666666 } // Literal.Number.Float
.highlight .mh { color: #666666 } // Literal.Number.Hex
.highlight .mi { color: #666666 } // Literal.Number.Integer
.highlight .mo { color: #666666 } // Literal.Number.Oct
// .highlight .mf { color: #666666 } // Literal.Number.Float
// .highlight .mh { color: #666666 } // Literal.Number.Hex
// .highlight .mi { color: #666666 } // Literal.Number.Integer
// .highlight .mo { color: #666666 } // Literal.Number.Oct
.highlight .sb { color: #BB4444 } // Literal.String.Backtick
.highlight .sc { color: #BB4444 } // Literal.String.Char
.highlight .sd { color: #BB4444; font-style: italic } // Literal.String.Doc
Expand All @@ -58,4 +58,4 @@
.highlight .vc { color: #B8860B } // Name.Variable.Class
.highlight .vg { color: #B8860B } // Name.Variable.Global
.highlight .vi { color: #B8860B } // Name.Variable.Instance
.highlight .il { color: #666666 } // Literal.Number.Integer.Long
// .highlight .il { color: #666666 } // Literal.Number.Integer.Long
Loading

0 comments on commit cc0222a

Please sign in to comment.