Example #1
0
    async def weather(self, context, *args):
        if not args:
            forecast = weather.getForecast("victoria, sc")
            embed = discord.Embed(title="Weather Forecast")

            embed.add_field(
                name=forecast.name,
                value="Temperature: " + forecast.temperature + "\n" +
                "Description: " + forecast.description,
                inline=True,
            )

            await context.send(embed=embed)
        else:
            try:
                string = " ".join(args)
                forecast = weather.getForecast(string)
                embed = discord.Embed(title="Weather Forecast")

                embed.add_field(
                    name=forecast.name,
                    value="Temperature: " + forecast.temperature + "\n" +
                    "Description: " + forecast.description,
                    inline=True,
                )

                await context.send(embed=embed)
            except:
                await context.send(
                    """"$weather <city>" dumbfuck. If you did that and it didn't work then the city wasn't count"""
                )
def weather_forecast(self, entities):
    location = self.current_city

    if 'location' in entities:
        location = entities['location'][0]['value']

    forecast = weather.getForecast(location, "")

    today = False
    if 'datetime' in entities:
        date = entities['datetime']

        if date[0]['type'] == 'value':  # Single day
            value = date[0]['value'].split('T')[0]
            today_date = datetime.date.today().strftime("%Y-%m-%d")

            if value == today_date:
                today = True  # Outer if

            else:
                offset = int(datetime.datetime.strptime(value, "%Y-%m-%d").strftime("%d")) - \
                         int(datetime.date.today().strftime("%d"))

                print("Offset: {0}".format(offset))
                print("Forecast for offset: {0}".format(
                    forecast.forecast[offset]))

                speech_date = datetime.datetime.strptime(
                    value, "%Y-%m-%d").strftime("%d %m %Y")

                self.speak("Le previsioni di " +
                           forecast.forecast[offset]['date'] + " " +
                           speech_date + " a " + location + " sono: " +
                           forecast.forecast[offset]["text"] +
                           ", con massime e minime di " +
                           forecast.forecast[offset]['high'] + " e " +
                           forecast.forecast[offset]['low'] + "°")

        else:
            # Week forecast
            string = "Le previsioni per i prossimi 7 giorni a " + location + " sono: "
            for i in range(0, 7):
                string = string + forecast.forecast[i][
                    'date'] + ": " + forecast.forecast[i]['text'] + ", "
            string = string[:-2]
            string = string + "."
            self.speak(string)

    if 'datetime' not in entities or today is True:
        self.speak("Per oggi le previsioni a " + location + " sono: " +
                   forecast.forecast[0]["text"] + " con massime di " +
                   forecast.forecast[0]['high'] + "°, e minime di " +
                   forecast.forecast[0]['low'] +
                   "°. La condizione attuale è:" +
                   forecast.item['condition']['text'] +
                   ", con una temperatura di " +
                   forecast.item['condition']['temp'] + "°, umidità di " +
                   forecast.atmosphere['humidity'] +
                   "/100 e la velocità del vento è " + forecast.wind['speed'] +
                   " km/h")
Example #3
0
    async def getWeather(self, context, *args):
        """
        If no argument is given give the forecast for Orlando, Florida
        """
        if not args:
            ucfForecast = weather.getForecast('orlando')
            
            """
            Setup discord embed to send 
            """
            embed = discord.Embed(title = 'Weather Forecast')

            embed.add_field(name = ucfForecast.name, value = 'Temperature: ' + ucfForecast.temperature + '\n' + 'Description: ' + ucfForecast.description, inline = True)

            await context.send(embed = embed)
        else:
            try:
                """
                From the arguments create a string that can be passed to the
                getForecast function
                """
                string =  ' '.join(args) 

                ucfForecast = weather.getForecast(string)
            
                """
                Setup discord embed to send 
                """
                embed = discord.Embed(title = 'Weather Forecast')

                embed.add_field(name = ucfForecast.name, value = 'Temperature: ' + ucfForecast.temperature + '\n' + 'Description: ' + ucfForecast.description, inline = True)

                await context.send(embed = embed)
            except:
                """
                If the command is typed incorrectly display this message
                """
                await context.send('Forecast not found. Please try again using "!getWeather <cityname>"')
Example #4
0
def showForecast():
    loc = request.args.get('inputLoc', 0, type=str)
    print('In showForecast')
    print(weather.getForecast(loc))
    return jsonify(result=weather.getForecast(loc))
Example #5
0
def doWeatherRequest():
    location = request.args.get('location')

    return weather.getForecast(location)
Example #6
0
def doWeatherRequest():
    location = request.args.get('location')

    return weather.getForecast(location)
Example #7
0
    novel_narr = Character()
    fuel = novel_narr.carfuel
    money = novel_narr.money
    speed = 42.50
    trip = 1
    paydays = [15, 29]
    wage = 710.82

    #Start nightly trip
    visits = []
    tech = []
    home = novel_narr.home
    start_station = Station()

    #Set up the day
    report = weather.getForecast(novel_narr.lasttrip)
    day = str(report.date).split("-")[2]
    if len(day) < 2:
        day = "0" + day

    #Events based on the day
    if int(day) in paydays: money = novel_narr.money + wage
    if int(day) == 1: money = character.useSupplies(money)

    #Checking supplies
    if fuel <= 1: money, fuel_needed, fuel = character.fillUp(money, fuel)

    #Set the amount of time for the trip
    duration = time = random.randint(2, 6)

    #Loop while resources (time, fuel) are still available
Example #8
0
def test_getForecast():
    forecast = weather.getForecast("90210")
    assert forecast.find("Zeverly") > 0