Example #1
0
def date_range(dfrom, dto):
    if dfrom and dto and dfrom != dto:
        return 'from %s to %s' % (web.datestr(dfrom), web.datestr(dto))
    elif ((dfrom == dto) and dfrom) or dfrom or dto:
        return 'on %s' % web.datestr(dfrom or dto)
    else:
        return ''
Example #2
0
def date_range(dfrom, dto):
    if dfrom and dto and dfrom != dto:
        return 'from %s to %s' % (web.datestr(dfrom), web.datestr(dto))
    elif ((dfrom == dto) and dfrom) or dfrom or dto:
        return 'on %s' % web.datestr(dfrom or dto)
    else:
        return ''
Example #3
0
    def get(self):
        query = self._story_query()
        tmp_stories = web.query(query)

        stories = []
        next_page = prev_page = False
        for idx, s in enumerate(tmp_stories):
            if idx >= config.stories_per_page:
                next_page = True
                break
            s.host = get_nice_host(s['url'])
            s.niceago = web.datestr(datetime.fromtimestamp(s['date_reddit']), datetime.now())
            stories.append(s)

        if self.page != 1:
            prev_page = True

        next_page_link = prev_page_link = None
        if next_page:
            next_page_link = self.next_page(self.subreddit, self.page)
        if prev_page:
            prev_page_link = self.prev_page(self.subreddit, self.page)

        return {'stories': stories,
                'next_page': next_page,
                'prev_page': prev_page,
                'next_page_link': next_page_link,
                'prev_page_link': prev_page_link}
Example #4
0
    def get(self):
        query = self._story_query()
        tmp_stories = web.query(query)

        stories = []
        next_page = prev_page = False
        for idx, s in enumerate(tmp_stories):
            if idx >= config.stories_per_page:
                next_page = True
                break
            s.host = get_nice_host(s['url'])
            s.niceago = web.datestr(datetime.fromtimestamp(s['date_reddit']),
                                    datetime.now())
            stories.append(s)

        if self.page != 1:
            prev_page = True

        next_page_link = prev_page_link = None
        if next_page:
            next_page_link = self.next_page(self.subreddit, self.page)
        if prev_page:
            prev_page_link = self.prev_page(self.subreddit, self.page)

        return {
            'stories': stories,
            'next_page': next_page,
            'prev_page': prev_page,
            'next_page_link': next_page_link,
            'prev_page_link': prev_page_link
        }
Example #5
0
def datestr(then, now=None):
    """Internationalized version of web.datestr."""
    result = web.datestr(then, now)
    if result[0] in string.digits: # eg: 2 milliseconds ago
        t, message = result.split(' ', 1)
        return _("%d " + message) % int(t)
    else:
        return babel.dates.format_date(then, format="long", locale=get_locale())
Example #6
0
def datestr(then, now=None, lang=None):
    """Internationalized version of web.datestr."""
    result = web.datestr(then, now)
    if result[0] in string.digits: # eg: 2 milliseconds ago
        t, message = result.split(' ', 1)
        return _("%d " + message) % int(t)
    else:
        return format_date(then, lang=lang)
Example #7
0
 def get(self):
     query = self._story_query()
     tmp_stories = web.query(query)
     stories = []
     for s in tmp_stories:
         s.host = get_nice_host(s['url'])
         s.niceago = web.datestr(datetime.fromtimestamp(s['date_reddit']), datetime.now())
         stories.append(s)
     return stories
Example #8
0
def datestr(then, now=None, lang=None):
    """Internationalized version of web.datestr."""
    result = web.datestr(then, now)
    if not result:
        return result
    elif result[0] in string.digits:  # eg: 2 milliseconds ago
        t, message = result.split(' ', 1)
        return _("%d " + message) % int(t)
    else:
        return format_date(then, lang=lang)
Example #9
0
 def get(self):
     query = self._story_query()
     tmp_stories = web.query(query)
     stories = []
     for s in tmp_stories:
         s.host = get_nice_host(s['url'])
         s.niceago = web.datestr(datetime.fromtimestamp(s['date_reddit']),
                                 datetime.now())
         stories.append(s)
     return stories
Example #10
0
def messageoffset(id, offset):
    messages = web.select('messages', where='thread_id = %s and id > %s' % (web.sqlquote(id), web.sqlquote(offset)))
    
    offsetmessages = []
    
    for message in messages:
        message['date_sent'] = web.datestr(message['date_sent'])
        message['author'] = people.getperson(message.author_id).name
        offsetmessages.append(message)
        
    return offsetmessages
Example #11
0
def datestr(then, now=None):
    """Converts time to a human readable string.

    Wrapper over web.datestr.

        >>> from datetime import datetime
        >>> datestr(datetime(2010, 1, 2), datetime(2010, 1, 1))
        '1 day ago'
    """
    s = web.datestr(then, now)
    if 'milliseconds' in s or 'microseconds' in s:
        s = 'Just now'
    return s
Example #12
0
def datestr(then, now=None, lang=None, relative = True):
    """Internationalized version of web.datestr."""
    if not relative:
        result = then.strftime("%b %d %Y")
    else:
        result = web.datestr(then, now)
    if not result:
        return result
    elif result[0] in string.digits: # eg: 2 milliseconds ago
        t, message = result.split(' ', 1)
        return _("%d " + message) % int(t)
    else:
        return format_date(then, lang=lang)
Example #13
0
def threadtranscript(threadid):
    thread = getthread(threadid)
    messages = getmessages(threadid)
    lastmessage = 0 # see javascript api for more information
    
    thread = web.storify(thread)
    thread.date_started = web.datestr(thread.date_started)
    
    transcript = { 'thread': thread, 'messages': None }
    transcript = web.storify(transcript)
    
    transcript.messages = []
    
    for message in messages:
        transcript.messages.append({ 'id': message.id, 'author_id': message.author_id, 'author': people.getperson(message.author_id).name, 'content': message.content, 'time': web.datestr(message.date_sent)})
        lastmessage = message.id
        
    transcript.thread.last_message = lastmessage
    
    return transcript
Example #14
0
def datestr(then, now=None):
    """Internationalized version of web.datestr"""

    # Examples:
    # 2 seconds from now
    # 2 microseconds ago
    # 2 milliseconds ago
    # 2 seconds ago
    # 2 minutes ago
    # 2 hours ago
    # 2 days ago
    # January 21
    # Jaunary 21, 2003

    result = web.datestr(then, now)
    _ = i18n.strings.get_namespace('/utils/date')
    if result[0] in string.digits:  # eg: 2 milliseconds ago
        t, unit, ago = result.split(' ', 2)
        return "{} {} {}".format(t, _[unit], _[ago.replace(' ', '_')])
    else:
        month, rest = result.split(' ', 1)
        return f"{_[month.lower()]} {rest}"
Example #15
0
def datestr(then, now=None):
    """Internationalized version of web.datestr"""
    
    # Examples:
    # 2 seconds from now
    # 2 microseconds ago
    # 2 milliseconds ago
    # 2 seconds ago
    # 2 minutes ago
    # 2 hours ago
    # 2 days ago
    # January 21
    # Jaunary 21, 2003
    
    result = web.datestr(then, now)
    _ = i18n.strings.get_namespace('/utils/date')
    
    import string
    if result[0] in string.digits: # eg: 2 milliseconds ago
        t, unit, ago = result.split(' ', 2)
        return "%s %s %s" % (t, _[unit], _[ago.replace(' ', '_')])
    else:
        month, rest = result.split(' ', 1)
        return "%s %s" % (_[month.lower()], rest)
Example #16
0
 def datestr(self,date):
     return web.datestr(date)
Example #17
0
def datestr(x):
    """
    Can't seem to set mysql creation ddl to UTC, so we'll have to adjust the datestr
    function to localtime which we will assume is the same as your database server.
    """
    return web.datestr(x, datetime.datetime.now())
Example #18
0
def how_long(d):
    return web.datestr(d, datetime.datetime.now())
Example #19
0
urls = (
    "/",
    "Index",
    "/view/(\d+)",
    "View",
    "/new",
    "New",
    "/delete/(\d+)",
    "Delete",
    "/edit/(\d+)",
    "Edit",
)

t_globals = {'datestr': web.datestr}
print("posted_on is %s " % datetime.datetime.utcnow())
print(web.datestr(datetime.datetime.utcnow()))
print(web.datestr(datetime.datetime.utcnow()))
# 定义模板位置,并设置base为基础模板(先加载它,并设置了一个公共变量)
path = os.path.dirname(__file__) + "/templates/"
render = web.template.Render(path, base="base", globals=t_globals)


class Index:
    def GET(self):
        posts = model.get_posts()
        return render.index(posts)


class View:
    def GET(self, id):
        post = model.get_post(int(id))
Example #20
0
def how_long(d):
    return web.datestr(d, datetime.datetime.now())
Example #21
0
def transform_datestr(posted_on):
    datetime_obj = datetime.datetime.strptime(posted_on, '%Y-%m-%d %H:%M:%S.%f')
    return web.datestr(datetime_obj)
Example #22
0
 def GET(self):
     """ Show page """
     posts = model.get_posts()
     for p in posts:
         print web.datestr(p.posted_on)
     return render.index(posts)
def Timestringify(timestamp):
    return web.datestr(datetime.datetime.utcfromtimestamp(timestamp), now=now)
Example #24
0
 def datestr(self, date):
     return web.datestr(date)
Example #25
0
def datestr(x):
    """
    Can't seem to set mysql creation ddl to UTC, so we'll have to adjust the datestr
    function to localtime which we will assume is the same as your database server.
    """
    return web.datestr(x, datetime.datetime.now())