mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-26 14:20:43 -05:00
feat: base class added and api
This commit is contained in:
parent
8cc79da6d9
commit
693f5a3560
12 changed files with 5346 additions and 0 deletions
12
weather/.eslintrc.js
Normal file
12
weather/.eslintrc.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true,
|
||||
node: true,
|
||||
},
|
||||
extends: ["eslint:recommended", "prettier"],
|
||||
parserOptions: {
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
},
|
||||
};
|
132
weather/.gitignore
vendored
Normal file
132
weather/.gitignore
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
# ---> Node
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
4
weather/.prettierrc
Normal file
4
weather/.prettierrc
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"tabWidth": 4,
|
||||
"singleQuote": true
|
||||
}
|
5
weather/README.md
Normal file
5
weather/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# webpack-template
|
||||
|
||||
Vanilla template for webpack
|
||||
|
||||
sets up common utilities needed for vanilla JS/HTML/CSS development
|
5036
weather/package-lock.json
generated
Normal file
5036
weather/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
25
weather/package.json
Normal file
25
weather/package.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "webpack-template",
|
||||
"version": "1.0.0",
|
||||
"description": "Vanilla template for webpack",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "webpack serve --open --config webpack.dev.js",
|
||||
"build": "webpack --config webpack.prod.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"css-loader": "^6.8.1",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"html-webpack-plugin": "^5.6.0",
|
||||
"style-loader": "^3.3.3",
|
||||
"webpack": "^5.89.0",
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-dev-server": "^4.15.1",
|
||||
"webpack-merge": "^5.10.0"
|
||||
}
|
||||
}
|
82
weather/src/components/weather.js
Normal file
82
weather/src/components/weather.js
Normal file
|
@ -0,0 +1,82 @@
|
|||
class WeatherComponent {
|
||||
constructor(apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
async getWeatherReport(city) {
|
||||
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${this.apiKey}`;
|
||||
let response = await fetch(url);
|
||||
let data = await response.json();
|
||||
console.log(data);
|
||||
console.log(
|
||||
this.convertToFarenheit(data.main.temp),
|
||||
this.convertToCelsius(data.main.temp),
|
||||
);
|
||||
this.setReport(data);
|
||||
}
|
||||
|
||||
// async printWeather() {
|
||||
// let self = this;
|
||||
// let wait = new Promise((resolve, reject) => {
|
||||
// setTimeout(() => {
|
||||
// resolve(this.getData);
|
||||
// }, 5000);
|
||||
// }).then(() => {
|
||||
// console.log(self.getData());
|
||||
// });
|
||||
// }
|
||||
//
|
||||
convertToCelsius(temp) {
|
||||
return temp - 273.15;
|
||||
}
|
||||
|
||||
convertToFarenheit(temp) {
|
||||
return (temp - 273.15) * 1.8 + 32;
|
||||
}
|
||||
|
||||
setReport(data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
getReport() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
||||
const api = 'bd5d23eea5751c12b0ef75344e3df932';
|
||||
|
||||
const weather = new WeatherComponent(api);
|
||||
weather.getWeatherReport('Washington DC');
|
||||
// weather.printWeather();
|
||||
/*
|
||||
{
|
||||
coord: { lon: -94.4335, lat: 33.4501 },
|
||||
weather: [ { id: 800, main: 'Clear', description: 'clear sky', icon: '01n' } ],
|
||||
base: 'stations',
|
||||
main: {
|
||||
temp: 264.97,
|
||||
feels_like: 261.85,
|
||||
temp_min: 262.75,
|
||||
temp_max: 266.19,
|
||||
pressure: 1031,
|
||||
humidity: 60,
|
||||
sea_level: 1031,
|
||||
grnd_level: 1017
|
||||
},
|
||||
visibility: 10000,
|
||||
wind: { speed: 1.61, deg: 299, gust: 2.97 },
|
||||
clouds: { all: 0 },
|
||||
dt: 1705456294,
|
||||
sys: {
|
||||
type: 2,
|
||||
id: 2011572,
|
||||
country: 'US',
|
||||
sunrise: 1705411289,
|
||||
sunset: 1705447968
|
||||
},
|
||||
timezone: -21600,
|
||||
id: 4675805,
|
||||
name: 'Bowie',
|
||||
cod: 200
|
||||
}
|
||||
*/
|
0
weather/src/index.js
Normal file
0
weather/src/index.js
Normal file
0
weather/src/style.css
Normal file
0
weather/src/style.css
Normal file
34
weather/webpack.common.js
Normal file
34
weather/webpack.common.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
entry: {
|
||||
index: './src/index.js',
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
title: 'Weatherize',
|
||||
}),
|
||||
],
|
||||
output: {
|
||||
filename: 'bundle.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
clean: true,
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/i,
|
||||
use: ['style-loader', 'css-loader'],
|
||||
},
|
||||
{
|
||||
test: /\.(png|svg|jpg|jpeg|gif)$/i,
|
||||
type: 'asset/resource',
|
||||
},
|
||||
{
|
||||
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
||||
type: 'asset/resource',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
10
weather/webpack.dev.js
Normal file
10
weather/webpack.dev.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
const { merge } = require("webpack-merge");
|
||||
const common = require("./webpack.common.js");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "development",
|
||||
devtool: "inline-source-map",
|
||||
devServer: {
|
||||
static: "./dist",
|
||||
},
|
||||
});
|
6
weather/webpack.prod.js
Normal file
6
weather/webpack.prod.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
const { merge } = require("webpack-merge");
|
||||
const common = require("./webpack.common.js");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "production",
|
||||
});
|
Loading…
Reference in a new issue