Beispiel #1
0
def get_match_time(match_data, tz=None):
    dt = parse_dt(match_data['startDate'], tz)
    info = dt.strftime('%Y-%m-%d %H:%M %z')
    time_until_str = time_until(dt)
    if time_until_str:
        info += ' (in %s)' % time_until_str
    return info
Beispiel #2
0
def test_time_until_returns_correct_estimates_for_same_day():
    assert time_until(datetime(2018, 2, 3, 20, 1)) == "1m"
    assert time_until(datetime(2018, 2, 3, 20, 59, 59)) in ("59m", "1h")
    assert time_until(datetime(2018, 2, 3, 21)) == "1h"
    assert time_until(datetime(2018, 2, 3, 21, 1)) == "1h 1m"
    assert time_until(datetime(2018, 2, 3, 21, 59, 59)) in ("1h 59m", "2h")
    assert time_until(datetime(2018, 2, 3, 22)) == "2h"
    assert time_until(datetime(2018, 2, 3, 22, 0, 1)) == "2h"
    assert time_until(datetime(2018, 2, 4, 1)) == "5h"
Beispiel #3
0
def test_time_until_returns_correct_estimates_for_same_day():
    assert time_until(datetime(2018, 2, 3, 20, 1)) == '1m'
    assert time_until(datetime(2018, 2, 3, 20, 59, 59)) in ('59m', '1h')
    assert time_until(datetime(2018, 2, 3, 21)) == '1h'
    assert time_until(datetime(2018, 2, 3, 21, 1)) == '1h 1m'
    assert time_until(datetime(2018, 2, 3, 21, 59, 59)) in ('1h 59m', '2h')
    assert time_until(datetime(2018, 2, 3, 22)) == '2h'
    assert time_until(datetime(2018, 2, 3, 22, 0, 1)) == '2h'
    assert time_until(datetime(2018, 2, 4, 1)) == '5h'
Beispiel #4
0
 def __str__(self):
     s = "%s vs %s" % (self.team_a, self.team_b)
     if not self.time is Match.LIVE:
         time_until_str = time_until(self.time)
         if time_until_str:
             s += " at %s (in %s)" % (
                 self.time.strftime("%Y-%m-%d %H:%M %z"),
                 time_until_str,
             )
     return s
Beispiel #5
0
def get_next_episode_info(show, tz='UTC'):
    query = {'q': show, 'embed': 'nextepisode'}
    try:
        response = requests.get('http://api.tvmaze.com/singlesearch/shows',
                                query,
                                timeout=4)
        response.raise_for_status()
    except requests.exceptions.RequestException:
        log.warning('TVMaze request caused an exception', exc_info=True)
        return None

    try:
        data = response.json()
    except ValueError:
        log.warning('TVMaze returned invalid JSON: %r',
                    response.text,
                    exc_info=True)
        return None

    info = data['name']
    nextepisode = data.get('_embedded', {}).get('nextepisode')
    if nextepisode:
        log.debug('next episode data: %r', nextepisode)
        dt = parse_dt(nextepisode['airstamp'], tz)
        info += ' - season %d, episode %d airs at %s' % (
            nextepisode['season'],
            nextepisode['number'],
            dt.strftime('%Y-%m-%d %H:%M %z'),
        )
        time_until_str = time_until(dt)
        if time_until_str:
            info += ' (in %s)' % time_until_str
    else:
        status = data['status']
        if status == 'Ended':
            info += ' - cancelled :('
        else:
            info += ' - next episode not announced yet'

    return info
Beispiel #6
0
def get_next_episode_info(show, tz="UTC"):
    query = {"q": show, "embed": "nextepisode"}
    try:
        response = requests.get("http://api.tvmaze.com/singlesearch/shows",
                                query,
                                timeout=4)
        response.raise_for_status()
    except requests.exceptions.RequestException:
        log.warning("TVMaze request caused an exception", exc_info=True)
        return None

    try:
        data = response.json()
    except ValueError:
        log.warning("TVMaze returned invalid JSON: %r",
                    response.text,
                    exc_info=True)
        return None

    info = data["name"]
    nextepisode = data.get("_embedded", {}).get("nextepisode")
    if nextepisode:
        log.debug("next episode data: %r", nextepisode)
        dt = parse_dt(nextepisode["airstamp"], tz)
        info += " - season %d, episode %d airs at %s" % (
            nextepisode["season"],
            nextepisode["number"],
            dt.strftime("%Y-%m-%d %H:%M %z"),
        )
        time_until_str = time_until(dt)
        if time_until_str:
            info += " (in %s)" % time_until_str
    else:
        status = data["status"]
        if status == "Ended":
            info += " - cancelled :("
        else:
            info += " - next episode not announced yet"

    return info
Beispiel #7
0
 def time_until(self):
     return time_until(self.time)
Beispiel #8
0
def test_time_until_returns_none_for_times_in_the_past():
    assert time_until(datetime(2018, 2, 3, 19)) == None
    assert time_until(datetime(2018, 2, 3, 20)) == None
Beispiel #9
0
def test_time_until_returns_correct_estimates_for_next_day():
    assert time_until(datetime(2018, 2, 4, 19)) == "23h"
    assert time_until(datetime(2018, 2, 4, 20)) == "1d"
    assert time_until(datetime(2018, 2, 4, 21)) == "1d 1h"
    assert time_until(datetime(2018, 2, 4, 21, 59, 59)) in ("1d 1h", "1d 2h")
Beispiel #10
0
def test_time_until_returns_correct_estimates_for_next_day():
    assert time_until(datetime(2018, 2, 4, 19)) == '23h'
    assert time_until(datetime(2018, 2, 4, 20)) == '1d'
    assert time_until(datetime(2018, 2, 4, 21)) == '1d 1h'
    assert time_until(datetime(2018, 2, 4, 21, 59, 59)) in ('1d 1h', '1d 2h')