Beispiel #1
0
    def UpdateCollection(self,
                         entry,
                         status,
                         tag=[],
                         rating=None,
                         private=False):
        if isinstance(entry, (str, unicode)):
            entry = self.Get(entry, douban.CollectionEntryFromString)

        entry.status = douban.Status(status)
        if rating:
            entry.rating = douban.Rating(rating)
        if tag:
            if isinstance(tag, (str, unicode)):
                tag = filter(None, tag.split(' '))
            entry.tags = [douban.Tag(name=t) for t in tag]
        else:
            entry.tags = [douban.Tag(name=t.name) for t in entry.tags]
        if private:
            attribute = douban.Attribute('privacy', 'private')
            entry.attribute.append(attribute)
        else:
            attribute = douban.Attribute('privacy', 'public')
            entry.attribute.append(attribute)
        uri = entry.GetSelfLink().href
        return self.Put(entry, uri, converter=douban.CollectionEntryFromString)
Beispiel #2
0
 def AddNote(self, uri, entry, private=False, can_reply=True):
     if private:
         attribute = douban.Attribute('privacy', 'private')
         entry.attribute.append(attribute)
     else:
         attribute = douban.Attribute('privacy', 'public')
         entry.attribute.append(attribute)
     if can_reply:
         attribute = douban.Attribute('can_reply', 'yes')
         entry.attribute.append(attribute)
     else:
         attribute = douban.Attribute('can_reply', 'no')
         entry.attribute.append(attribute)
     return self.Post(entry, uri, converter=douban.NoteEntryFromString)
Beispiel #3
0
 def addRecommendation(self, title, url, comment=""):
     entry = douban.RecommendationEntry()
     entry.title = atom.Title(text=title)
     entry.link = atom.Link(href=url, rel="related")
     attribute = douban.Attribute('comment', comment)
     entry.attribute.append(attribute)
     return self.__parsed(self.__post("/recommendations", entry.ToString()),
                          douban.RecommendationEntryFromString)
Beispiel #4
0
 def AddCaptchaDoumail(self, receiverURI, subject, body, captcha_token,
                       captacha_string):
     entry = douban.DoumailEntry()
     entry.entity.append(
         douban.Entity('receiver',
                       "",
                       extension_elements=[atom.Uri(text=receiverURI)]))
     entry.title = atom.Title(text=subject)
     entry.content = atom.Content(text=body)
     entry.attribute = []
     entry.attribute.append(
         douban.Attribute('captcha_string', captacha_string))
     entry.attribute.append(douban.Attribute('captcha_token',
                                             captcha_token))
     return self.Post(entry,
                      '/doumails',
                      converter=douban.DoumailEntryFromString)
Beispiel #5
0
    def UpdateEvent(self,
                    entry,
                    content,
                    title,
                    invite_only=False,
                    can_invite=True):
        if isinstance(entry, (str, unicode)):
            entry = self.Get(entry, douban.EventEntryFromString)

        entry.title = atom.Title(text=title)
        entry.content = atom.Content(text=content)
        entry.attribute.append(
            douban.Attribute('invite_only', invite_only and 'yes' or 'no'))
        entry.attribute.append(
            douban.Attribute('can_invite', can_invite and 'yes' or 'no'))
        uri = entry.GetSelfLink().href
        return self.Put(entry, uri, converter=douban.EventEntryFromString)
Beispiel #6
0
 def MarkDoumailRead(self, uris):
     feed = gdata.GDataFeed()
     for uri in uris:
         entry = gdata.GDataEntry()
         entry.id = atom.Id(text=uri)
         entry.attribute = []
         entry.attribute.append(douban.Attribute('unread', 'false'))
         feed.entry.append(entry)
     return self.Put(feed, '/doumail/')
Beispiel #7
0
 def AddRecommendation(self, title, url, comment=""):
     entry = douban.RecommendationEntry()
     entry.title = atom.Title(text=title)
     entry.link = atom.Link(href=url, rel="related")
     attribute = douban.Attribute('comment', comment)
     entry.attribute.append(attribute)
     return self.Post(entry,
                      '/recommendations',
                      converter=douban.RecommendationEntryFromString)
Beispiel #8
0
    def UpdateNote(self, entry, content, title, private=True, can_reply=True):
        if isinstance(entry, (str, unicode)):
            entry = self.Get(entry, douban.NoteEntryFromString)

        entry.title = atom.Title(text=title)
        entry.content = atom.Content(text=content)
        if private:
            attribute = douban.Attribute('privacy', 'private')
            entry.attribute.append(attribute)
        else:
            attribute = douban.Attribute('privacy', 'public')
            entry.attribute.append(attribute)
        if can_reply:
            attribute = douban.Attribute('can_reply', 'yes')
            entry.attribute.append(attribute)
        else:
            attribute = douban.Attribute('can_reply', 'no')
            entry.attribute.append(attribute)
        uri = entry.id.text
        return self.Put(entry, uri, converter=douban.NoteEntryFromString)
Beispiel #9
0
 def addDoumail(self,
                to,
                subject,
                body,
                captacha_token=None,
                captacha_string=None):
     entry = douban.DoumailEntry()
     receiverURI = "http://api.douban.com/people/%s" % to
     entry.entity.append(
         douban.Entity('receiver',
                       "",
                       extension_elements=[atom.Uri(text=receiverURI)]))
     entry.title = atom.Title(text=subject)
     entry.content = atom.Content(text=body)
     if captacha_token:
         entry.attribute.append(
             douban.Attribute('captacha_token', captacha_token))
     if captacha_string:
         entry.attribute.append(
             douban.Attribute('captacha_string', captacha_string))
     return self.__post("/doumails", entry.ToString())
Beispiel #10
0
 def AddCollection(self,
                   status,
                   subject,
                   rating=None,
                   tag=[],
                   private=True):
     subject = douban.Subject(atom_id=subject.id)
     entry = douban.CollectionEntry(subject=subject,
                                    status=douban.Status(status))
     if rating:
         entry.rating = douban.Rating(rating)
     if isinstance(tag, (str, unicode)):
         tag = filter(None, tag.split(' '))
     if private:
         attribute = douban.Attribute('privacy', 'private')
         entry.attribute.append(attribute)
     else:
         attribute = douban.Attribute('privacy', 'public')
         entry.attribute.append(attribute)
     entry.tags = [douban.Tag(name=t) for t in tag]
     return self.Post(entry,
                      '/collection',
                      converter=douban.CollectionEntryFromString)
Beispiel #11
0
 def AddEvent(self, uri, entry, invite_only=False, can_invite=True):
     entry.attribute.append(
         douban.Attribute('invite_only', invite_only and 'yes' or 'no'))
     entry.attribute.append(
         douban.Attribute('can_invite', can_invite and 'yes' or 'no'))
     return self.Post(entry, uri, converter=douban.EventEntryFromString)