Beispiel #1
0
    def __init__(self, entry=None, title=None, dataverse=None, edit_uri=None,
                 edit_media_uri=None, statement_uri=None, **kwargs):

        # Generate sword entry
        sword_entry = sword2.Entry(entry)
        if not get_elements(sword_entry.pretty_print(), namespace='dcterms', tag='title'):
            # Append title to entry
            if isinstance(title, basestring):
                sword_entry.add_field(format_term('title'), title)
            else:
                raise DataverseException('Study needs a single, valid title.')
        if kwargs:
            # Updates sword entry from keyword arguments
            for k in kwargs.keys():
                if isinstance(kwargs[k], list):
                    for item in kwargs[k]:
                        sword_entry.add_field(format_term(k), item)
                else:
                    sword_entry.add_field(format_term(k), kwargs[k])

        self.entry = sword_entry.pretty_print()
        self.dataverse = dataverse

        self.edit_uri = edit_uri
        self.edit_media_uri = edit_media_uri
        self.statement_uri = statement_uri
Beispiel #2
0
def imagevenue(url, name, dest, delim, digits, number):
    print "Downloading images from [imagevenue]...\n"

    links = get_page_links(url, lambda x: "imagevenue.com" in x)

    regex_base_url = re.compile(r'.*imagevenue.com', re.IGNORECASE)
    regex_ext = re.compile(r'\.[a-zA-Z]*$', re.IGNORECASE)

    for link in links:
        try:
            # source image (i.e. "Open image in a new tab")
            img = get_elements(link, "img#thepic")

            base_url_match = regex_base_url.search(link)
            if base_url_match and img is not []:
                # image name and filetype
                img_url = img[0]['src']
                ext = regex_ext.search(img_url).group(0)

                # image URL and output filename
                new_name = set_name(name, ext, delim, number, digits)
                image_url = "{0}/{1}".format(base_url_match.group(0), img_url)

                # download
                download_file(image_url, new_name, dest, number)
                number += 1
        except:
            pass
Beispiel #3
0
    def get_dataverses(self, refresh=False):
        collections = get_elements(
            self.get_service_document(refresh)[0],
            tag='collection',
        )

        return [Dataverse(self, col) for col in collections]
Beispiel #4
0
def imgur(url, name, dest, delim, digits, number):
    print "Downloading images from [imgur]...\n"

    if not str.endswith(url, "/layout/blog"):
        url += "/layout/blog"

    links = [div.a.get('href') for div in get_elements(
        url, "div.item.view.album-view-image-link")]

    regex = re.compile(r'\.com/\w*(\.[a-zA-Z]*)$', re.IGNORECASE)

    for link in links:
        try:
            # image URL and filetype
            image_url = "http://" + link[2:]
            ext = regex.search(image_url).group(1)

            # output filename
            new_name = set_name(name, ext, delim, number, digits)

            # download
            download_file(image_url, new_name, dest, number)
            number += 1
        except:
            pass
Beispiel #5
0
def imagevenue(url, name, dest, delim, digits, number):
    print "Downloading images from [imagevenue]...\n"

    links = get_page_links(url, lambda x: "imagevenue.com" in x)

    regex_base_url = re.compile(r'.*imagevenue.com', re.IGNORECASE)
    regex_ext = re.compile(r'\.[a-zA-Z]*$', re.IGNORECASE)

    for link in links:
        try:
            # source image (i.e. "Open image in a new tab")
            img = get_elements(link, "img#thepic")

            base_url_match = regex_base_url.search(link)
            if base_url_match and img is not []:
                # image name and filetype
                img_url = img[0]['src']
                ext = regex_ext.search(img_url).group(0)

                # image URL and output filename
                new_name = set_name(name, ext, delim, number, digits)
                image_url = "{0}/{1}".format(base_url_match.group(0), img_url)

                # download
                download_file(image_url, new_name, dest, number)
                number += 1
        except:
            pass
    def get_dataverses(self, refresh=False):
        collections = get_elements(
            self.get_service_document(refresh)[0],
            tag='collection',
        )

        return [Dataverse(self, col) for col in collections]
    def get_datasets(self):

        collection_info = requests.get(
            self.collection.get('href'),
            auth=self.connection.auth,
        ).content

        entries = get_elements(collection_info, tag='entry')
        return [Dataset.from_dataverse(entry, self) for entry in entries]
Beispiel #8
0
def imagebam(url, name, dest, delim, digits, number):
    print "Downloading images from [imagebam]...\n"

    # gallery page numbers (ascending)
    page_count = [int(el.contents[0])
                  for el in get_elements(url, "a.pagination_link")]

    if page_count:
        # multi-page gallery
        links = get_imagebam_htmlcode_links(url, page_count[-1])
    else:
        # single-page gallery
        links = get_page_links(url, lambda x: "imagebam.com" in x)

    # remove any duplicate links
    links = list(unique_everseen(links))

    regex = re.compile(r'\.[a-zA-Z]*$', re.IGNORECASE)

    for link in links:
        try:
            # source image (i.e. "Open image in a new tab")
            src = [el['src']
                   for el in get_elements(link, 'img')
                   if 'id' in el.attrs]
            if len(src) > 0:
                # image URL
                image_url = src[0]

                # filetype
                ext = regex.search(image_url)
                if ext is None:
                    ext = ".jpg"
                else:
                    ext = ext.group(0)

                # output filename
                new_name = set_name(name, ext, delim, number, digits)

                # download
                download_file(image_url, new_name, dest, number)
                number += 1
        except:
            pass
Beispiel #9
0
def imagebam(url, name, dest, delim, digits, number):
    print "Downloading images from [imagebam]...\n"

    # gallery page numbers (ascending)
    page_count = [int(el.contents[0])
                  for el in get_elements(url, "a.pagination_link")]

    if page_count:
        # multi-page gallery
        links = get_imagebam_htmlcode_links(url, page_count[-1])
    else:
        # single-page gallery
        links = get_page_links(url, lambda x: "imagebam.com" in x)

    # remove any duplicate links
    links = list(unique_everseen(links))

    regex = re.compile(r'\.[a-zA-Z]*$', re.IGNORECASE)

    for link in links:
        try:
            # source image (i.e. "Open image in a new tab")
            src = [el['src']
                   for el in get_elements(link, 'img')
                   if 'id' in el.attrs]
            if len(src) > 0:
                # image URL
                image_url = src[0]

                # filetype
                ext = regex.search(image_url)
                if ext is None:
                    ext = ".jpg"
                else:
                    ext = ext.group(0)

                # output filename
                new_name = set_name(name, ext, delim, number, digits)

                # download
                download_file(image_url, new_name, dest, number)
                number += 1
        except:
            pass
Beispiel #10
0
def imgbox(url, name, dest, delim, digits, number):
    print "Downloading images from [imgbox]...\n"

    links = ['https://imgbox.com/' + el['href']
             for el in get_elements(url, '#gallery-view-content a')]

    regex = re.compile(r'(\.[a-zA-Z]*)$', re.IGNORECASE)

    for link in links:
        try:
            image_url = [el['src'] for el in get_elements(link, '#img')][0]
            ext = regex.search(image_url).group(1)

            new_name = set_name(name, ext, delim, number, digits)

            download_file(image_url, new_name, dest, number)
            number += 1
        except:
            pass
Beispiel #11
0
 def get_studies(self):
     studiesResponse = self.connection.swordConnection.get_resource(self.collection.href)
     
     # get all the entry nodes and parse them into study objects
     studies = []
     for element in utils.get_elements(studiesResponse.content, tag="entry"):
         s = Study.CreateStudyFromEntryElement(element, hostDataverse=self)
         studies.append(s)
         
     return studies
    def get_dataverses(self, refresh=False):
        if refresh:
            self.connect()

        collections = get_elements(
            self.service_document[0],
            tag="collection",
        )
        
        return [Dataverse(self, col) for col in collections]
Beispiel #13
0
 def CreateFromAtomEntry(cls, atomXml, hostStudy):
     url = utils.get_elements(atomXml, 
                                tag="id", 
                                numberOfElements=1).text
     
     name = url.rsplit("/")[-1]
     editMediaUri = url
     
     contentType = utils.get_elements(atomXml, 
                                tag="content", 
                                numberOfElements=1).get("type")
     mimetype = mimetypes.guess_type(contentType)
     
     
     
     updatedString = utils.get_elements(atomXml, 
                       tag="updated", 
                       numberOfElements=1).text
     updated = datetime.utcfromtimestamp(updatedString)
     return cls(name, editMediaUri, mimetype, updated, hostStudy)
Beispiel #14
0
 def get_statement(self):
     if not self.statementUri:
         atomXml = self.get_entry()
         statementLink = utils.get_elements(atomXml, 
                                            tag="link", 
                                            attribute="rel", 
                                            attributeValue="http://purl.org/net/sword/terms/statement", 
                                            numberOfElements=1)
         self.statementUri = statementLink.get("href")
     
     studyStatement = self.hostDataverse.connection.swordConnection.get_resource(self.statementUri).content
     return studyStatement
Beispiel #15
0
    def get_released_files(self):
        """
        Uses data sharing API to retrieve a list of files from the most
        recently released version of the study
        """
        metadata_url = 'https://{0}/dvn/api/metadata/{1}'.format(
            self.dataverse.connection.host, self.doi
        )
        xml = requests.get(metadata_url, verify=False).content
        elements = get_elements(xml, tag='otherMat')

        return [DataverseFile.from_metadata(element, self)
                for element in elements]
Beispiel #16
0
    def CreateStudyFromEntryElement(cls, entryElement, hostDataverse=None):
        idElement = utils.get_elements(entryElement, 
                                       tag="id", 
                                       numberOfElements=1)
                                    
        titleElement = utils.get_elements(entryElement, 
                                       tag="title", 
                                       numberOfElements=1)
                                            
        editMediaLinkElement = utils.get_elements(entryElement, 
                                                  tag="link", 
                                                  attribute="rel", 
                                                  attributeValue="edit-media", 
                                                  numberOfElements=1)

        editMediaLink = editMediaLinkElement.get("href") if editMediaLinkElement is not None else None

        return cls(idElement.text,     
                   titleElement.text,        
                   editUri=entryElement.base,   # edit iri
                   editMediaUri=editMediaLink,
                   hostDataverse=hostDataverse)  # edit-media iri
Beispiel #17
0
    def get_files(self):
        atomXml = self.get_entry()
        statementLink = utils.get_elements(atomXml, 
                                           tag="link", 
                                           attribute="rel", 
                                           attributeValue="http://purl.org/net/sword/terms/statement", 
                                           numberOfElements=1)
        studyStatementLink = statementLink.get("href")

        atomStatement = self.hostDataverse.connection.swordConnection.get_atom_sword_statement(studyStatementLink)
        
        files = []
        for res in atomStatement.resources:
            f = DvnFile.CreateFromAtomStatementObject(res, self)
            files.append(f)
        
        return files
Beispiel #18
0
def imgur(url, name, dest, delim, digits, number):
    print "Downloading images from [imgur]...\n"

    links = ['https:' + el['src']
             for el in get_elements(url, '.post-image-placeholder, .post-image img')]

    regex = re.compile(r'\.com/\w*(\.[a-zA-Z]*)$', re.IGNORECASE)

    for image_url in links:
        try:
            # filetype
            ext = regex.search(image_url).group(1)

            # output filename
            new_name = set_name(name, ext, delim, number, digits)

            # download
            download_file(image_url, new_name, dest, number)
            number += 1
        except:
            pass
Beispiel #19
0
def imgbox(url, name, dest, delim, digits, number):
    print "Downloading images from [imgbox]...\n"

    links = [el['src']
             for el in get_elements(url, '#gallery-view-content img')]

    regex = re.compile(r'\.com/(\w*)(\.[a-zA-Z]*)$', re.IGNORECASE)

    for link in links:
        try:
            # image name and filetype
            match = regex.search(link)
            image, ext = match.group(1), match.group(2)

            # image URL and output filename
            image_url = "http://i.imgbox.com/" + image
            new_name = set_name(name, ext, delim, number, digits)

            # download
            download_file(image_url, new_name, dest, number)
            number += 1
        except:
            pass
Beispiel #20
0
 def get_state(self):
     return utils.get_elements(self.get_statement(), tag="category", attribute="term", attributeValue="latestVersionState", numberOfElements=1).text
Beispiel #21
0
 def get_citation(self):
     return utils.get_elements(self.get_entry(), namespace="http://purl.org/dc/terms/", tag="bibliographicCitation", numberOfElements=1).text
 def get_studies(self):
     response = self.connection.sword.get_resource(self.collection.href)
     entries = utils.get_elements(response.content, tag='entry')
     return [Study.from_entry(entry, dataverse=self) for entry in entries]
        ax = pylab.subplot(111)
        pylab.grid(True)

        pylab.plot(P1[0], P1[1], "go", P2[0], P2[1], "ro")

        ax.set_title("Total cost: %s" % COST)

        for l in LINES:
            pylab.plot((l[0][0], l[1][0]), (l[0][1], l[1][1]), "k-")

        pylab.show()

    a = SC(r_outer=2)
    sampls = 30

    imgs = get_elements("test.png")

    points1, t1 = get_points_from_img("9M.png", simpleto=sampls)
    P = a.compute(points1)
    x1 = [p[0] for p in points1]
    y1 = [400 - p[1] for p in points1]

    for i, img in enumerate(imgs):
        cv.ShowImage("Preview - %s" % i, img)
        cv.WaitKey()
    sys.exit()

    for img in imgs:

        cv.ShowImage("Preview2", img)
        cv.WaitKey()
 def get_datasets(self, refresh=False):
     collection_info = self.get_collection_info(refresh)
     entries = get_elements(collection_info, tag='entry')
     return [Dataset.from_dataverse(entry, self) for entry in entries]
Beispiel #25
0
        ax = pylab.subplot(111)
        pylab.grid(True)
        
        pylab.plot(P1[0],P1[1],'go',P2[0],P2[1],'ro')
        
        ax.set_title('Total cost: %s' % COST)       
        
        for l in LINES:     
            pylab.plot((l[0][0],l[1][0]),(l[0][1],l[1][1]), 'k-')
        
        pylab.show()

    a = SC()
    sampls = 100

    imgs = get_elements('test.png')

    points = get_points_from_img('9M2.png',simpleto=sampls)
    P = a.compute(points)
    x1 = [p[0] for p in points]
    y1 = [400-p[1] for p in points]
        
    for img in imgs:
    
        points2 = get_points_from_img(img,simpleto=sampls)
        
        if points2:
            Q = a.compute(points2)
            x2 = [p[0] for p in points2]
            y2 = [400-p[1] for p in points2]
            
Beispiel #26
0
 def CreateStudyFromAtomEntryXmlString(cls, xml):
     title = utils.get_elements(xml, tag="title", numberOfElements=1).text
     
     return cls(title, atomEntryXml=xml)
 def get_studies(self):
     response = self.connection.sword.get_resource(self.collection.href)
     entries = utils.get_elements(response.content, tag='entry')
     return [Study.from_entry(entry, dataverse=self) for entry in entries]
        ax = pylab.subplot(111)
        pylab.grid(True)

        pylab.plot(P1[0],P1[1],'go',P2[0],P2[1],'ro')

        ax.set_title('Total cost: %s' % COST)

        for l in LINES:
            pylab.plot((l[0][0],l[1][0]),(l[0][1],l[1][1]), 'k-')

        pylab.show()

    a = SC(r_outer=2)
    sampls = 30

    imgs = get_elements('test.png')

    points1,t1 = get_points_from_img('9M.png',simpleto=sampls)
    P = a.compute(points1)
    x1 = [p[0] for p in points1]
    y1 = [400-p[1] for p in points1]

    for i,img in enumerate(imgs):
        cv.imshow('Preview - %s' % i,img)
        cv.waitKey(0)
    sys.exit()

    for img in imgs:

        cv.imshow('Preview2',img)
        cv.waitKey(0)
Beispiel #29
0
db = tango.Database()

# Setup
pool = sys.argv[1]
pool_server = "Pool/{}".format(pool)
pool_name = db.get_device_name(pool_server, "Pool")[0]
logging.info("Pool: {}".format(pool))
logging.info("Server: {}".format(pool_server))
logging.info("Pool device: {}".format(pool_name))
ms_server = "MacroServer/{}".format(pool)
ms_name = db.get_device_name(ms_server, "MacroServer")[0]
logging.info("MacroServer: {}".format(ms_server))
logging.info("MacroServer device: {}".format(ms_name))

# Prepare environment
elements = get_elements(pool, db)
ms_elements = get_ms_elements(pool, db)
print("controller/endstationmanipulator/a_ea01_mpb_01_ctrl" in elements)
# Generate mapping
aliases = generate_aliases_mapping(elements, db)
ids = generate_id_mapping(elements, db)
ctrl_ids = generate_prop_mapping(elements, db, "ctrl_id")
motor_ids = generate_prop_mapping(elements, db, "motor_role_ids")
pseudo_ids = generate_prop_mapping(elements, db, "pseudo_motor_role_ids")
channel_ids = generate_prop_mapping(elements, db, "elements")
instrument_list = generate_instrument_list(pool_name, db)
instrument_ids = generate_instrument_mapping(instrument_list)

# Class mapping
classes = generate_class_mapping(elements, db)
classes_ms = generate_class_mapping(ms_elements, db)
Beispiel #30
0
 def is_released(self):
      collectionInfo = self.connection.swordConnection.get_resource(self.collection.href).content
      status = utils.get_elements(collectionInfo, namespace="http://purl.org/net/sword/terms/state", tag="dataverseHasBeenReleased", numberOfElements=1).text
      return bool(status)