Python datetime.datetime.timetuple() Examples

The following are code examples for showing how to use datetime.datetime.timetuple(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: sfm-weibo-harvester   Author: gwu-libraries   File: weiboarc.py    (license) View Source Project 6 votes vote down vote up
def wait_time(self):
        """
        If a rate limit error is encountered we will sleep until we can
        issue the API call again.
        refer https://github.com/ghostrong/weibo-crawler/blob/master/example.py
        """
        try:
            rl = self.rate_limit()
        except Exception, e:
            rl = None

        if rl:
            if rl['remaining_ip_hits'] > 1 and rl['remaining_user_hits'] > 1:
                return 60
            return rl['reset_time_in_seconds'] + 10

        now = datetime.now()
        reset = now + timedelta(seconds=3600 - now.minute * 60 - now.second)
        reset_ts = time.mktime(datetime.timetuple(reset))
        return reset_ts - time.time() + 60 
Example 2
Project: otRebuilder   Author: Pal3love   File: Rebuilder.py    (MIT License) View Source Project 5 votes vote down vote up
def __updateHead(self):
        headT = self.font.get("head")
        if not headT:
            return
        general = self.config.get("General")
        style = self.config.get("Style")
        if general:
            version = general.get("version")
            createdTime = general.get("createdTime")
            modifiedTime = general.get("modifiedTime")
            if isinstance(version, float) or isinstance(version, int):
                headT.fontRevision = float(abs(version))
            if isinstance(createdTime, datetime):
                headT.created = long(mktime(datetime.timetuple(createdTime)) - epoch_diff)
            if isinstance(modifiedTime, datetime):
                headT.modified = long(mktime(datetime.timetuple(modifiedTime)) - epoch_diff)
                self.font.recalcTimestamp = False
        if style:
            styleLink = style.get("styleLink")
            widthScale = style.get("widthScale")
            if styleLink in range(0, 5):
                # Clear related bits first
                headT.macStyle &= ~0b11
                if styleLink == Constants.STYLELINK_BOLD:
                    headT.macStyle |= 1
                elif styleLink == Constants.STYLELINK_ITALIC:
                    headT.macStyle |= 1<<1
                elif styleLink == Constants.STYLELINK_BOLDITALIC:
                    headT.macStyle |= 1
                    headT.macStyle |= 1<<1
                else:
                    pass
            if widthScale in range(1, 10):
                headT.macStyle &= ~(0b11<<5)
                if widthScale < 5:
                    headT.macStyle |= 1<<5
                elif widthScale > 5:
                    headT.macStyle |= 1<<6
                else:
                    pass
        return 
Example 3
Project: code   Author: ActiveState   File: recipe-578875.py    (MIT License) View Source Project 5 votes vote down vote up
def painthms(self):
        self.canvas.delete(self._ALL)  # delete the handles
        T = datetime.timetuple(datetime.utcnow()-self.delta)
        x,x,x,h,m,s,x,x,x = T
        self.root.title('%02i:%02i:%02i' %(h,m,s))
        angle = pi/2 - pi/6 * (h + m/60.0)
        x, y = cos(angle)*0.70,sin(angle)*0.70   
        scl = self.canvas.create_line
        # draw the hour handle
        scl(self.T.windowToViewport(0,0,x,y), fill = self.timecolor, tag=self._ALL, width = self.pad/3)
        angle = pi/2 - pi/30 * (m + s/60.0)
        x, y = cos(angle)*0.90,sin(angle)*0.90
        # draw the minute handle
        scl(self.T.windowToViewport(0,0,x,y), fill = self.timecolor, tag=self._ALL, width = self.pad/5)
        angle = pi/2 - pi/30 * s
        x, y = cos(angle)*0.95,sin(angle)*0.95   
        # draw the second handle
        scl(self.T.windowToViewport(0,0,x,y), fill = self.timecolor, tag=self._ALL, arrow = 'last')
   
    ## Draws a circle at a given point.
    # 
    #  @param x,y given point.
    # 
Example 4
Project: sigpath   Author: utds3lab   File: minidump.py    (license) View Source Project 5 votes vote down vote up
def _encode(self, obj, ctx):
        return int(mktime(datetime.timetuple())) 
Example 5
Project: sigpath   Author: utds3lab   File: minidump.py    (license) View Source Project 5 votes vote down vote up
def _encode(self, obj, ctx):
        unix_time = int(mktime(datetime.timetuple()))
        if unix_time == 0:
            return unix_time

        windows_time = unix_time + 11644473600
        windows_time = windows_time * 10000000
        return windows_time 
Example 6
Project: amonone   Author: amonapp   File: dates.py    (license) View Source Project 5 votes vote down vote up
def datetime_to_unixtime(datetime):
    return int(calendar.timegm(datetime.timetuple()))

# Converts date string to unix UTC time 
Example 7
Project: oejia_wx   Author: JoneXiong   File: fields.py    (license) View Source Project 5 votes vote down vote up
def to_xml(self, value):
        value = time.mktime(datetime.timetuple(value))
        value = int(value)
        tpl = '<{name}>{value}</{name}>'
        return tpl.format(name=self.name, value=value) 
Example 8
Project: uscensus   Author: nkrishnaswami   File: discovery.py    (license) View Source Project 5 votes vote down vote up
def format_datetime(dt):
        now = time.mktime(dt.timetuple())
        return formatdate(now) 
Example 9
Project: TornadoWeb   Author: VxCoder   File: fields.py    (license) View Source Project 5 votes vote down vote up
def to_xml(self, value):
        value = time.mktime(datetime.timetuple(value))
        value = int(value)
        tpl = '<{name}>{value}</{name}>'
        return tpl.format(name=self.name, value=value)