Example #1
0
    def human_msg_age(self,ts):
        """ Human message reporting message age. ts is the time stamp provided
            by twitter (string).
            See function GetRelativeCreatedAt()
            http://code.google.com/p/python-twitter/source/browse/trunk/twitter.py
        """
        fudge = 1.25
        ma = time.mktime(self._strptime(ts))
        delta  = int(time.mktime(time.gmtime())) - int(ma)

        if delta < (1 * fudge):
          return u'~1s ago'
        elif delta < (60 * (1/fudge)):
          return u'~%ds ago' % (delta)
        elif delta < (60 * fudge):
          return u'~1m ago'
        elif delta < (60 * 60 * (1/fudge)):
          return u'~%dm ago' % (delta / 60)
        elif delta < (60 * 60 * fudge):
          return u'~1h ago'
        elif delta < (60 * 60 * 24 * (1/fudge)):
          return u'~%dh ago' % (delta / (60 * 60))
        elif delta < (60 * 60 * 24 * fudge):
          return u'~1d ago'
        else:
          return u'~%dd ago' % (delta / (60 * 60 * 24))
Example #2
0
    def edit_comment(self, idx, email, realname, website, contents):
        comment_id = self.comments[idx]['comment_id']
        comment = wp.WordPressEditComment()
        comment.status = 'approve'
        comment.content = unicode_to_utf8( contents )
        comment.author = unicode_to_utf8( realname )
        comment.author_url = unicode_to_utf8( website )
        comment.author_email = unicode_to_utf8( email )
        comment.date_created_gmt = DateTime(time.mktime(time.gmtime())) # gmt time required
    
        try:
            self.blog.editComment(comment_id, comment)
        except:
            note(LABELS.loc.wp_err_cant_updt_cmt,"error")
            return False

        try:
            c = self.blog.getComment( comment_id )
        except:
            note(LABELS.loc.wp_err_cant_updt_cmt_list,"error")
            c = None

        if c:
            self.comments[idx] = c

        return True
Example #3
0
 def delete_only_remote_post(self,idx):
     """ Delete remote post, keeping local changes
     """
     if self.post_is_remote(idx):
         try:
             self.blog.deletePost(self.posts[idx]['postid'])
         except:
             return False
         del self.posts[idx]['postid']
         self.posts[idx]['dateCreated'] = DateTime(time.mktime(time.gmtime()))
         self.posts[idx]['wordmobi'] = True
         self.save()
         return True
     return False
Example #4
0
 def save_new_post(self, title, contents, categories, tags, publish):
     """ Instead posting, save the post locally.
         We need to create a post like that one provided by xmlrpclib (utf8).
         Otherwise, WM will fail when decoding this post.
         Just a new dict is added (wordmobi), for controlling.
         See parameters in new_post.
     """
     if publish:
         pub = 'publish'
     else:
         pub = 'draft'
     dt = time.gmtime()
     pst = { 'title': unicode_to_utf8(title),
             'description': unicode_to_utf8(contents),
             'categories':[ unicode_to_utf8(c) for c in categories ],
             'mt_keywords':",".join([ unicode_to_utf8(t) for t in tags ]),
             'post_status':pub,
             'dateCreated':DateTime(time.mktime(dt)),
             'mt_text_more':'',
             'wordmobi':True
             }
     self.posts.insert(0,pst)
     self.save()
Example #5
0
def get_period_time_stamp():
	t = datetime.datetime.now()
	t = t - datetime.timedelta(hours = 12)
	#t = t.replace(hour = 0, minute = 0, second = 0, microsecond = 0)
	stamp = time.mktime(t.timetuple())
	return stamp
Example #6
0
def gm_to_localtime( tm ):
    diff = time.time() - time.mktime(time.gmtime())
    return time.localtime(time.mktime( tm ) + diff)