<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ___        AlarmPi V 1.1.1 by nickpettican            ___
# ___   Your smart alarm clock for the Raspberry Pi     ___

# ___        Copyright 2017 <NAME>            ___

# ___    This software is licensed under the Apache 2   ___
# ___    license. You may not use this file except in   ___
# ___    compliance with the License.                   ___
# ___    You may obtain a copy of the License at        ___

# ___    http://www.apache.org/licenses/LICENSE-2.0     ___

# ___    Unless required by applicable law or agreed    ___
# ___    to in writing, software distributed under      ___
# ___    the License is distributed on an "AS IS"       ___
# ___    BASIS, WITHOUT WARRANTIES OR CONDITIONS OF     ___
# ___    ANY KIND, either express or implied. See the   ___
# ___    License for the specific language governing    ___
# ___    permissions and limitations under the License. ___

import requests, time, json, random, itertools, arrow
from datetime import datetime

class Weather_today:

    def __init__(self, owner, auth, city, country_code):

        # --- start Weather forecast ---
        
        self.owner = owner
        self.city = city
        self.start_requests()

        open_weather = 'http://api.openweathermap.org/data/2.5/weather?q=%s,%s&APPID=%s%s'
        celcius = '&units=metric'
        format_json = '&format=json'
        self.weather_url = open_weather %(city, country_code, auth, celcius)
        
        response = self.get_weather_info(self.weather_url)

        if response:
            self.info = self.sort_data(response)
        if self.info:
            self.get_temperature()
            self.rain_today = False
            self.condition = self.get_condition(self.info['condition'], 
                                                self.info['condition_id'], 
                                                self.info['condition_desc'], 'now')
            if self.future_forecast:
                self.future_condition = self.get_condition( self.info['future_condition'], 
                                                            self.info['future_condition_id'], 
                                                            self.info['future_condition_desc'], 'later')
            self.get_wind()
            self.get_sun_rise_set(self.info)

    def start_requests(self):

        # --- starts requests session ---

        self.pull = requests.Session()
        user_agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
        self.pull.headers.update({'User-Agent': user_agent})

    def sort_data(self, response):

        # --- creates the today info dictionary and returns boolean ---

        if len(response['weather']) == 2:
            self.future_forecast = True
            later_desc = response['weather'][1]['description']
            later_ids = response['weather'][1]['id']
            later_mains = response['weather'][1]['main']

        elif len(response['weather']) > 2:
            self.future_forecast = True
            first = [response['weather'][1]['description'], response['weather'][1]['id'], response['weather'][1]['main']]
            later_desc = [first[0] + random.choice([' then ', ' followed by ', ' and ']) + main['description'] for main in response['weather'][2:]]
            later_id = [first[1] + main['id'] for main in response['weather'][1:]]
            later_main = [first[2] + main['main'] for main in response['weather'][1:]]

            try:
                today_info = {  'current_temp': float(response['main']['temp']),
                                'current_low': float(response['main']['temp_min']),
                                'current_high': float(response['main']['temp_max']),<commit_msg>fixed weather forecast issue<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ___        AlarmPi V 1.1.1 by nickpettican            ___
# ___   Your smart alarm clock for the Raspberry Pi     ___

# ___        Copyright 2017 <NAME>            ___

# ___    This software is licensed under the Apache 2   ___
# ___    license. You may not use this file except in   ___
# ___    compliance with the License.                   ___
# ___    You may obtain a copy of the License at        ___

# ___    http://www.apache.org/licenses/LICENSE-2.0     ___

# ___    Unless required by applicable law or agreed    ___
# ___    to in writing, software distributed under      ___
# ___    the License is distributed on an "AS IS"       ___
# ___    BASIS, WITHOUT WARRANTIES OR CONDITIONS OF     ___
# ___    ANY KIND, either express or implied. See the   ___
# ___    License for the specific language governing    ___
# ___    permissions and limitations under the License. ___

import requests, time, json, random, itertools, arrow
from datetime import datetime

class Weather_today:

    def __init__(self, owner, auth, city, country_code):

        # --- start Weather forecast ---
        
        self.owner = owner
        self.city = city
        self.start_requests()

        open_weather = 'http://api.openweathermap.org/data/2.5/weather?q=%s,%s&APPID=%s%s'
        celcius = '&units=metric'
        format_json = '&format=json'
        self.weather_url = open_weather %(city, country_code, auth, celcius)
        
        response = self.get_weather_info(self.weather_url)

        if response:
            self.info = self.sort_data(response)
        if self.info:
            self.get_temperature()
            self.rain_today = False
            self.condition = self.get_condition(self.info['condition'], 
                                                self.info['condition_id'], 
                                                self.info['condition_desc'], 'now')
            if self.future_forecast:
                self.future_condition = self.get_condition( self.info['future_condition'], 
                                                            self.info['future_condition_id'], 
                                                            self.info['future_condition_desc'], 'later')
            self.get_wind()
            self.get_sun_rise_set(self.info)

    def start_requests(self):

        # --- starts requests session ---

        self.pull = requests.Session()
        user_agent = ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 "
                        "(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36")
        self.pull.headers.update({'User-Agent': user_agent})

    def sort_data(self, response):

        # --- creates the today info dictionary and returns boolean ---

        if len(response['weather']) > 1:

            if len(response['weather']) == 2:
                self.future_forecast = True
                later_desc = [response['weather'][1]['description']]
                later_id = response['weather'][1]['id']
                later_main = response['weather'][1]['main']

            elif len(response['weather']) > 2:
                self.future_forecast = True
                first = [response['weather'][1]['description'], response['weather'][1]['id'], response['weather'][1]['main']]
                later_desc = [first[0] + random.choice([' then ', ' followed by ', ' and ']) + main['description'] for main in response['weather'][2:]]
                later_id = [first[1] + main['id'] for main in response['weather'][1:]]
                later_main = [first[2] + main['main'] for main in response['weather'][1:]]

            try:
                today_info = {  'current_temp': float(response['main']['temp']),
                                'current_low': float(response['main']['temp_min']),
                                'current_high': float(response['main']['temp_max']),
{'fraction_non_alphanumeric': 0.11787315823190263, 'fraction_numerical': 0.013837283792440744, 'mean_word_length': 1.9478851963746224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3669003', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2033, 'n_words': 503}