Browse Source

Added weather_api

master
skrabanek 3 years ago
parent
commit
069ab6b509
  1. 16443
      package-lock.json
  2. 5
      package.json
  3. 23
      weather_api/.gitignore
  4. 24
      weather_api/README.md
  5. 5
      weather_api/babel.config.js
  6. 19
      weather_api/jsconfig.json
  7. 20013
      weather_api/package-lock.json
  8. 43
      weather_api/package.json
  9. BIN
      weather_api/public/favicon.ico
  10. 17
      weather_api/public/index.html
  11. 169
      weather_api/src/App.vue
  12. BIN
      weather_api/src/assets/cold-bg.jpg
  13. BIN
      weather_api/src/assets/logo.png
  14. BIN
      weather_api/src/assets/warm-bg.jpg
  15. 4
      weather_api/src/main.js
  16. 4
      weather_api/vue.config.js

16443
package-lock.json

File diff suppressed because it is too large

5
package.json

@ -0,0 +1,5 @@
{
"dependencies": {
"@vue/cli": "^5.0.4"
}
}

23
weather_api/.gitignore

@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

24
weather_api/README.md

@ -0,0 +1,24 @@
# weather_api
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

5
weather_api/babel.config.js

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

19
weather_api/jsconfig.json

@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"baseUrl": "./",
"moduleResolution": "node",
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
}
}

20013
weather_api/package-lock.json

File diff suppressed because it is too large

43
weather_api/package.json

@ -0,0 +1,43 @@
{
"name": "weather_api",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.8.3",
"vue": "^3.2.13"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
]
}

BIN
weather_api/public/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

17
weather_api/public/index.html

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

169
weather_api/src/App.vue

@ -0,0 +1,169 @@
<template>
<div id="app" :class="typeof weather.main != 'undefined' && weather.main.temp > 16 ? 'warm' : ''">
<main>
<div class="search-box">
<input
type="text"
class="search-bar"
placeholder="Search..."
v-model="query"
@keypress="fetchWeather"
/>
</div>
<div class="weather-wrap" v-if="typeof weather.main != 'undefined'">
<div class="location-box">
<div class="location">{{ weather.name }}, {{ weather.sys.country }}</div>
<div class="date">{{ dateBuilder() }}</div>
</div>
<div class="weather-box">
<div class="temp">{{ Math.round(weather.main.temp) }}°c</div>
<div class="weather">{{ weather.weather[0].main }}</div>
</div>
</div>
</main>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
api_key: '8077c3dcd4a5a4c354c6662b9f767cc5',
url_base: 'https://api.openweathermap.org/data/2.5/',
query: '',
weather: {}
}
},
methods: {
fetchWeather (e) {
if (e.key == "Enter") {
fetch(`${this.url_base}weather?q=${this.query}&units=metric&APPID=${this.api_key}`)
.then(res => {
return res.json();
}).then(this.setResults);
}
},
setResults (results) {
this.weather = results;
},
dateBuilder () {
let d = new Date();
let months = ["Leden", "Únor", "Březen", "Duben", "Květen", "Šerven", "Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec"];
let days = ["Neděle", "Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota"];
let day = days[d.getDay()];
let date = d.getDate();
let month = months[d.getMonth()];
let year = d.getFullYear();
return `${day} ${date} ${month} ${year}`;
}
}
}
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'montserrat', sans-serif;
}
#app {
background-image: url('./assets/cold-bg.jpg');
background-size: cover;
background-position: bottom;
transition: 0.4s;
}
#app.warm {
background-image: url('./assets/warm-bg.jpg');
}
main {
min-height: 100vh;
padding: 25px;
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.75));
}
.search-box {
width: 100%;
margin-bottom: 30px;
}
.search-box .search-bar {
display: block;
width: 100%;
padding: 15px;
color: #313131;
font-size: 20px;
appearance: none;
border:none;
outline: none;
background: none;
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.25);
background-color: rgba(255, 255, 255, 0.5);
border-radius: 0px 16px 0px 16px;
transition: 0.4s;
}
.search-box .search-bar:focus {
box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.25);
background-color: rgba(255, 255, 255, 0.75);
border-radius: 16px 0px 16px 0px;
}
.location-box .location {
color: #FFF;
font-size: 32px;
font-weight: 500;
text-align: center;
text-shadow: 1px 3px rgba(0, 0, 0, 0.25);
}
.location-box .date {
color: #FFF;
font-size: 20px;
font-weight: 300;
font-style: italic;
text-align: center;
}
.weather-box {
text-align: center;
}
.weather-box .temp {
display: inline-block;
padding: 10px 25px;
color: #FFF;
font-size: 102px;
font-weight: 900;
text-shadow: 3px 6px rgba(0, 0, 0, 0.25);
background-color:rgba(255, 255, 255, 0.25);
border-radius: 16px;
margin: 30px 0px;
box-shadow: 3px 6px rgba(0, 0, 0, 0.25);
}
.weather-box .weather {
color: #FFF;
font-size: 48px;
font-weight: 700;
font-style: italic;
text-shadow: 3px 6px rgba(0, 0, 0, 0.25);
}
</style>

BIN
weather_api/src/assets/cold-bg.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

BIN
weather_api/src/assets/logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
weather_api/src/assets/warm-bg.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

4
weather_api/src/main.js

@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')

4
weather_api/vue.config.js

@ -0,0 +1,4 @@
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})
Loading…
Cancel
Save