Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(20)  |  Call(16)  |  Derive(0)  |  Import(4)

        def get_timezone(db=None, config=None, zone=None, nick=None, channel=None):
    """Find, and return, the approriate timezone

    Time zone is pulled in the following priority:
    1. `zone`, if it is valid
    2. The timezone for `zone` in `db` if one is set and valid.
    3. The timezone for `nick` in `db`, if one is set and valid.
    4. The timezone for `channel` in `db`, if one is set and valid.
    5. The default timezone in `config`, if one is set and valid.

    If `db` is not given, or given but not set up, steps 2 and 3 will be
    skipped. If `config` is not given, step 4 will be skipped. If no step
    yeilds a valid timezone, `None` is returned.

    Valid timezones are those present in the IANA Time Zone Database. Prior to
    checking timezones, two translations are made to make the zone names more
    human-friendly. First, the string is split on `', '`, the pieces reversed,
    and then joined with `'/'`. Next, remaining spaces are replaced with `'_'`.
    Finally, strings longer than 4 characters are made title-case, and those 4
    characters and shorter are made upper-case. This means "new york, america"
    becomes "America/New_York", and "utc" becomes "UTC".

    This function relies on `pytz` being available. If it is not available,
    `None` will always be returned.
    """
    if not pytz:
        return None
    tz = None

    def check(zone):
        """Returns the transformed zone, if valid, else None"""
        if zone:
            zone = '/'.join(reversed(zone.split(', '))).replace(' ', '_')
            if len(zone) <= 4:
                zone = zone.upper()
            else:
                zone = zone.title()
            if zone in pytz.all_timezones:
                return zone
        return None

    if zone:
        tz = check(zone)
        if not tz and zone in db.preferences:
            tz = check(db.preferences.get(zone, 'tz'))
    if not tz and nick and nick in db.preferences:
        tz = check(db.preferences.get(nick, 'tz'))
    if not tz and channel and channel in db.preferences:
        tz = check(db.preferences.get(channel, 'tz'))
    if not tz and config and config.has_option('core', 'default_timezone'):
        tz = check(config.core.default_timezone)
    return tz
        


src/w/i/willie-4.3.0/willie/modules/seen.py   willie(Download)
import time
import datetime
from willie.tools import Ddict, Nick, get_timezone, format_time
from willie.module import commands, rule, priority
 
        message = seen_dict[nick]['message']
 
        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)

src/w/i/willie-HEAD/willie/modules/seen.py   willie(Download)
import time
import datetime
from willie.tools import Ddict, Nick, get_timezone, format_time
from willie.module import commands, rule, priority
 
        message = seen_dict[nick]['message']
 
        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)

src/w/i/willie-4.3.0/willie/modules/clock.py   willie(Download)
import datetime
from willie.module import commands, example, OP
from willie.tools import get_timezone, format_time
 
 
def f_time(bot, trigger):
    """Returns the current time."""
    if trigger.group(2):
        zone = get_timezone(bot.db, bot.config, trigger.group(2).strip(), None, None)
        if not zone:
            bot.say('Could not find timezone %s.' % trigger.group(2).strip())
            return
    else:
        zone = get_timezone(bot.db, bot.config, None, trigger.nick,
                         " http://strftime.net to make one.")
 
        tz = get_timezone(bot.db, bot.config, None, None,
                                       trigger.sender)
        try:
                         " http://strftime.net to make one.")
 
        tz = get_timezone(bot.db, bot.config, None, None,
                                       trigger.sender)
        try:

src/w/i/willie-HEAD/willie/modules/clock.py   willie(Download)
import datetime
from willie.module import commands, example, OP
from willie.tools import get_timezone, format_time
 
 
def f_time(bot, trigger):
    """Returns the current time."""
    if trigger.group(2):
        zone = get_timezone(bot.db, bot.config, trigger.group(2).strip(), None, None)
        if not zone:
            bot.say('Could not find timezone %s.' % trigger.group(2).strip())
            return
    else:
        zone = get_timezone(bot.db, bot.config, None, trigger.nick,
                         " http://strftime.net to make one.")
 
        tz = get_timezone(bot.db, bot.config, None, None,
                                       trigger.sender)
        try:
                         " http://strftime.net to make one.")
 
        tz = get_timezone(bot.db, bot.config, None, None,
                                       trigger.sender)
        try:

src/w/i/willie-4.3.0/willie/modules/tell.py   willie(Download)
 
    if not tellee in (Nick(teller), bot.nick, 'me'):
        tz = willie.tools.get_timezone(bot.db, bot.config, None, tellee)
        timenow = willie.tools.format_time(bot.db, bot.config, tz, tellee)
        bot.memory['tell_lock'].acquire()

src/w/i/willie-HEAD/willie/modules/tell.py   willie(Download)
 
    if not tellee in (Nick(teller), bot.nick, 'me'):
        tz = willie.tools.get_timezone(bot.db, bot.config, None, tellee)
        timenow = willie.tools.format_time(bot.db, bot.config, tz, tellee)
        bot.memory['tell_lock'].acquire()

src/w/i/willie-4.3.0/willie/modules/remind.py   willie(Download)
        duration = int(duration)
    timezone = willie.tools.get_timezone(
        bot.db, bot.config, None, trigger.nick, trigger.sender)
    create_reminder(bot, trigger, duration, reminder, timezone)
 
 
    if pytz:
        timezone = willie.tools.get_timezone(bot.db, bot.config, tz,
                                             trigger.nick, trigger.sender)
        now = datetime.now(pytz.timezone(timezone))

src/w/i/willie-HEAD/willie/modules/remind.py   willie(Download)
        duration = int(duration)
    timezone = willie.tools.get_timezone(
        bot.db, bot.config, None, trigger.nick, trigger.sender)
    create_reminder(bot, trigger, duration, reminder, timezone)
 
 
    if pytz:
        timezone = willie.tools.get_timezone(bot.db, bot.config, tz,
                                             trigger.nick, trigger.sender)
        if not timezone: