예제 #1
0
def get_next_event_text(calendar, after=None, include_current=None, tz=None, verbose=True):
	"""
	Build the actual human-readable response to the !next command.

	The tz parameter can override the timezone used to display the event times.
	This can be an actual timezone object, or a string timezone name.
	Defaults to moonbase time.
	"""
	if after is None:
		after = datetime.datetime.now(datetime.timezone.utc)
	if not tz:
		tz = config['timezone']
	elif isinstance(tz, str):
		tz = tz.strip()
		try:
			tz = utils.get_timezone(tz)
		except pytz.exceptions.UnknownTimeZoneError:
			return "Unknown timezone: %s" % tz

	events = get_next_event(calendar, after=after, include_current=include_current)
	if not events:
		return "There don't seem to be any upcoming scheduled streams"

	strs = []
	for i, ev in enumerate(events):
		if ev['location'] is not None:
			title = "%(title)s (%(location)s)" % ev
		else:
			title = ev['title']
		# If several events are at the same time, just show the time once after all of them
		if i == len(events) - 1 or ev['start'] != events[i+1]['start']:
			if verbose:
				if ev['start'] < after:
					nice_duration = utils.nice_duration(after - ev['start'], 1) + " ago"
				else:
					nice_duration = utils.nice_duration(ev['start'] - after, 1) + " from now"
				strs.append("%s at %s (%s)" % (title, ev['start'].astimezone(tz).strftime(DISPLAY_FORMAT), nice_duration))
			else:
				strs.append("%s at %s" % (ev['title'], ev['start'].astimezone(tz).strftime(DISPLAY_FORMAT)))
		else:
			strs.append(title if verbose else ev['title'])
	response = ', '.join(strs)

	if verbose:
		if calendar == CALENDAR_LRL:
			response = "Next scheduled stream: %s." % response
		elif calendar == CALENDAR_FAN:
			response = "Next scheduled fan stream: %s." % response

	return utils.shorten(response, 450) # For safety
예제 #2
0
파일: misc.py 프로젝트: TomHanra/lrrbot
def desertbus(lrrbot, conn, event, respond_to, timezone):
	if not timezone:
		timezone = config['timezone']
	else:
		timezone = timezone.strip()
		try:
			timezone = utils.get_timezone(timezone)
		except pytz.exceptions.UnknownTimeZoneError:
			conn.privmsg(respond_to, "Unknown timezone: %s" % timezone)

	now = datetime.datetime.now(datetime.timezone.utc)

	if now < DESERTBUS_START:
		nice_duration = utils.nice_duration(DESERTBUS_START - now, 1) + " from now"
		conn.privmsg(respond_to, "Desert Bus for Hope will begin at %s (%s)" % (DESERTBUS_START.astimezone(timezone).strftime(
			googlecalendar.DISPLAY_FORMAT), nice_duration))
	elif now < DESERTBUS_END:
		conn.privmsg(respond_to, "Desert Bus for Hope is currently live! Go watch it now at http://desertbus.org/live/")
	else:
		conn.privmsg(respond_to, "Desert Bus for Hope will return next year, start saving your donation money now!")
예제 #3
0
파일: misc.py 프로젝트: keab42/lrrbot
def desertbus(lrrbot, conn, event, respond_to, timezone):
	if not timezone:
		timezone = config['timezone']
	else:
		timezone = timezone.strip()
		try:
			timezone = utils.get_timezone(timezone)
		except pytz.exceptions.UnknownTimeZoneError:
			conn.privmsg(respond_to, "Unknown timezone: %s" % timezone)

	now = datetime.datetime.now(datetime.timezone.utc)

	if now < DESERTBUS_START:
		nice_duration = utils.nice_duration(DESERTBUS_START - now, 1) + " from now"
		conn.privmsg(respond_to, "Desert Bus for Hope will begin at %s (%s)" % (DESERTBUS_START.astimezone(timezone).strftime(
			googlecalendar.DISPLAY_FORMAT), nice_duration))
	elif now < DESERTBUS_END:
		conn.privmsg(respond_to, "Desert Bus for Hope is currently live! Go watch it now at http://desertbus.org/live/")
	else:
		conn.privmsg(respond_to, "Desert Bus for Hope will return next year, start saving your donation money now!")
예제 #4
0
def get_next_event_text(calendar,
                        after=None,
                        include_current=None,
                        tz=None,
                        verbose=True):
    """
	Build the actual human-readable response to the !next command.

	The tz parameter can override the timezone used to display the event times.
	This can be an actual timezone object, or a string timezone name.
	Defaults to moonbase time.
	"""
    if after is None:
        after = datetime.datetime.now(datetime.timezone.utc)
    if not tz:
        tz = config['timezone']
    elif isinstance(tz, str):
        tz = tz.strip()
        try:
            tz = utils.get_timezone(tz)
        except pytz.exceptions.UnknownTimeZoneError:
            return "Unknown timezone: %s" % tz

    events = get_next_event(calendar,
                            after=after,
                            include_current=include_current)
    if not events:
        return "There don't seem to be any upcoming scheduled streams"

    strs = []
    for i, ev in enumerate(events):
        # If several events are at the same time, just show the time once after all of them
        if i == len(events) - 1 or ev['start'] != events[i + 1]['start']:
            if verbose:
                if ev['location'] is not None:
                    title = "%(title)s (%(location)s)" % ev
                else:
                    title = ev['title']
                if ev['start'] < after:
                    nice_duration = utils.nice_duration(
                        after - ev['start'], 1) + " ago"
                else:
                    nice_duration = utils.nice_duration(
                        ev['start'] - after, 1) + " from now"
                strs.append(
                    "%s at %s (%s)" %
                    (title,
                     ev['start'].astimezone(tz).strftime(DISPLAY_FORMAT),
                     nice_duration))
            else:
                strs.append(
                    "%s at %s" %
                    (ev['title'],
                     ev['start'].astimezone(tz).strftime(DISPLAY_FORMAT)))
        else:
            strs.append(ev['title'])
    response = ', '.join(strs)

    if verbose:
        if calendar == CALENDAR_LRL:
            response = "Next scheduled stream: " + response
        elif calendar == CALENDAR_FAN:
            response = "Next scheduled fan stream: " + response

    return utils.shorten(response, 450)  # For safety