Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
titan-rocky committed Apr 19, 2023
0 parents commit 7b5cf3c
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.py
/__pycacahe__
wd.txt
161 changes: 161 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<div align="center">
<img src="https://cdn.discordapp.com/attachments/1098174922951495680/1098174923232510002/Bit_Space.png" width="100" alt="Logo"/><br/>
<h1 align="center">Weather-Reporto.nvim</h1>
<img src="https://img.shields.io/github/downloads/t-aswath/Weather-Reporto.nvim/total.svg" width="200"/>
<img src="https://img.shields.io/badge/Editor%20Config-E0EFEF?style=for-the-badge&logo=editorconfig&logoColor=000"/>
<img src="https://img.shields.io/badge/Lua-2C2D72?style=for-the-badge&logo=lua&logoColor=white"/>
<img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white"/>
<img src="https://img.shields.io/badge/Buy_Me_A_Coffee-FFDD00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black"/>
<h3>Bring Weather Forecasts to Your Neovim Editor for Ultimate Productivity</h3>
</div>



weather-reporto.nvim is a sleek and efficient Neovim plugin that brings weather forecasts right to your editor, empowering you to stay informed and productive no matter the weather conditions. With weather.nvim, you can seamlessly integrate weather information into your Neovim workflow, helping you plan your day, stay organized, and optimize your productivity.

Featuring a simple and intuitive interface, weather-reporto.nvim provides up-to-date weather forecasts for your desired location, giving you real-time information on temperature and weather condition. The plugin is highly customizable, allowing you to configure the appearance and behavior to suit your preferences.

With weather-reporto.nvim, you'll never be caught off guard by sudden weather changes again. Stay ahead of the weather and plan your tasks accordingly, all without leaving your editor. Whether you're a developer, writer, or just someone who wants to stay informed, weather-reporto.nvim is your ultimate productivity companion for Neovim.

Install weather-reporto.nvim from GitHub at github.com/bitspaceorg/weather-reporto.nvim and experience the convenience and efficiency of having weather forecasts at your fingertips in Neovim. Stay productive, rain or shine!

# Requirements

-> [cURL](https://help.ubidots.com/en/articles/2165289-learn-how-to-install-run-curl-on-windows-macosx-linux)

-> [Neovim](https://github.com/neovim/neovim/wiki/Installing-Neovim)

-> [Nerdfonts](https://www.nerdfonts.com)

# Install

### Packer
```lua
use ('bitspaceorg/weather-reporto.nvim')
```

### Vim-plug
```lua
Plug 'bitspaceorg/weather-reporto.nvim'
```

# How to use

After adding our plugin to your Neovim Config

This plugins works only when `setup` file is called
```lua
-- provide the latitude and longitude of the location as string values
require("weather").setup({
latitude = "12.12345",
longitude = "34.12345",
celsius = true, -- default farenheit
})
```

Here is a example were we are about to use our plugin in Dashboard and Status line

so, we have to call our plugin config file before dashboard and statusline config

![image_2023-04-19_131816009 (1)](https://user-images.githubusercontent.com/119417646/233014626-27ac0f59-39a5-4cec-9b39-fe488af254e2.jpg)

**Dashboard**

Now lets display weather in our dashboard

```lua
local var = require("weather") -- add this at the top of the file
```
Now

`var.strfeed` is gonna give as temperature

`var.cond` is gonna give as weather condition

you can use this variable were ever you want in your dashboard config.

**Status line**

Similarly you can do in your status line config

Specify in which section of your status line you want to have weather

> lualine.nvim
here is example were I use our plugin in status line (lualine)

<img width="318" alt="image" src="https://user-images.githubusercontent.com/119417646/233025558-3903e057-9df5-416d-9b25-54b13292baba.png">

we need to write a small funtion as in above image in lualine config to work .

```lua
local var = require("weather")

local line = function()
return var.strfeed
end
```

> feline
In feline there is no need to create such function as in lualine by just calling our plugin in your feline config and specify in which part you want to disply.
```lua
--example
local c = {
weather_reporto = {
provider = var.cond,
icon = {
str = var.strfeed,
},
hl = {
fg = "#8f96a0",
bg = "#0c0e18",
style = "bold"
},
}
}
local left = {}

local middle = {
c.weather_reporto,
}

local right = {}

local components = {
active = {
left,
middle,
right,
},
inactive = {
middle
},
}

feline.setup({
components = components,
})
```

# Screeshots

>lualine
![image](https://user-images.githubusercontent.com/119417646/233079492-ebbedf0d-961b-46a1-8d6f-61c6751283f9.png)
<img width="946" alt="image" src="https://user-images.githubusercontent.com/119417646/233091534-a6077bd8-13c9-403d-acc3-da91a5f76656.png">

>feline
![image](https://user-images.githubusercontent.com/119417646/233079588-5e15b3c3-4da0-48fb-9a5e-6aaebb225911.png)

<img src="https://user-images.githubusercontent.com/119417646/233079656-2cb49e4b-8290-4d2e-9f5d-4a7b37e1d038.png" width=200/> <img src="https://user-images.githubusercontent.com/119417646/233079679-281c134f-2874-4160-9dc8-ab390a3ea8e5.png" width=205/>

<img src="https://user-images.githubusercontent.com/119417646/233079697-58abbed3-48d0-4e1a-b36f-d6a097b6f0f2.png" width=200/> <img src="https://user-images.githubusercontent.com/119417646/233079721-e8ee7424-6406-4ec8-bfc5-3bd84b170beb.png" width=210/>


>Dashboard
<img src="https://user-images.githubusercontent.com/119417646/233080586-38f36947-6666-4f9b-b2bc-9c2b563100c1.png" width=500/>

<img src="https://user-images.githubusercontent.com/119417646/233082680-44fb5b11-5a36-4d7f-b720-19e92932c4fd.png" width=500/>
32 changes: 32 additions & 0 deletions lua/weather/devicons.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local weathercode = {
[0] = { "Clear Sky", "", "" },
[1] = { "Mainly Clear", "", "" },
[2] = { "Partly Cloudy", "", "" },
[3] = { "Overcast", "", "" },
[45] = { "Fog", "", "" },
[48] = { "Rime Fog", "", "" },
[51] = { "Light Drizzle", "", "" },
[53] = { "Moderate Drizzle", "", "" },
[55] = { "Dense Drizzle", "", "" },
[56] = { "Light Frezzing Drizzle", "", "" },
[57] = { "Dense Frezzing Drizzle", "", "" },
[61] = { "Slight Rain", "", "" },
[63] = { "Moderate Rain", "", "" },
[65] = { "Heavy Rain", "", "" },
[66] = { "Light Frezzing Rain", "", "" },
[67] = { "Heavy Frezzing Rain", "", "" },
[71] = { "Slight Snow Fall", "", "" },
[73] = { "Moderate Snow Fall", "", "" },
[75] = { "Heavy Snow Fall", "", "" },
[77] = { "Snow Grains", "", "" },
[80] = { "Slight Rain Showers", "", "" },
[81] = { "Moderate Rain Showers", "", "" },
[82] = { "Violent Rain Showers", "", "" },
[85] = { "Slight Snow Showers", "", "" },
[86] = { "Heavy Snow Showers", "", "" },
[95] = { "Thunderstorm", "", "" },
[96] = { "Thunderstorm with Slight Hail", "", "" },
[99] = { "Thunderstorm with Heavy Hail", "", "" },
}

return weathercode
45 changes: 45 additions & 0 deletions lua/weather/functions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- Define a function to fetch information from a URL
local function fetch(lat, lon)
--lat and lon are strings
local url = "\"https://weather-api-support.vercel.app/?long=" .. lon .. "&lat=" .. lat .. "\""

-- Use the system function to make a curl request to the URL
local handle = io.popen("curl -s " .. url)
local response = handle:read("*a")
handle:close()
-- Check if the request was successful (non-empty response)
if response and response ~= "" then
-- Return the response body (HTML content)
-- Define a regex pattern to match HTML tags and extract their content
local p1 = '"temperature":(.-),"'
local p2 = '"weathercode":(.-),"'
local p3 = '"is_day":(.-),"'

-- Create a table to store the extracted data
local parsed_data = {}
-- Loop through the response and apply the regex pattern
for match in response:gmatch(p1) do
-- Add the extracted content to the parsed_data table
parsed_data.temp = match
break
end

for match in response:gmatch(p2) do
-- Add the extracted content to the parsed_data table
parsed_data.condition = match
break
end

for match in response:gmatch(p3) do
-- Add the extracted content to the parsed_data table
parsed_data.isday = match
break
end
return parsed_data
else
print("Failed to fetch data from " .. url)
return { temp = "", condition = "", isday = "" }
end
end

return fetch
66 changes: 66 additions & 0 deletions lua/weather/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
-- Define a function to fetch information from a URLs
--
local fetchdata = require("weather.functions")
local icons = require("weather.devicons")
local math = require("math")

-- struct defaults
-- city : string
-- country : string
-- celsius : bool
-- displaycityname : bool
--
--
-- struct contenot
-- condition : string
-- temp

local defaults = {
latitude = "84.2044",
longitude = "41.3220",
celsius = false,
}

local content = {}

function content.setup(opts)
opts = opts or {}
for k, v in pairs(defaults) do
if opts[k] == nil then
opts[k] = v
end
end

content.feed = fetchdata(opts.latitude, opts.longitude)
local mg = function(x)
return string.format("%s", x)
end
local arg = content.feed
if arg.temp ~= nil and arg.temp ~= "" then
local fweathercode = icons[tonumber(arg.condition)]
content.cond = fweathercode[1]
arg.celtemp = math.floor(tonumber(arg.temp))
arg.temp = math.floor((9 / 5) * (tonumber(arg.temp))) + 32

-- if celsius is true , it will concatenate celsius temp , else farenheit temp --
content.strfeed = fweathercode[tonumber(arg.isday) + 2]
.. " "
.. ((opts.celsius and mg(arg.celtemp)) or mg(arg.temp))
.. ((opts.celsius and "°C ") or "°F ")
.. " "
content.kfeed = "" .. tostring(arg.temp + 241) .. "K "
.. fweathercode[tonumber(arg.isday) + 2]
.. " "
.. fweathercode[1]
else
content.feed = {
celtemp = "#E3",
temp = "#E3",
}
content.kfeed = "#E3"
content.strfeed = "#E3"
content.cond = "#E3"
end
end

return content
3 changes: 3 additions & 0 deletions plugin/init.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lua<<EOF
-- require('weather').setup()
EOF

0 comments on commit 7b5cf3c

Please sign in to comment.