示例#1
0
def create_thumbnails():

    itemIDS = zotero.get_item_ids()

    for itemID in itemIDS:
        try:
            filepath = zotero.get_attachment(itemID)
            logger.debug("Creating thumbnail %s" % filepath)
            print "thumbnail %s" % filepath

            path, filename = os.path.split(filepath)

            if filepath.endswith('.pdf'):

                pwd = os.getcwd()
                os.chdir(path)
                p = Popen(" ".join([
                    IMAGEMAGICK, '-verbose -density 150  -quality 100  -trim',
                    '\"%s\"[0]' % filename, "filecover.jpeg"
                ]),
                          shell=True)
                p.wait()
                os.chdir(pwd)
        except Exception as err:
            print err, err.args, err.__class__
示例#2
0
def item_data_html(itemid):
    """
    Returns item data in html format

    """
    data = zotero.get_item_data(itemid)
    logger.debug("data = %s" % data)

    print "data ", data

    # Get attachment file
    #------------------------------------------------------------
    attachment = zotero.get_attachment(itemid)
    if attachment is None:
        attachment_url = ""
        attachment_row = ""
    else:
        attachment_url = attachment_link(attachment, "Attachment")
        #attachment_url = link_tpl(label="Attachment", url='/attachment/%s' % itemid)
        attachment_row = _attachment_row.format(attachment=attachment_url)

    # Get item tags url
    #------------------------------------------------------------
    item_tags = zotero.get_item_tags(itemid)
    item_tag_links = [
        link_tpl("/tagid/%s" % tagid, tagname) for tagid, tagname in item_tags
    ]

    if item_tag_links:

        item_tag_links = " ".join(item_tag_links)
        tag_row = _row_tpl.format(label="Tag", value=item_tag_links)

    else:
        tag_row = ""

    #  Get Image thumbnail
    #------------------------------------------------------------
    image = thumbnail_html(itemid)
    image_row = _image_row_tpl.format(image=image)

    #  Get Item Metadata
    #------------------------------------------------------------
    try:
        Title = data['title']
    except:
        Title = attachment

    content = ""

    for label, attribute in attributes:
        content = "".join([content, row_tpl(label, attribute, data)])

    content = "".join([content, tag_row, attachment_row, image_row])

    table = table_tpl.format(id=itemid, content=content, title=Title)

    return table
示例#3
0
def item_data_html(itemid):
    """
    Returns item data in html format

    """
    data = zotero.get_item_data(itemid)
    logger.debug("data = %s" % data)

    print "data ", data

    # Get attachment file
    #------------------------------------------------------------
    attachment = zotero.get_attachment(itemid)
    if attachment is None:
        attachment_url = ""
        attachment_row = ""
    else:
        attachment_url = attachment_link(attachment, "Attachment")
        #attachment_url = link_tpl(label="Attachment", url='/attachment/%s' % itemid)
        attachment_row = _attachment_row.format(attachment=attachment_url)


    # Get item tags url
    #------------------------------------------------------------
    item_tags = zotero.get_item_tags(itemid)
    item_tag_links = [link_tpl("/tagid/%s" % tagid, tagname) for tagid, tagname in item_tags]

    if item_tag_links:

       item_tag_links = " ".join(item_tag_links)
       tag_row = _row_tpl.format(label="Tag", value=item_tag_links)

    else:
        tag_row = ""

    #  Get Image thumbnail
    #------------------------------------------------------------
    image = thumbnail_html(itemid)
    image_row = _image_row_tpl.format(image=image)

    #  Get Item Metadata
    #------------------------------------------------------------
    try:
        Title = data['title']
    except:
        Title = attachment

    content = ""

    for label, attribute in attributes:
        content = "".join([content, row_tpl(label, attribute, data)])

    content = "".join([content, tag_row, attachment_row, image_row])

    table = table_tpl.format(id=itemid, content=content, title=Title)

    return table
示例#4
0
def get_item_link(item_filename):
    """
    Returns a html link to the file, given the fileID

    """
    # Get item attachment path

    path = item_filename #zotero.get_attachment(itemid)
    logger.debug("path = %s" % path)

    if path is not None:
        # path = os.path.join("/files", path)
        # path = "/files" + path

        #name = os.path.split(path)[1]
        link = attachment_link(path, "Attachment", newtab=True)
        # print link
        # link = '<a href="' + path + '">' + "file" + "</a>"
        return link

    return None
示例#5
0
def get_item_link(item_filename):
    """
    Returns a html link to the file, given the fileID

    """
    # Get item attachment path

    path = item_filename  #zotero.get_attachment(itemid)
    logger.debug("path = %s" % path)

    if path is not None:
        # path = os.path.join("/files", path)
        # path = "/files" + path

        #name = os.path.split(path)[1]
        link = attachment_link(path, "Attachment", newtab=True)
        # print link
        # link = '<a href="' + path + '">' + "file" + "</a>"
        return link

    return None
示例#6
0
def route_collectionid(collid):
    # Find all subcollections from a given collecion
    # which  collID is known.
    #
    # subcollections =  [ ( collIDx, collNameX ), ( ....) ... ]
    #
    logger.warn("ROUTE: /collectionid/<collid:int> = %s" % collid )

    subcollections = zotero.get_subcollections(collid)
    html_subcolls = html_collections_link(subcollections)

    collname = zotero.get_collection_name(collid)

    items = zotero.get_item_from_collections(collid)

    html_items = html_item_link_list(items)

    html = html_subcolls + "<br \><br />"# + '\n<hr width=35% color="black" align="left" >\n'
    html = html + html_items

    logger.debug("collname = %s" % collname)
    logger.debug("items = %s" % items)
    logger.debug("html_items %s" %html_items )

    subtilte_ = "Collection: " + collname
    return template(base_template, subtitle=subtilte_, content=html, backlink="collections")
示例#7
0
def route_collectionid(collid):
    # Find all subcollections from a given collecion
    # which  collID is known.
    #
    # subcollections =  [ ( collIDx, collNameX ), ( ....) ... ]
    #
    logger.warn("ROUTE: /collectionid/<collid:int> = %s" % collid)

    subcollections = zotero.get_subcollections(collid)
    html_subcolls = html_collections_link(subcollections)

    collname = zotero.get_collection_name(collid)

    items = zotero.get_item_from_collections(collid)

    html_items = html_item_link_list(items)

    html = html_subcolls + "<br \><br />"  # + '\n<hr width=35% color="black" align="left" >\n'
    html = html + html_items

    logger.debug("collname = %s" % collname)
    logger.debug("items = %s" % items)
    logger.debug("html_items %s" % html_items)

    subtilte_ = "Collection: " + collname
    return template(base_template,
                    subtitle=subtilte_,
                    content=html,
                    backlink="collections")
示例#8
0
def attachment_link(path, name, newtab=True):
    """
    Create html link code to URL
    Returns the html code to the link

    linktofile = False : Link to any page
               = True  : Link to Internal file

    newtab     = False : Open the links in same tab/window
                 True  : Force to open links in new tab
    """

    url = os.path.join("/library/", os.path.relpath(path, zotero.storage))
    logger.debug("url = %s" % url)

    targ = ""
    if newtab == True:
        targ = ' target="_blank" '

    link = "".join(['<a href="', url, '"', targ, '>', name, '</a>'])
    logger.debug("link = %s" % link)
    return link
示例#9
0
def create_thumbnails():

    itemIDS = zotero.get_item_ids()


    for itemID in itemIDS:
        try:
            filepath = zotero.get_attachment(itemID)
            logger.debug("Creating thumbnail %s" % filepath)
            print "thumbnail %s" % filepath

            path, filename = os.path.split(filepath)

            if filepath.endswith('.pdf'):

                pwd = os.getcwd()
                os.chdir(path)
                p = Popen(" ".join([IMAGEMAGICK, '-verbose -density 150  -quality 100  -trim', '\"%s\"[0]' % filename, "filecover.jpeg"]), shell=True)
                p.wait()
                os.chdir(pwd)
        except Exception as err:
            print err, err.args, err.__class__
示例#10
0
def attachment_link(path, name, newtab=True):
    """
    Create html link code to URL
    Returns the html code to the link

    linktofile = False : Link to any page
               = True  : Link to Internal file

    newtab     = False : Open the links in same tab/window
                 True  : Force to open links in new tab
    """

    url = os.path.join("/library/", os.path.relpath(path, zotero.storage))
    logger.debug("url = %s" % url)

    targ = ""
    if newtab == True:
        targ = ' target="_blank" '

    link = "".join(['<a href="', url, '"', targ, '>', name, '</a>'])
    logger.debug("link = %s" % link)
    return link
示例#11
0
def route_library(path):

    logger.warn("ROUTE: /files = %s" % path)

    _path = os.path.join(zotero.storage, path)

    if os.path.isfile(_path):
        path_, file_ = os.path.split(_path)

        logger.debug("path_ = %s" % path_)
        logger.debug("file_ = %s" % file_)

        return static_file(file_, path_)
    else:
        logger.debug("Error: File don't exist on server.")
        return "Error: File don't exist on server."
示例#12
0
def route_library(path):


    logger.warn("ROUTE: /files = %s" % path)

    _path = os.path.join(zotero.storage, path)

    if os.path.isfile(_path):
        path_, file_ = os.path.split(_path)

        logger.debug("path_ = %s" % path_)
        logger.debug("file_ = %s" % file_)

        return static_file(file_, path_)
    else:
        logger.debug("Error: File don't exist on server.")
        return "Error: File don't exist on server."
示例#13
0
def route_fileid(itemid):
    """
    Retrives file that matches itemid

    """
    logger.warn("ROUTE: /fileid = %s" % itemid)
    path = zotero.get_attachment(itemid)
    logger.debug("path = %s" % path)

    if path is not None:
        path_, file_ = os.path.split(path)

        logger.debug("path_ = %s" % path_)
        logger.debug("file_ = %s" % file_)

        return static_file(file_, path_, download=file_)
    # return "File was  " + str(itemid) + " " + path
    else:
        return "Error: File not found"
示例#14
0
def route_fileid(itemid):
    """
    Retrives file that matches itemid

    """
    logger.warn("ROUTE: /fileid = %s" % itemid)
    path = zotero.get_attachment(itemid)
    logger.debug("path = %s" % path)

    if path is not None:
        path_, file_ = os.path.split(path)

        logger.debug("path_ = %s" % path_)
        logger.debug("file_ = %s" % file_)

        return static_file(file_, path_, download=file_)
    # return "File was  " + str(itemid) + " " + path
    else:
        return "Error: File not found"