Exemple #1
0
def createnewalbum(albumname, rights, gds, username):
    """Create new album with specified name and rights.

    Create new album with specified name, rights and return its feed url for posting.
    """
    print 'Photos will be inserted in a newly-created album', albumname, 'with rights', rights # debug
    # prepare metadata
    gdata_entry = gdata.GDataEntry()
    gdata_entry.title = atom.Title(text=albumname)
    # create new albums as private
    gdata_entry.rights = atom.Rights(text=rights) # standard atom rights
    # extended rights definition in google namespace
    ext_rights = atom.ExtensionElement(
		    tag='access',
		    namespace='http://schemas.google.com/photos/2007')
    ext_rights.text = rights # setting the extended rights
    gdata_entry.extension_elements.append(ext_rights)
    # listing categories of gdata_entry (binding to picasa service)
    gdata_entry.category.append(atom.Category(
            scheme = gdata.GDATA_NAMESPACE + '#kind',
            term = 'http://schemas.google.com/photos/2007#album'
            ))
    # create new album entry by submitting gdata object
    try:
        album = gds.Post(
                gdata_entry,
                'http://picasaweb.google.com/data/feed/api/user/' + username
                )
    except:
        sys.exit('Error while creating new album: ' + sys.exc_info()[0])
    # Note: here we have `album` as gdata.GDataEntry object
    return album.GetFeedLink().href # return album feed url
    def testAtomBaseConvertsExtensions(self):
        # Using Id because it adds no additional members.
        atom_base = atom.Id()
        extension_child = atom.ExtensionElement('foo',
                                                namespace='http://ns0.com')
        extension_grandchild = atom.ExtensionElement(
            'bar', namespace='http://ns0.com')
        extension_child.children.append(extension_grandchild)
        atom_base.extension_elements.append(extension_child)
        self.assertEquals(len(atom_base.extension_elements), 1)
        self.assertEquals(len(atom_base.extension_elements[0].children), 1)
        self.assertEquals(atom_base.extension_elements[0].tag, 'foo')
        self.assertEquals(atom_base.extension_elements[0].children[0].tag,
                          'bar')

        element_tree = atom_base._ToElementTree()
        self.assert_(element_tree.find('{http://ns0.com}foo') is not None)
        self.assert_(
            element_tree.find('{http://ns0.com}foo').find(
                '{http://ns0.com}bar') is not None)
    def testNormalAuthorShouldHaveNoExtensionElements(self):
        self.author.name = atom.Name(text='Jeff Scudder')
        self.assert_(self.author.name.text == 'Jeff Scudder')
        self.assert_(len(self.author.extension_elements) == 0)
        new_author = atom.AuthorFromString(self.author.ToString())
        self.assert_(len(self.author.extension_elements) == 0)

        self.author.extension_elements.append(
            atom.ExtensionElement('foo', text='bar'))
        self.assert_(len(self.author.extension_elements) == 1)
        self.assert_(self.author.name.text == 'Jeff Scudder')
        new_author = atom.AuthorFromString(self.author.ToString())
        self.assert_(len(self.author.extension_elements) == 1)
        self.assert_(new_author.name.text == 'Jeff Scudder')
Exemple #4
0
    def createAlbum(self, folderName, public=True):
        gd_entry = gdata.GDataEntry()
        gd_entry.title = atom.Title(text=folderName)
        gd_entry.category.append(
            atom.Category(scheme='http://schemas.google.com/g/2005#kind',
                          term='http://schemas.google.com/photos/2007#album'))

        rights = public and "public" or "private"
        gd_entry.rights = atom.Rights(text=rights)

        ext_rights = atom.ExtensionElement(
            tag='access', namespace='http://schemas.google.com/photos/2007')
        ext_rights.text = rights
        gd_entry.extension_elements.append(ext_rights)

        album_entry = self.Post(
            gd_entry,
            'http://picasaweb.google.com/data/feed/api/user/' + self.email)

        return PicasaAlbum(self, album_entry)
 def setUp(self):
     self.ee = atom.ExtensionElement('foo')
Exemple #6
0
    def _CreateBirthdayWebContentEvent(self, name, birthday, photo_url):
        """ Create the birthday web content event.

        This function creates and populates a CalendarEventEntry. webContent
        specific attributes are set. To learn more about the webContent
        format:

        http://www.google.com/support/calendar/bin/answer.py?answer=48528

        Args:
          name: string
          birthday: string - expected format (MM/DD)
          photo_url: string     

        Returns:
           the webContent CalendarEventEntry
    """

        title = "%s's Birthday!" % name
        content = "It's %s's Birthday!" % name
        month = string.atoi(birthday.split("/")[0])
        day = string.atoi(birthday.split("/")[1])

        # Get current year
        year = time.ctime()[-4:]
        year = string.atoi(year)

        # Calculate the "end date" for the all day event
        start_time = datetime.date(year, month, day)
        one_day = datetime.timedelta(days=1)
        end_time = start_time + one_day

        start_time_str = start_time.strftime("%Y-%m-%d")
        end_time_str = end_time.strftime("%Y-%m-%d")

        # Create yearly recurrence rule
        recurrence_data = (
            "DTSTART;VALUE=DATE:%s\r\n"
            "DTEND;VALUE=DATE:%s\r\n"
            "RRULE:FREQ=YEARLY;WKST=SU\r\n" %
            (start_time.strftime("%Y%m%d"), end_time.strftime("%Y%m%d")))

        web_rel = "http://schemas.google.com/gCal/2005/webContent"
        icon_href = "http://www.perstephanie.com/images/birthdayicon.gif"
        icon_type = "image/gif"
        extension_text = (
            'gCal:webContent xmlns:gCal="http://schemas.google.com/gCal/2005"'
            ' url="%s" width="300" height="225"' % (photo_url))

        event = gdata.calendar.CalendarEventEntry()
        event.title = atom.Title(text=title)
        event.content = atom.Content(text=content)
        event.recurrence = gdata.calendar.Recurrence(text=recurrence_data)
        event.when.append(
            gdata.calendar.When(start_time=start_time_str,
                                end_time=end_time_str))

        # Adding the webContent specific XML
        event.link.append(
            atom.Link(rel=web_rel,
                      title=title,
                      href=icon_href,
                      link_type=icon_type))
        event.link[0].extension_elements.append(
            atom.ExtensionElement(extension_text))

        return event
Exemple #7
0
    def post_videos(self,
                    paths,
                    category,
                    title=None,
                    desc=None,
                    tags=None,
                    devtags=None,
                    access=None):
        """Post video(s) to YouTube.

    Keyword arguments:
      paths: List of paths to videos.
      category: YouTube category for the video.
      title: Title of the video. (Default is the filename of the video).
      desc: Video summary (Default None).
      tags: Tags of the video as a string, separated by commas (Default None).
      devtags: Developer tags for the video (Default None).
      access: 'private' or 'unlisted', anything else = 'public'

    """
        from gdata.media import Group, Title, Description, Keywords, Private
        if isinstance(paths, basestring):
            paths = [paths]

        if access is None:
            access = 'public'

        access = access.lower()
        private = None
        if access == 'private':
            private = Private()

        for path in paths:
            filename = os.path.basename(path).split('.')[0]
            my_media_group = Group(
                title=Title(text=title or filename),
                description=Description(text=desc or 'A video'),
                keywords=Keywords(text=tags),
                category=build_category(category),
                private=private)

            if access == 'unlisted':
                extension_elements = [
                    atom.ExtensionElement(
                        'accessControl',
                        namespace=gdata.media.YOUTUBE_NAMESPACE,
                        attributes={
                            'action': 'list',
                            'permission': 'denied'
                        })
                ]
                video_entry = gdata.youtube.YouTubeVideoEntry(
                    media=my_media_group,
                    extension_elements=extension_elements)
            else:
                video_entry = gdata.youtube.YouTubeVideoEntry(
                    media=my_media_group)

            if devtags:
                taglist = devtags.replace(', ', ',')
                taglist = taglist.split(',')
                video_entry.AddDeveloperTags(taglist)
            LOG.info(safe_encode('Loading ' + path))
            try:
                entry = self.InsertVideoEntry(video_entry, path)
            except gdata.service.RequestError, err:
                LOG.error('Failed to upload video: %s' % err)
            except gdata.youtube.service.YouTubeError, err:
                err_str = str(err)
                if err_str.find('path name or a file-like object') != -1:
                    err_str = safe_encode('Could not find file ' + path)
                if (err.args[0]['body'].find('invalid_value') != -1
                        and err.args[0]['body'].find('media:category') != -1):
                    err_str = 'Invalid category: %s' % category
                    err_str += (
                        '\nFor a list of valid categories, see '
                        'http://code.google.com/p/googlecl/wiki/Manual#YouTube'
                    )
                LOG.error(err_str)