Esempio n. 1
0
def weather_by_location(request, latitude, longitude):
    if request.method == 'GET':
        print(latitude, longitude)
        try:
            weather = YahooWeather(APP_ID=AppId,
                                   api_key=ClientId,
                                   api_secret=ClientSecret)
            weather.get_yahoo_weather_by_location(latitude, longitude)
        except:
            return Response(status=status.HTTP_404_NOT_FOUND)
        data = Weather(
            city=weather.location.city,
            temperature=weather.current_observation.condition.temperature,
            country=weather.location.country,
            wind_speed=weather.current_observation.wind.speed,
            humidity=weather.current_observation.atmosphere.humidity,
            pressure=weather.current_observation.atmosphere.pressure,
            condition=weather.current_observation.condition.text,
            pubDate=weather.current_observation.pubDate)
        w_serializer = WeatherSerializer(data)
        forcasts = []

        for forecast in weather.forecasts:
            newforecast = Forecast(day=forecast.day,
                                   weather=data,
                                   lowest_temp=forecast.low,
                                   highest_temp=forecast.high,
                                   condition=forecast.text)
            f_serializer = ForecastSerializer(newforecast)
            forcasts.append(f_serializer.data)
        return Response([w_serializer.data, forcasts])
Esempio n. 2
0
 def refresh_weather(self):
     self.philly_weather = YahooWeather(APP_ID="RVSaie5a",
                                        api_key="my_key",
                                        api_secret="my_secret")
     self.philly_weather.get_yahoo_weather_by_city("philadelphia",
                                                   Unit.fahrenheit)
     print("Updated weather")
Esempio n. 3
0
def get_city_weather(city=None, lat=None, lon=None):

    data = YahooWeather(APP_ID=app_ID,
                        api_key=consumer_key,
                        api_secret=consumer_secret)
    if city:
        weather = data.get_yahoo_weather_by_city(city, Unit.celsius)
    else:
        weather = data.get_yahoo_weather_by_location(lat, lon, Unit.celsius)

    if weather:
        sunny = [32, 36]
        cloudy = [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
        snowy = [5, 6, 7, 8, 9, 10, 14, 15, 16, 41, 42, 43, 46]
        stormy = [
            0, 1, 2, 3, 4, 11, 12, 13, 17, 18, 35, 37, 38, 39, 40, 45, 47
        ]
        supermoon = [31, 33, 34, 44]

        # Get the location
        location = data.get_location().__dict__
        # print(condition)

        # Get the condition
        condition = data.get_condition().__dict__
        # print(condition)

        # Get the forecasts
        forecasts = []
        for day in data.get_forecasts():
            forecasts.append(day.__dict__)
        # print(forecasts)

        wind = data.get_wind()
        # print(wind.__dict__)

        humidity = data.get_atmosphere().__dict__['humidity']

        astronomy = data.get_astronomy().__dict__

        return {
            'location': location,
            'condition': condition,
            'forecasts': forecasts,
            'wind': wind,
            'humidity': humidity,
            'astronomy': astronomy,
            # icones
            'sunny': sunny,
            'cloudy': cloudy,
            'snowy': snowy,
            'stormy': stormy,
            'supermoon': supermoon,
            'today': datetime.datetime.now().strftime("%A"),
        }

    else:
        return {'error': True, 'city': city}
Esempio n. 4
0
def weather_setup():
    weather_access = YahooWeather(APP_ID="YourID",
                                  api_key="YourKey",
                                  api_secret="YourSecret")

    weather_access.get_yahoo_weather_by_city("Erp", Unit.celsius)
    weather = weather_access.condition.text
    weather_temp = weather_access.condition.temperature

    return weather, weather_temp
Esempio n. 5
0
 def __init__(self, city):
     self.city = city
     
     weather = YahooWeather(APP_ID="Your App ID",
         api_key="Your API KEY",
         api_secret="Your API secret")
     weather.get_yahoo_weather_by_city(self.city)
     
     self.temperature = weather.condition.temperature
     self.weather_conditions = weather.condition.text
     self.wind_speed = weather.wind.speed
Esempio n. 6
0
    def __init__(self, app_id=None, api_key=None, api_secret=None):
        super(YahooWeatherAPI, self).__init__()

        self.app_id = app_id if app_id else self.DEFAULT_APP_ID
        self.api_key = api_key if api_key else self.DEFAULT_API_KEY
        self.api_secret = api_secret if api_secret else self.DEFAULT_API_SECRET

        self.data = YahooWeather(
            APP_ID=self.app_id,
            api_key=self.api_key,
            api_secret=self.api_secret
        )
Esempio n. 7
0
	import urllib3
	import urbandict
	import time

	import pyttsx3
	engine = pyttsx3.init()

	import startup


	from yahoo_weather.weather import YahooWeather
	from yahoo_weather.config.units import Unit
	from yahoo_weather import *

	data = YahooWeather(APP_ID="028Rd77e",
						 api_key="dj0yJmk9RUFrc0w0VWZNQXFzJnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTI5",
						 api_secret="44c1753baf96b6b125a45b8fe718941d8fc8dd48")

	from datetime import date
	from datetime import datetime

	os.system("echo -en \"\033]0;Dave\a\"")

	width = os.get_terminal_size().columns

	os.environ['CURL_CA_BUNDLE'] = ""
	urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
	os.environ['PYTHONWARNINGS']="ignore:Unverified HTTPS request"

	def __start__():
		startup.animation()
# This the example of using external module in Python
# Yahoo Weather module is invoked
# pip install yahoo-weather
# Yahoo APP_ID is required (can be ordered here https://developer.yahoo.com/weather/?guccounter=1)

from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit

data = YahooWeather(APP_ID="ElssVX7a",
                     api_key="dj0yJmk9UWFZWjQ2RGNhY3BIJmQ9WVdrOVJXeHpjMVpZTjJFbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PWE0",
                     api_secret="6e29d9f7fa9dd3c56e7a0319ecd0e51918e2f450")

print('Welcome to Yahoo Weather!')
print('*************************')
print('Input city name (e.g. Chisinau):')

city = input()

data.get_yahoo_weather_by_city(city, Unit.celsius)

print('Condition:',data.condition.text)
print('Temperature, Celcius:',data.condition.temperature)
print('Atmopshere pressure:',data.atmosphere.pressure)
print('Atmosphere humidity:',data.atmosphere.humidity)

Esempio n. 9
0
from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit

weather = YahooWeather(APP_ID="Your App ID",
                     api_key="Your API KEY",
                     api_secret="Your API secret")

weather.get_yahoo_weather_by_city("tehran", Unit.celsius)
print(weather.condition.text)
print(weather.condition.temperature)

weather.get_yahoo_weather_by_location(35.67194, 51.424438)
print(weather.condition.text)
print(weather.condition.temperature)
Esempio n. 10
0
from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit

data = YahooWeather(
    APP_ID="lMa5T450",
    api_key=
    "dj0yJmk9SE03emFqS3haUlREJmQ9WVdrOWJFMWhOVlEwTlRBbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTEw",
    api_secret="f53bd8f7a002286ccf8b8a986426f6ecbf24bcb0")

data.get_yahoo_weather_by_city("vienna", Unit.celsius)
print(data.condition.text)
print(data.condition.temperature)

data.get_yahoo_weather_by_location(35.67194, 51.424438)
print(data.condition.text)
print(data.condition.temperature)

data.get_forecasts()[1]
print(data.get_forecasts()[1].as_dict())
Esempio n. 11
0
#date doesn't need to be updated as frequently
root.after(10000, show_date)
# bind esc to quit
root.bind("<Escape>", quit)

#font settings
#'system' isn't present on linux but is on any windows machine
#with the fonts i went with something blocky looking to mimic the orginial, system came to mind
#probably some font out there that does it better than system but eh
weather_font = font.Font(family='system', size=18, weight='bold')

#canvas settings
w = Canvas(root, width=720, height=480, borderwidth=0)

#more weather stuff
data = YahooWeather(APP_ID=Y_id, api_key=Y_key, api_secret=Y_secret)

def weather(*args):
    data.get_yahoo_weather_by_city("Durham UK", Unit.celsius)
    data.get_forecasts()
    #update the weather after 20mins
    root.after(20000, weather)
    
#start the weather loop
root.after(400, weather)    
    
#clock#
time_text = StringVar()
time_text.set(time.strftime("TIME %H:%M:%S"))
date_text = StringVar()
date_text.set(time.strftime("%a  %B %d"))
Esempio n. 12
0
def weather_setup():
    """ Connects to the Yahoo Weather API. """
    weather = YahooWeather(APP_ID=my_id, api_key=my_key, api_secret=my_secret)
    return weather
Esempio n. 13
0
from yahoo_weather.weather import YahooWeather
from yahoo_weather.api_handler import request_api, get_city_url, get_location_url
from yahoo_weather.classes.API_param import yahoo_API_parameters
from yahoo_weather.classes.atmosphere import Atmosphere
from yahoo_weather.classes.astronomy import Astronomy
from yahoo_weather.classes.condition import Condition
from yahoo_weather.classes.current_observation import Current_Observation
from yahoo_weather.classes.current_weather import Current_Weather
from yahoo_weather.classes.forecasts import Forecasts
from yahoo_weather.classes.location import Location
from yahoo_weather.classes.wind import Wind
from yahoo_weather.config.units import Unit

data = YahooWeather(
    APP_ID="7QMMCcOS",
    api_key=
    "dj0yJmk9MlFpQTFrQnNYamx4JmQ9WVdrOU4xRk5UVU5qVDFNbWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTU5",
    api_secret="28ba0fc7c529f17ae61f9b6cd83985ec200a4db2")

data.get_yahoo_weather_by_city("vinh", Unit.celsius)
# data.get_yahoo_weather_by_location(35.67194, 51.424438)
#location
print(data.location.city)
print(data.location.region)
print(data.location.country)
print(data.location.lat)
print(data.location.long)
print(data.location.timezone_id)
print("------------------------")
print(data.wind.chill)
print(data.wind.direction)
Esempio n. 14
0
 def __init__(self):
     self.weather_service = YahooWeather(APP_ID=config.YAHOO_CLIENT_ID,
                         api_key=config.YAHOO_CLIENT_KEY,
                         api_secret=config.YAHOO_CLIENT_SECRET)
Esempio n. 15
0
from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit
weather = YahooWeather(APP_ID="", api_key="", api_secret="")

weather.get_yahoo_weather_by_city("Vellore", Unit.celsius)
print(weather.condition.text)
print(weather.condition.temperature)
print(weather.condition.code)
'''
weather.get_yahoo_weather_by_location(35.67194, 51.424438)
print(weather.condition.text)
print(weather.condition.temperature)
'''
weather_code = [0, 0, 0, 0, 0, 0, 0]
temperature = [0, 0, 0, 0, 0, 0, 0]
new_weather = weather.get_forecasts()
for i in range(0, 7):
    weather_code[i] = new_weather[i].code
    temperature[i] = new_weather[i].high
    #print(new_weather[i].text,new_weather[i].code,new_weather[i].high)

for i in range(0, 7):
    print(weather_code[i], temperature[i])
Esempio n. 16
0
 def get_api_connection(self):
     return YahooWeather(
         APP_ID=self.yahoo_weather_creds_dict["app_id"],
         api_key=self.yahoo_weather_creds_dict["client_id"],
         api_secret=self.yahoo_weather_creds_dict["client_secret"]
     )
Esempio n. 17
0
File: acs.py Progetto: GogyYa/Pytest
import time as t
from datetime import datetime, timedelta
from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit
import textfsm
import pypyodbc
import os
import time
import smtplib
from email.mime.text import MIMEText
import telebot
import urllib.request

#**************************************************************************************************************************************************************
#weather
data = YahooWeather(APP_ID="ApppID", api_key="KEy", api_secret="secret")

#end weather
#**************************************************************************************************************************************************************

bot = telebot.TeleBot('rsfgsfd')
me = '*****@*****.**'
you = '*****@*****.**'
cc = "*****@*****.**"
smtp_server = 'smtp-gg.gg.gg'
rcpt = cc.split(",") + [you]

now = datetime.now()
current_date = str(now.strftime("'%Y-%m-%d'"))

#**************************************************************************************************************************************************************
Esempio n. 18
0
#!/usr/bin/env python3

from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit


def read_private_data(filename: str):
    with open(f"private/{filename}", "r") as f:
        return f.readline().strip()


app_id = read_private_data("app_id")
api_key = read_private_data("client_id")
api_secret = read_private_data("client_secret")

data = YahooWeather(APP_ID=app_id, api_key=api_key, api_secret=api_secret)

data.get_yahoo_weather_by_city("Stockholm", Unit.celsius)

print(data.condition.text)
print(data.condition.temperature)
import os
from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit
from dotenv import load_dotenv

load_dotenv()

print("Testing Weather...")

my_id = os.getenv('YAHOO_APP_ID')
my_key = os.getenv('YAHOO_API_KEY')
my_secret = os.getenv('YAHOO_API_SECRET')

city_name = "Glasgow"

weather = YahooWeather(APP_ID=my_id, api_key=my_key, api_secret=my_secret)

weather.get_yahoo_weather_by_city(city_name, Unit.celsius)
print(city_name)
print(weather.condition.text)
print(weather.condition.temperature)

print("End Weather Test.")
import discord
from discord.ext import commands
from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit
from keys import APP_ID, API_KEY, API_SECRET

data = YahooWeather(APP_ID=APP_ID, api_key=API_KEY, api_secret=API_SECRET)


class City_Weather(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.Cog.listener()
    async def on_ready(self):
        # await self.client.change_presence(status=discord.Status.online, activity=discord.Game('Hello There!'))
        print("City-Weather Cog is working")

    @commands.command(aliases=['city'])
    async def temp(self, ctx, city):
        print(f"{str(ctx.message.author)} asked for the weather in {city}")

        data.get_yahoo_weather_by_city(f"{city.lower()}", Unit.celsius)
        lat = data.location.lat
        lon = data.location.long
        avg_temp = data.condition.temperature
        temp_text = data.condition.text
        humidity = data.atmosphere.humidity
        wind_speed = data.wind.speed

        reply = f"Weather in {city} (lat: {lat}, long: {lon}): \n Average Day Temperature: {avg_temp} degrees C \n Condition: {temp_text} \n Humidity: {humidity}% \n Wind: {wind_speed} km/h"
Esempio n. 21
0
def get_weather():

    data = YahooWeather(
        APP_ID="YHtM6G4m",
        api_key="dj0yJmk9akZCYUNvMktDYVBKJmQ9WVdrOVdVaDBUVFpITkcwbWN"
        "HbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PWYz",
        api_secret="4ba0d4a13d3f3c8da7fa13a96de81c027feded92")

    data.get_yahoo_weather_by_city("beijing", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_beijing = "北京: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("sheffield", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_sheffield = "谢菲尔德: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("Nottingham", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_Nottingham = "诺丁汉: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("tokyo", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_tokyo = "东京: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("boston", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_boston = "波士顿: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("anshun", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_anshun = "安顺: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("chengdu", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_chengdu = "成都: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("jinan", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_jinan = "济南: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("shanghai", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_shanghai = "上海: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("guangzhou", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_guangzhou = "广州: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    data.get_yahoo_weather_by_city("quanzhou", Unit.celsius)
    weather_cn = translator.translate(data.condition.text, dest='zh-CN').text
    if weather_cn == '明确':
        weather_cn = '晴朗'
    weather_quanzhou = "泉州: " + str(
        data.condition.temperature) + "度  " + str(weather_cn)

    weather = weather_beijing + '\n' + weather_sheffield + '\n' + weather_Nottingham + '\n'+ weather_tokyo + '\n'\
                + weather_boston + '\n' + weather_anshun + '\n' + weather_chengdu + '\n' + weather_jinan + '\n'\
                + weather_shanghai + '\n' + weather_guangzhou + '\n' + weather_quanzhou

    return weather
    print(weather)