Ejemplo n.º 1
0
    def render_tab(self, ctx):
        self.update_uptime()

        for website, status in self.website_status.iteritems():
            ctx.fg_color(Screen.WHITE).write_line(website)

            if status:
                ctx.fg_color(Screen.GREEN).write_line("UP").linebreak()
            else:
                ctx.fg_color(Screen.RED).write_line(
                    "DOWN for %s" %
                    format_timespan(int(time.time() -
                                        self.downtime[website]))).linebreak()
Ejemplo n.º 2
0
    def render_tab(self, ctx):
        self.update_stats()

        if self.error:
            ctx.fg_color(Screen.RED).write_line(str(self.error)).fg_color(
                Screen.WHITE)
            return

        ctx.bg_color(Screen.BLACK).fg_color(Screen.YELLOW).write_line(
            self.host.replace("http://", "")).linebreak()

        ctx.fg_color(Screen.WHITE).write("Connections: ")

        if self.connections < self.CONNECTION_YELLOW_THRESHOLD:
            ctx.fg_color(Screen.RED)
        elif self.connections >= self.CONNECTION_YELLOW_THRESHOLD and self.connections <= self.CONNECTION_GREEN_THRESHOLD:
            ctx.fg_color(Screen.YELLOW)
        else:
            ctx.fg_color(Screen.GREEN)

        ctx.write_line(str(self.connections))
        ctx.fg_color(Screen.WHITE).write("    inbound: ").fg_color(
            Screen.YELLOW).write_line(str(self.inbound))
        ctx.fg_color(Screen.WHITE).write("   outbound: ").fg_color(
            Screen.YELLOW).write_line(str(self.outbound)).linebreak()

        ctx.fg_color(Screen.WHITE).write("Blocks: ").fg_color(
            Screen.YELLOW).write_line(str(self.block_count))
        ctx.fg_color(Screen.WHITE).write("Unconf. tx: ").linebreak().fg_color(
            Screen.YELLOW).write(str(self.utx_count))

        current_time = int(time.time())
        time_since_start = current_time - self.utx_start_time

        if time_since_start != 0:
            tx_per_second = float(self.utx_count - self.utx_count_on_block
                                  ) / float(time_since_start)
        else:
            tx_per_second = 0.0

        time_since_block = current_time - self.last_block_time

        ctx.write_line(" (%.2f tx/s)" % tx_per_second).fg_color(Screen.WHITE)

        ctx.write_line("Time since block: ").fg_color(
            Screen.YELLOW).write_line(format_timespan(time_since_block))
Ejemplo n.º 3
0
 def render_tab(self, ctx):
     self.update_stats()
     
     if self.error:
         ctx.fg_color(Screen.RED).write_line(str(self.error)).fg_color(Screen.WHITE)
         return
     
     ctx.bg_color(Screen.BLACK).fg_color(Screen.YELLOW).write_line(self.host.replace("http://", "")).linebreak()
     
     ctx.fg_color(Screen.WHITE).write("Connections: ")
     
     if self.connections < self.CONNECTION_YELLOW_THRESHOLD:
         ctx.fg_color(Screen.RED)
     elif self.connections >= self.CONNECTION_YELLOW_THRESHOLD and self.connections <= self.CONNECTION_GREEN_THRESHOLD:
         ctx.fg_color(Screen.YELLOW)
     else:
         ctx.fg_color(Screen.GREEN)
     
     ctx.write_line(str(self.connections))
     ctx.fg_color(Screen.WHITE).write("    inbound: ").fg_color(Screen.YELLOW).write_line(str(self.inbound))
     ctx.fg_color(Screen.WHITE).write("   outbound: ").fg_color(Screen.YELLOW).write_line(str(self.outbound)).linebreak()
     
     ctx.fg_color(Screen.WHITE).write("Blocks: ").fg_color(Screen.YELLOW).write_line(str(self.block_count))
     ctx.fg_color(Screen.WHITE).write("Unconf. tx: ").linebreak().fg_color(Screen.YELLOW).write(str(self.utx_count))
     
     current_time = int(time.time())
     time_since_start = current_time - self.utx_start_time
     
     if time_since_start != 0:
         tx_per_second = float(self.utx_count - self.utx_count_on_block) / float(time_since_start)
     else:
         tx_per_second = 0.0
         
     time_since_block = current_time - self.last_block_time
     
     ctx.write_line(" (%.2f tx/s)" % tx_per_second).fg_color(Screen.WHITE)
     
     ctx.write_line("Time since block: ").fg_color(Screen.YELLOW).write_line(format_timespan(time_since_block))
Ejemplo n.º 4
0
 def render_tab(self, ctx):
     # Update system info
     self.update_sysinfo()
     
     # Print CPU usage
     for i in range(0, len(self.cpu_usages)):
         cpu_usage = self.cpu_usages[i]
         
         ctx.fg_color(Screen.WHITE)
         
         ctx.write("CPU %d:" % i).fg_color(Screen.YELLOW).write_line(" %.2f %%" % (cpu_usage*100)).fg_color(Screen.WHITE).write("[")
         
         if cpu_usage < self.YELLOW_THRESHOLD:
             ctx.fg_color(Screen.GREEN)
         elif cpu_usage >= self.YELLOW_THRESHOLD and cpu_usage <= self.RED_THRESHOLD:
             ctx.fg_color(Screen.YELLOW)
         else:
             ctx.fg_color(Screen.RED)
             
         ctx.write(get_progress_bar(ctx.get_columns()-2, cpu_usage)).fg_color(Screen.WHITE).write("]")
         
     # Print RAM
     used = humanfriendly.format_size(self.used_ram)
     total = humanfriendly.format_size(self.total_ram)
     ctx.linebreak().write_line("RAM").fg_color(Screen.YELLOW).write_line("%s / %s" % (used, total)).fg_color(Screen.WHITE)
     
     ram_usage = float(self.used_ram) / float(self.total_ram)
         
     ctx.write("[")
     
     if ram_usage < 0.33:
         ctx.fg_color(Screen.GREEN)
     elif ram_usage >= 0.33 and ram_usage <= 0.66:
         ctx.fg_color(Screen.YELLOW)
     else:
         ctx.fg_color(Screen.RED)
         
     ctx.write(get_progress_bar(ctx.get_columns()-2, ram_usage)).fg_color(Screen.WHITE).write("]")
     
     # Print uptime
     ctx.linebreak().write_line("Uptime:").fg_color(Screen.YELLOW).write_line("%s" % format_timespan(self.uptime)).fg_color(Screen.WHITE)
Ejemplo n.º 5
0
def music_get_album(album_id: str, locale: str):
    try:
        album = musicbrainzngs.get_release_by_id(
            album_id, includes=["artists", "recordings"])["release"]
    except ResponseError as error:
        abort(error.cause.code)
        return
    album_name: str = album["title"]
    artist = album["artist-credit"][0]["artist"]
    artist_id: str = artist["id"]
    artist_name: str = artist["name"]
    tracks = album["medium-list"][0]["track-list"]

    doc: Document = minidom.Document()
    feed: Element = create_feed(doc, album_name, album_id, request.endpoint)

    if bool(album["cover-art-archive"]["front"]):
        # Add front cover
        image_elem: Element = doc.createElement("image")
        image_id_elem: Element = create_id(doc, album_id)
        image_elem.appendChild(image_id_elem)
        feed.appendChild(image_elem)

    for track in tracks:
        recording = track["recording"]
        track_id: str = recording["id"]
        track_title: str = recording["title"]
        entry: Element = create_entry(doc, track_title, track_id,
                                      f"/v3.2/{locale}/")

        # Set primaryArtist
        primary_artist_elem: Element = doc.createElement("primaryArtist")
        primary_artist_props = {"id": artist_id, "name": artist_name}
        set_values_as_elements(doc, primary_artist_elem, primary_artist_props)
        entry.appendChild(primary_artist_elem)

        try:
            length_ms: int = int(track["track_or_recording_length"])
            length_elem: Element = doc.createElement("duration")
            length_timespan: str = utils.format_timespan(length_ms)
            set_element_value(length_elem, length_timespan)
            entry.appendChild(length_elem)
        except:
            pass

        try:
            track_position: str = track["position"]
            index_elem: Element = doc.createElement("trackNumber")
            set_element_value(index_elem, track_position)
            entry.appendChild(index_elem)
        except:
            pass

        try:
            # Add rights
            right: Element = doc.createElement("right")
            right_props = {
                # "providerName": "YouTube",
                "providerCode": "117767492:MP3_DOWNLOAD_UENC_256kb_075",
                "price": 800,
                "priceCurrencyCode": "MPT",
                "licenseType": "Preview",
                "audioEncoding": "MP3",
                "offerId": "urn:uuid:9534a201-2102-11db-89ca-0019b92a3933",
                "paymentTypes": {
                    "paymentType": "Microsoft Points"
                }
                # "offerInstanceId": "urn:uuid:9534a201-2102-11db-89ca-0019b92a3933",
            }
            set_values_as_elements(doc, right, right_props)
            rights: Element = doc.createElement("rights")
            rights.appendChild(right)
            entry.appendChild(rights)
            set_value_as_element(doc, entry, "isActionable", "True")
            set_value_as_element(doc, entry, "canPlay", "True")
        except:
            pass

        feed.appendChild(entry)

    # doc.appendChild(feed)
    xml_str = doc.toprettyxml(indent="\t")
    return Response(xml_str, mimetype=MIME_XML)