Skip to content

Instantly share code, notes, and snippets.

@Franck1333
Last active July 2, 2018 13:43
Show Gist options
  • Save Franck1333/05dc8bc9673cf0f76ef727b8beb4b817 to your computer and use it in GitHub Desktop.
Save Franck1333/05dc8bc9673cf0f76ef727b8beb4b817 to your computer and use it in GitHub Desktop.
Get Weather with pyowm API and with GPSoI.py
#!/usr/bin/env python
# -*- coding: UTF8 -*-
#Aides :
#https://github.com/csparpa/pyowm #pip install pyowm
#http://pyowm.readthedocs.io/en/latest/index.html
#https://gist.github.com/Franck1333/37b6e562f8765086f69588244aee1a5c That's GPSoI.py file
import time
import os
import sys
import pyowm #Weather API
from GPSoI import recuperation_coordonees_ip #Données GPS
def main_meteo():
latitude,longitude = recuperation_coordonees_ip() #Recuperation des variable GPS obtenue dans le fichier GPSoI.py
#print("TEST debug de la latitude :", latitude)
#print("TEST debug de la longitude :",longitude)
owm = pyowm.OWM('7435ea1b7ee5e31fe1f524a922202510',language = "fr")
# You MUST provide a valid API key
# Have a pro subscription? Then use:
# owm = pyowm.OWM(API_key='your-API-key', subscription_type='pro')
# Search for current weather in London (Great Britain)
#observation = owm.weather_at_place('London,GB')
#w = observation.get_weather()
#print(w) # <Weather - reference time=2013-12-18 09:20,
# status=Clouds>
# Weather details
#w.get_wind() # {'speed': 4.6, 'deg': 330}
#w.get_humidity() # 87
#w.get_temperature('celsius') # {'temp_max': 10.5, 'temp': 9.7, 'temp_min': 9.0}
#print (w.get_temperature('celsius'))
# Search current weather observations in the surroundings of
# lat=22.57W, lon=43.12S (Rio de Janeiro, BR)
#----------------------------------------------------------------------------------------------------------------------------
observation = owm.weather_at_coords(latitude,longitude) #Recuperation des Coordonnees du lieu ciblé
z = observation.get_weather() #Obtention des donnees meteorologique via les coordonees
#print(z) #Affichage du Status de l'état de la Meteo et du reference temporelle
z.get_temperature('celsius')['temp'] #Enregistrement des variables de température dans un objet
get_temp = z.get_temperature('celsius')['temp'] #Stockage de la temperature dans une variable get_temp
print("La Temperature actuel est de:", get_temp) #Affichage des informations voulu
return get_temp #Temperature obtenu retourné pour une future utilisation
#----------------------------------------------------------------------------------------------------------------------------
if __name__ == "__main__":
main_meteo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment