Пример #1
0
def make_html(pixdir, route_name, results):

    title = "Pictures from %s" % route_name

    document = dominate.document(title=title)

    with document.head:
        meta(charset="UTF-8")
        style("""
        table { page-break-inside:auto; border-spacing:3px; padding:3px; }
        table { margin-left:auto; margin-right:auto; }
        table, td, th, tr { border:1px solid green; }
        th { background-color: green; color: white; }
        th.tiny { width:3%; }
        th.narrow { width:47%; }
        th.wide { width:50%; }
        tr { page-break-inside:avoid; page-break-after:auto; }
        tr.center { margin-left:auto; margin-right:auto; }
        tr.alt { background-color: #f0f0f0; }
        caption { background-color: #c0c040; font-size: 16px; \
font-family: "Courier New"; }
        body { font-size: 16px; }
        @media print {
            body { font-size: 8px; font-family: "Courier New" }
            caption { font-size: 10px }
            a {
            text-decoration: none; font-style: italic; font-weight: bold}
            th { background-color: white; color: black; }
        }
        """)

    with document.body:

        with table():

            caption(route_name)

            tr(th("Name"), th("Description"), th("Imagefile"))

            for time, filename, gc, tp in results:

                pathname = os.path.join(pixdir, filename)

                gcname, gcdesc = map(str, gc[1:])
                gclink = "http://coord.info/%s" % quote(gcname)

                with tr():

                    td(a(gcname, href=gclink))
                    td(gcdesc)
                    td(a(filename, href=quote(pathname)))

    print >> open("make_html.html", "w"), document
Пример #2
0
    def write_table(self):
        """
        |write_table| with HTML table format.

        :Example:
            :ref:`example-html-table-writer`

        .. note::
            - |None| is not written
        """

        self._logger.logging_start_write()

        self._verify_property()
        self._preprocess()

        if typepy.is_not_null_string(self.table_name):
            self._table_tag = tags.table(
                id=pathvalidate.sanitize_python_var_name(self.table_name))
            self._table_tag += tags.caption(
                MultiByteStrDecoder(self.table_name).unicode_str)
        else:
            self._table_tag = tags.table()

        try:
            self._write_header()
        except EmptyHeaderError:
            pass

        self._write_body()

        self._logger.logging_complete_write()
Пример #3
0
    def write_table(self, **kwargs) -> None:
        """
        |write_table| with HTML table format.

        Args:
            write_css (bool):
                If |True|, write CSS corresponding to the specified styles,
                instead of attributes of HTML tags.

        Example:
            :ref:`example-html-table-writer`

        .. note::
            - |None| values will be replaced with an empty value
        """

        tags, raw = _get_tags_module()
        write_css = kwargs.get("write_css", False)

        with self._logger:
            try:
                self._verify_property()
            except EmptyTableDataError:
                self._logger.logger.debug("no tabular data found")
                return

            self._preprocess()

            css_class = None

            if write_css:
                css_class = kwargs.get(
                    "css_class",
                    "{}-css".format(
                        replace_symbol(self.table_name, replacement_text="-")),
                )

                css_writer = CssTableWriter(table_name=css_class)
                css_writer.from_writer(self, is_overwrite_table_name=False)
                css_writer.write_table(write_style_tag=True)

            if typepy.is_not_null_string(self.table_name):
                if css_class:
                    self._table_tag = tags.table(id=sanitize_python_var_name(
                        self.table_name),
                                                 class_name=css_class)
                else:
                    self._table_tag = tags.table(
                        id=sanitize_python_var_name(self.table_name))
                self._table_tag += tags.caption(
                    MultiByteStrDecoder(self.table_name).unicode_str)
            else:
                self._table_tag = tags.table()

            try:
                self._write_header()
            except ValueError:
                pass

            self._write_body(not write_css)
Пример #4
0
    def write_table(self):
        """
        |write_table| with HTML table format.

        :Example:
            :ref:`example-html-table-writer`

        .. note::
            - |None| is not written
        """

        tags = _get_tags_module()

        with self._logger:
            self._verify_property()
            self._preprocess()

            if typepy.is_not_null_string(self.table_name):
                self._table_tag = tags.table(id=sanitize_python_var_name(self.table_name))
                self._table_tag += tags.caption(MultiByteStrDecoder(self.table_name).unicode_str)
            else:
                self._table_tag = tags.table()

            try:
                self._write_header()
            except EmptyHeaderError:
                pass

            self._write_body()
Пример #5
0
    def write_table(self):
        """
        |write_table| with HTML table format.
        """

        self._verify_property()
        self._preprocess()

        if dataproperty.is_not_empty_string(self.table_name):
            self._table_tag = tags.table(
                id=pathvalidate.sanitize_python_var_name(self.table_name))
            self._table_tag += tags.caption(self.table_name)
        else:
            self._table_tag = tags.table()

        self._write_header()
        self._write_body()
Пример #6
0
    def write_table(self):
        """
        |write_table| with HTML table format.
        """

        self._verify_property()
        self._preprocess()

        if dataproperty.is_not_empty_string(self.table_name):
            self._table_tag = tags.table(
                id=pathvalidate.sanitize_python_var_name(self.table_name))
            self._table_tag += tags.caption(self.table_name)
        else:
            self._table_tag = tags.table()

        self._write_header()
        self._write_body()
Пример #7
0
def make_html(pixdir, route_name, results, debug=False):

    document = dominate.document(
        title="Pictures from %s" % route_name,
    )

    with document.head:
        meta(charset="UTF-8")
        style("""
            table { page-break-inside:auto; border-spacing:3px; padding:3px; }
            table { margin-left:auto; margin-right:auto; }
            table, td, th, tr { border:1px solid green; }
            th { background-color: green; color: white; }
            th.tiny { width:3%; }
            th.narrow { width:47%; }
            th.wide { width:50%; }
            tr { page-break-inside:avoid; page-break-after:auto; }
            tr.center { margin-left:auto; margin-right:auto; }
            tr.alt { background-color: #f0f0f0; }
            caption { background-color: #c0c040; \
font-size: 16px; \
font-family: "Courier New"; }
            td.center { text-align: center }
            body { font-size: 16px; }
            @media print {
                body { font-size: 8px; font-family: "Courier New" }
                caption { font-size: 10px }
                a {
                  text-decoration: none; font-style: italic; font-weight: bold
                }
                th { background-color: white; color: black; }
            }
        """)

    groups = []
    uniquekeys = []

    # return gcname from line in results
    def keyfunc(t):
        return t[2][1]

    # k is gcnumber
    for k, g in groupby(results, keyfunc):
        groups.append(list(g))
        uniquekeys.append(k)

    if debug:
        pprint(groups, sys.stderr, width=132)
        pprint(uniquekeys, sys.stderr, width=132)

    picture_table = table()
    picture_table.add(caption(route_name))
    with picture_table:

        # output the table header
        tr(
            th("GC Name"),
            th("Geocache Description"),
            th("Imagefile")
        )

        # group output fows by gcname_key
        for gcname_key, g in zip(uniquekeys, groups):

            # key gcname_key is gcname
            coord_info_url = "http://coord.info/%s" % gcname_key

#           groups.append(list(g))
#           uniquekeys.append(gcname_key)

            rowspan = len(g)
            first = True

            for time, filename, gc, tp in g:

                with tr():

                    distance, gcnumber, description = gc
                    lat, lon = tp

                    if rowspan == 1:
                        td(a(gcname_key, href=coord_info_url, target="_blank"))
                        td(description or "", cls="center")
                    elif first:
                        td(
                            a(gcname_key, href=coord_info_url,
                              target="_blank"),
                            rowspan=rowspan
                        )
                        td(description or "", rowspan=rowspan, cls="center")
                        first = False

                    td(a(filename, href=filename, target="_blank"))

    document += picture_table

    outfilename = os.path.join(pixdir, "make_html.html")
    print(document, file=open(outfilename, "w"))
    print("Output is in %s" % outfilename)
Пример #8
0
def create_rooter_document(gpxname):
    """Generate the HTML 'Rooter' output document.

    Create a HTML document from the information contained in the .gpx file
    named gpxname.
    """
    print("reading %s" % gpxname)

    wpts, latlon_dictionary = get_wpts(gpxname)

    _w0 = wpts[0]

    def make_wtag(_s):
        """Create a waypoint tag from _s."""
        return _w0.tag.replace("wpt", _s)

    rooter_document = document()

    rooter_document.head = tr(cls="center")
    rooter_document.head.add(th("Geocache", cls="wide"))
    rooter_document.head.add(th("Found By", cls="tiny"))
    rooter_document.head.add(th("Notes", cls="narrow"))

    html_table = table()
    html_table.add(caption("File: %s" % gpxname))
    html_table.add(rooter_document.head)

    # row counter for even/odd formatting
    row_number = 0

    for wpt in wpts:

        w_lat = wpt.attrib["lat"]
        w_lon = wpt.attrib["lon"]
        #       w_time = wpt.find(make_wtag("time")).text
        w_name = wpt.find(make_wtag("name")).text
        #       _w_cmt = wpt.find(make_wtag("cmt"))
        #       w_cmt = _w_cmt is not None and _w_cmt.text
        w_desc = wpt.find(make_wtag("desc")).text
        _w_link = wpt.find(make_wtag("link"))
        w_link_href = _w_link.attrib["href"]
        #       w_link_text = _w_link[0].text
        #       w_sym = wpt.find(make_wtag("sym")).text
        w_type = wpt.find(make_wtag("type")).text
        w_extensions = wpt.find(make_wtag("extensions"))

        if DEBUG:
            w_format = "%-20s = %-70s"

            print(w_format % ("lat", str(w_lat)))
            print(w_format % ("lon", str(w_lon)))
            #           print(w_format % ("time", w_time))
            print(w_format % ("name", w_name))
            #           print(w_format % ("cmt", w_cmt))
            print(w_format % ("desc", w_desc))
            print(w_format % ("link_href", w_link_href))
            #           print(w_format % ("link_text", w_link_text))
            #           print(w_format % ("sym", w_sym))
            print(w_format % ("type", w_type))
            print(w_format % ("extensions", w_extensions))

        _wpt_extension = w_extensions[0]
        _etag = _wpt_extension[0].tag

        def make_etag(_s):
            """Create an etag from _s."""
            return _etag.replace('UserFlag', _s)

        def get_ext(_s):
            """Docstring."""
            tag = make_etag(_s)
            _v = _wpt_extension.find(tag)
            if _v is not None:
                _v = _v.text
            if DEBUG:
                print("%s=%s" % (_s, _v))
            return _v

#       e_userflag = get_ext('UserFlag')
#       e_lock = get_ext('Lock')
#       e_dnf = get_ext('DNF')
#       e_watch = get_ext('Watch')
#       e_userdata = get_ext('UserData')

        e_lat_before_correct = get_ext('LatBeforeCorrect')
        e_lon_before_correct = get_ext('LonBeforeCorrect')
        #       e_firsttofind = get_ext('FirstToFind')
        e_user2 = get_ext('User2')
        #       e_user3 = get_ext('User3')
        #       e_user4 = get_ext('User4')
        #       e_county = get_ext('County')
        e_usersort = get_ext('UserSort')

        #       e_smartname = get_ext('SmartName')
        #       e_lastgpxdate = get_ext('LastGpxDate')
        #       e_code = get_ext('Code')
        #       e_resolution = get_ext('Resolution')
        #       e_ispremium = get_ext('IsPremium')
        #       e_favpoints = get_ext('FavPoints')
        #       e_gcnote = get_ext('GcNote')
        #       e_guid = get_ext('Guid')
        #       e_cacheimages = get_ext('CacheImages')
        #       e_logimages = get_ext('LogImages')
        #       e_customdata = get_ext('CustomData')

        ####
        def make_ctag(_s):
            """Create a ctag from _s."""
            return ctag.replace('name', _s)

        if len(w_extensions) > 1:
            _wpt_cache = w_extensions[1]

            ctag = _wpt_cache[0].tag

            def get_cext(_s):
                """Docstring."""
                tag = make_ctag(_s)
                _v = _wpt_cache.find(tag)
                if _v is not None:
                    _v = _v.text
                if DEBUG:
                    print("%s=%s" % (_s, _v))
                return _v
        else:

            def get_cext(_s):
                """Docstring."""
                return ""

        c_cache_id = _wpt_cache.attrib["id"]
        c_cache_available = _wpt_cache.attrib["available"]
        c_cache_archived = _wpt_cache.attrib["archived"]
        if DEBUG:
            print(c_cache_id,
                  c_cache_available,
                  c_cache_archived,
                  file=sys.stderr)

#       c_name = get_cext("name")
#       c_placed_by = get_cext("placed_by")
#       c_owner = get_cext("owner")
#       c_type = get_cext("type")
        c_container = get_cext("container")
        #       c_attributes = get_cext("attributes")
        #       c_difficulty = get_cext("difficulty")
        #       c_terrain = get_cext("terrain")
        #       c_country = get_cext("country")
        #       c_state = get_cext("state")
        #       c_short_description = get_cext("short_description")
        #       c_long_description = get_cext("long_description")
        c_encoded_hints = get_cext("encoded_hints")
        #       c_logs = _wpt_cache.find(make_ctag("logs"))
        #       c_travelbugs = get_cext("travelbugs")

        ####
        if not w_name.startswith("GC"):
            print("   skipping %s: '%s'" % (w_name, w_desc[:50]))
            continue

        if row_number % 2:
            row = tr(cls="alt")
        else:
            row = tr()
        row_number += 1

        gc_text = td()

        if e_usersort:
            gc_text += "%s: " % e_usersort
        gc_text += a(w_desc, href=w_link_href, target="_blank")
        gc_text += " (%s)" % w_name

        gc_text += br()
        if w_type:
            gc_text += "%s" % w_type.replace("Geocache|", "")
        if c_container:
            gc_text += ", %s" % c_container
#       if log_info:
#           gc_text += br()
#           gc_text += log_info

# don't publish coordinates for SKIPped geocaches
        if e_user2 is not None and e_user2.startswith("SKIP"):
            # try to locate the puzzle FINAl coordinates
            final_name = w_name.replace("GC", "FL")
            if final_name in latlon_dictionary:
                f_lat, f_lon = latlon_dictionary[final_name]
                #               gc_text += " FINAL=(%s, %s)" % (
                #                   degmin(f_lat, "NS"),
                #                   degmin(f_lon, "EW")
                #               )
                gc_text += " FINAL="
                gc_text.add(location_link(f_lat, f_lon))
            else:
                gc_text += " (ignoring published puzzle location)"
        else:
            # gc_text += " (%s, %s)" % (degmin(w_lat, "NS"),
            #                           degmin(w_lon, "EW"))
            gc_text += "  "
            gc_text.add(location_link(w_lat, w_lon))

            if not ((e_lat_before_correct is None) and
                    (e_lon_before_correct is None)):
                gc_text.add(" (Corrected)")

        if c_encoded_hints:
            gc_text += br()

            gc_em = em("Hint: ")
            for index, hint in enumerate(c_encoded_hints.split("\n")):
                if index:
                    gc_em.add(br())
                gc_em.add(hint)
            gc_text.add(gc_em)

        from latest_log import latest_log
        # get log information from wpt
        log_info = latest_log(wpt)
        #       "count": 0,
        #       "most_recent_find_date": "",
        #       "recent_log_types": [],
        #       "most_recent_log": "",
        if log_info["count"]:
            gc_text.add(br())
            gc_text.add("Log count: %d" % log_info["count"])
            gc_text.add(" '%s'" % ellipsis(
                "".join(x[0]
                        for x in log_info["recent_log_types"]), ELLIPSIS_MAX))
            gc_text.add(br())
            gc_text.add("Most recent log: '%s'" %
                        ellipsis(log_info["most_recent_log"], ELLIPSIS_MAX))

        row.add(gc_text)

        row.add(td())

        gc_text = ""
        if not c_cache_available == "True":
            gc_text += " CACHE NOT AVAILABLE !!"
        if not c_cache_archived == "False":
            gc_text += " CACHE ARCHIVED !!"
        row.add(td(gc_text))

        html_table.add(row)

    # create the rest of the HTML output file
    rooter_document = document(title="Rooter's HTML: %s" % gpxname)

    r_style = style(type="text/css")
    for line in STYLE.split("\n"):
        r_style.add("\n" + line)

    rooter_document.head.add(meta(charset="UTF-8"))
    rooter_document.head.add(r_style)

    r_body = rooter_document.body
    r_body.add(html_table)

    return rooter_document