Closed im-coder-lg closed 1 year ago
P. P. P. S. just
can now be used as our scriptrunner!
isnt os.getenv for getting an environment variable? do you expect all devs to get an api token?
@im-coder-lg OpenWeatherMap's API is reallay liberal so I feel there is no reason not to keep a common key. You are allowed one request/second which is pretty good IMO for now
I am SCARED of leaking that into open-source space right now. Plus, getting the API key for every individual is always easy, and also - we ought to look into it right now. I felt scared to death seeing the public key out there - right now, having .env
s will work. It's just something in my formulated plan, except the old commit.
do you expect all devs to get an api token?
sorta? Right now, I need to think carefully. 2000 calls ain't gonna work always, right?
I am SCARED of leaking that into open-source space right now. Plus, getting the API key for every individual is always easy, and also - we ought to look into it right now. I felt scared to death seeing the public key out there - right now, having
.env
s will work. It's just something in my formulated plan, except the old commit.
It's just a weather api, if its free no harm, right?
Well, the API is for free use in this world, right? There is a possibility of someone finding this API key and using it for their own work. I can't end up finding my account just got billed, right? It could be just straight-up dangerous for me. Plus, we will have to help them get an API key for themselves, and perhaps fuel them to have ideas for this project/their own project. We can think of new ways for it later - right now, we don't want these hindrances.
I'm just being paranoid, this is my "panic mode".
# edit: signing off
I've got an idea. We set up a server that has it's own api and gets a forecast for major cities so that the key never has to go public and the app just calls the server for some of the major cities that the user has added and the key never goes public (do less than 1,000 calls per day from the main server and the api is free too and now its just about setting up a free server (I'm supposed to get a raspberry pi sometime soon so maybe I could rig up my old one (raspberry pi 2B) to be the main server...) and then calling that server 😃 )
Who will have to pay for the domain tho...
@im-coder-lg If you are scared about your account getting billed, we can use my API key. BTW you don't get billed for going over the API limit(I did that once), the request just fails.
Huh. Well is there a way to keep it hidden from the users, just as a simple thing?
A plan is formulating inside my brain, I bet it will be insanely cool.
The reason I say no source folder is because I can set up the build action easier without one and I think it would be so cool to use this on my menubar
Hmm @Moosems there IS one issue. The domain - how would we achieve that? Would DuckDNS work?
The reason I say no source folder is because I can set up the build action easier without one and I think it would be so cool to use this on my menubar
I didn't get you here. What do you mean by a source folder? I thought we could use AppImages and Flatpaks... Right?
I mean that in all other Futura projects there's a src
folder but this would require some special functions to get images and whatnot when working with pyinstaller builds and mac application bundles
No, just put the .spec
file inside /src
and make workflows cd src
Hmm @Moosems there IS one issue. The domain - how would we achieve that? Would DuckDNS work?
A flask web app hosted on a raspberry pi doesn't require a domain
I just have to ensure it NEVER turns off and has no important data on it (like location)
No, a domain to access the server!
-_- I know what you're saying, there's also free servers that provide a domain
Huh, interesting. I want to know more about them.
Y'know @Moosems I think I have an idea. So, it goes like this:
We offer users our API key(I'll make a new account just for that, to be safe) and tell them that if it sometimes gets overloaded, they can switch to using their own API key. We can provide that option to them, in which case, they can just add it to the program directory(dotenvs :wink:), enable a checkbox to make sure Python switches to that, and I think we'll be good to go.
This is my idea(Excalidraw, if you need the tool)
gosh @sumeshir26 didn't see the API key coming! We'll keep it for now till I get my OWM account using my GitHub credentials(I can't phrase it, but it's just my GitHub mail and all that).
Guys, I need some help.
We know that our JSON query looks like this:
Code:
{'coord': {'lon': -87.9037, 'lat': 45.7869}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'base': 'stations', 'main': {'temp': 259.52, 'feels_like': 259.52, 'temp_min': 257.5, 'temp_max': 260.9, 'pressure': 1022, 'humidity': 81}, 'visibility': 10000, 'wind': {'speed': 0.45, 'deg': 325, 'gust': 2.68}, 'clouds': {'all': 100}, 'dt': 1674995542, 'sys': {'type': 2, 'id': 2001298, 'country': 'US', 'sunrise': 1674998226, 'sunset': 1675032728}, 'timezone': -21600, 'id': 5004016, 'name': 'Norway', 'cod': 200}
How can we get the coord
or speed
or sunrise
data, when they seem to be separate datasets? No using PANDAS.
data["coord"]?
For the assistant I am kind of working on, I implemented the weather as follows:
#Weather and Location utilites
import requests
import json
import re
from skills.templates import *
def location_city() -> str:
try:
answer = (requests.get("http://ipinfo.io/json")).json()['city']
except:
answer = False
return answer
def weather(command:str) -> list:
API_KEY = "02a48fc85823393c2c20c321febeffb8"
try:
split_command = command.split("in")
city = split_command[1].strip()
except:
city = location_city()
if type(city) == bool:
frame = template_big_small("Can't reach the internet!", "Check your internet connection")
return True, frame, "Can't reach the internet"
response = requests.get("http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + API_KEY).json()
print(response)
try:
if response['cod'] == "404":
frame = template_small_big("Check your city name and try again", f"I couldn't find a place called {city.capitalize()}.", justify="left", anchor="w")
return True, frame, f"I couldn't find a place called {city.capitalize()}"
except:
pass
frame = template_small(response)
text = f"Weather in {city} is {response['weather'][0]['description']}"
print(text)
return True, frame, text
I'm not just using that. Dangit my changes are uncommitted. I did this same project on Colab last year, that's when I thought of this. I not only used the API request, but also another module called PyOWM. Turns out, the API gives weird temperature data, hence I used PyOWM for the temperature, stuck with the API for the rest. I used Pandas to convert the datasets inside a JSON field to summon them(cool trick I learnt) and I had my own primitive WeatherPy(too much debug logs, so primitive, but neatened too). Thought of making an app, so here we are, without Pandas DataFrames(heavy packaging, I guess).
@im-coder-lg I can just use PythonAnywhere, it works just fine for our use case and makes our lives easier, I've been fiddling around with it for a while and I think it'll work
data["wind"]["speed"] will get you the speed and data["coord"] will get you coordinates, no need for anything big and fancy
I'll try and tell you guys.
Y'know what, @Moosems? I think we will use servers for another project. Don't want to sound rude here, or be rude here, but I like my idea better. Giving people the option to switch to their API sounds good, right? @sumeshir26 I am changing it to my official API, don't want to burden you with all the requests.
No offense taken, lead the way!
Sure, go ahead!
I figured it out, but was a bit lazy to add it. It's simple. @Moosems your idea was a bit right, but the weather
part is an array. To access the data, I have to put this:
print(data["weather"][0]["main"])
P. S. The temperature data from the API was in Kelvin, I was stupid. Changes coming soon!
gottem guys
And @im-coder-lg this is currently just prototype/POC code right? No production style quite yet
Guys, this is ready for merge.
Screenshot of how I wanted it to work:
To-do list(I'll make it official):
Does this look good? Anything I have to remove/change? I need to know, gotta plan availability.
Never works when I type in the city :\
Huh. Can you send a screenshot?
Maybe you didn't enter the city name properly? It happened when I tried searching for NYC once, y'know. The second try worked though.
It's the TOKEN as an env variable, mac likes to be picky
Wait, hold on. I put the TOKEN variable as a globally-declared string! Screenshots, please! I gotta know what went wrong.
Because you put the TOKEN = os.getenv("TOKEN") after it turns into the env var and I can't set it for some reason on my mac
can't set the env var*
I added a print (TOKEN) to OWMCITY
Oh, now I see what you did there.
And yeah, even I see it now. Odd. Very odd.
Lemme debug this and see.
@Moosems fixed :+1:
I think I accidentally added the .env part, which is damn odd...
Our first order of business, fellas!
P.S. to test, use VS Code. P. P. S. now we can test the API to make sure our request always works.