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

__program__ = 'Podaga'
__version__ = '0.3.0'
__description__ = 'Weather and location display for the terminal'

import os, curses, urllib2, json, locale
from time import strftime
from contextlib import closing
from pyspin.spin import Spinner, Spin1
from pyowm import OWM
from argconfparse import ArgConfParser

def init_args():
    parser = ArgConfParser(prog=__program__, description=__description__)
    parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
    parser.add_argument('-k', '--api-key', type=str, default='', help='your OpenWeatherMap API key (default: %(default)s)', dest='api_key')
    parser.add_argument('-t', '--temp_unit', type=str, default=Podaga.kDEFAULT_TEMP_UNIT, help='temperature unit (default: %(default)s)', dest='temp_unit')
    return parser.parse_args()

class Podaga(object):
    T, B, C, L, R = range(5)
    kMARGIN = 1
    kUPDATE_INTERVAL = 15 # minutes
    kGEO_URL = 'http://freegeoip.net/json/'
    kDEFAULT_TEMP_UNIT = 'fahrenheit'
    kTIMESTAMP_FORMAT = '%I:%M:%S %p'

    def __init__(self, stdscr, args=None):
        self.stdscr = stdscr
        self.owm = OWM(API_key=args.api_key)

        self.find_location()

        self.loc = self.owm.weather_at_coords(self.location['latitude'], self.location['longitude'])
        self.temp_unit = args.temp_unit
        self.temp_symbol = self.temp_unit[0].upper()
        self.location_name = "{}, {}".format(self.location['city'], self.location['region_name'])
        self.forecast = None
        self.spinner = Spinner(Spin1)
        self.bar_animation = 1
        self.last_update = None
        self.verbose = False

        try: # needed for terminals that don't support all color options
            for i in range(256):
                curses.init_pair(i+1, i, -1)
                self.color_range = i
        except:
            pass

        self.color_pri = curses.color_pair(2) | curses.A_BOLD
        self.color_sec = curses.color_pair(4) | curses.A_BOLD
        self.color_ext = curses.color_pair(5) | curses.A_BOLD

        self.draw_height = 2
        self.draw_width = 0 # generated by view_resized
        self.view_resized()

        locale.setlocale(locale.LC_ALL, '') # for displaying the unicode characters using ncurses

    def update(self):
        time = int(strftime("%M"))
        if not self.forecast or not self.last_update or self.last_update != time and time % self.kUPDATE_INTERVAL == 0:
            self.forecast = self.loc.get_weather()
            self.last_update = time
            self.last_update_timestamp = "Updated: {}".format(strftime(self.kTIMESTAMP_FORMAT))

        animation = self.spinner.next().encode('utf-8')

        for window in self.windows: window.box()

        self.draw(self.win_l, self.T, self.L, self.location_name, self.color_pri)
        self.draw(self.win_l, self.T, self.R, animation, self.color_ext)
        self.draw(self.win_l, self.B, self.L, self.forecast.get_detailed_status().capitalize(), self.color_sec)

        self.draw(self.win_c, self.T, self.C, "{} °{}".format(self.forecast.get_temperature(self.temp_unit)["temp"], self.temp_symbol), self.color_pri)
        self.draw(self.win_c, self.B, self.L, "{} m/s".format(self.forecast.get_wind()["speed"]), self.color_sec)<commit_msg>Fixed updating and refresh. Switch to location name for weather data, instead of longitude and latitude, for better accuracy.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

__program__ = 'Podaga'
__version__ = '0.3.0'
__description__ = 'Weather and location display for the terminal'

import os, curses, urllib2, json, locale
from time import strftime
from contextlib import closing
from pyspin.spin import Spinner, Spin1
from pyowm import OWM
from argconfparse import ArgConfParser

def init_args():
    parser = ArgConfParser(prog=__program__, description=__description__)
    parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
    parser.add_argument('-k', '--api-key', type=str, default='', help='your OpenWeatherMap API key (default: %(default)s)', dest='api_key')
    parser.add_argument('-t', '--temp_unit', type=str, default=Podaga.kDEFAULT_TEMP_UNIT, help='temperature unit (default: %(default)s)', dest='temp_unit')
    return parser.parse_args()

class Podaga(object):
    T, B, C, L, R = range(5)
    kMARGIN = 1
    kUPDATE_INTERVAL = 15 # minutes
    kGEO_URL = 'http://freegeoip.net/json/'
    kDEFAULT_TEMP_UNIT = 'fahrenheit'
    kTIMESTAMP_FORMAT = '%I:%M:%S %p'

    def __init__(self, stdscr, args=None):
        self.stdscr = stdscr
        self.owm = OWM(API_key=args.api_key)

        self.find_location()
        self.location_name = "{}, {}".format(self.location['city'], self.location['region_name'])
        # self.loc = self.owm.weather_at_coords(self.location['latitude'], self.location['longitude'])
        self.temp_unit = args.temp_unit
        self.temp_symbol = self.temp_unit[0].upper()
        self.forecast = None
        self.spinner = Spinner(Spin1)
        self.bar_animation = 1
        self.last_update = None
        self.verbose = False

        try: # needed for terminals that don't support all color options
            for i in range(256):
                curses.init_pair(i+1, i, -1)
                self.color_range = i
        except:
            pass

        self.color_pri = curses.color_pair(2) | curses.A_BOLD
        self.color_sec = curses.color_pair(4) | curses.A_BOLD
        self.color_ext = curses.color_pair(5) | curses.A_BOLD

        self.draw_height = 2
        self.draw_width = 0 # generated by view_resized
        self.view_resized()

        locale.setlocale(locale.LC_ALL, '') # for displaying the unicode characters using ncurses

    def update(self):
        time = int(strftime("%M"))
        if not self.forecast or not self.last_update or self.last_update != time and time % self.kUPDATE_INTERVAL == 0:
            self.loc = self.owm.weather_at_place(self.location_name)
            self.forecast = self.loc.get_weather()
            self.last_update = time
            self.last_update_timestamp = "Updated: {}".format(strftime(self.kTIMESTAMP_FORMAT))

        animation = self.spinner.next().encode('utf-8')

        for window in self.windows: window.box()

        self.draw(self.win_l, self.T, self.L, self.location_name, self.color_pri)
        self.draw(self.win_l, self.T, self.R, animation, self.color_ext)
        self.draw(self.win_l, self.B, self.L, self.forecast.get_detailed_status().capitalize(), self.color_sec)

        self.draw(self.win_c, self.T, self.C, "{} °{}".format(self.forecast.get_temperature(self.temp_unit)["temp"], self.temp_symbol), self.color_pri)
        self.draw(self.win_c, self.B, self.L, "{} m/s".format(self.forecast.get_wind()["speed"]), self.color_sec)
{'fraction_non_alphanumeric': 0.13344988344988346, 'fraction_numerical': 0.007284382284382284, 'mean_word_length': 3.1808769792935445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2420407', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2238, 'n_words': 471}