Added yapf config, applied yapf
This commit is contained in:
parent
98fb0be057
commit
cd2bd27711
3 changed files with 49 additions and 13 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -102,3 +102,5 @@ venv.bak/
|
|||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
/tags
|
||||
/tags.*
|
||||
|
|
30
.style.yapf
Normal file
30
.style.yapf
Normal file
|
@ -0,0 +1,30 @@
|
|||
[style]
|
||||
|
||||
# The column limit.
|
||||
column_limit=120
|
||||
|
||||
# Split before the '.' if we need to split a longer expression:
|
||||
#
|
||||
# foo = ('This is a really long string: {}, {}, {}, {}'.format(a, b, c, d))
|
||||
#
|
||||
# would reformat to something like:
|
||||
#
|
||||
# foo = ('This is a really long string: {}, {}, {}, {}'
|
||||
# .format(a, b, c, d))
|
||||
split_before_dot=False
|
||||
|
||||
# Set to True to split list comprehensions and generators that have
|
||||
# non-trivial expressions and multiple clauses before each of these
|
||||
# clauses. For example:
|
||||
#
|
||||
# result = [
|
||||
# a_long_var + 100 for a_long_var in xrange(1000)
|
||||
# if a_long_var % 10]
|
||||
#
|
||||
# would reformat to something like:
|
||||
#
|
||||
# result = [
|
||||
# a_long_var + 100
|
||||
# for a_long_var in xrange(1000)
|
||||
# if a_long_var % 10]
|
||||
split_complex_comprehension=True
|
30
httping.py
30
httping.py
|
@ -1,6 +1,5 @@
|
|||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" Simulates httping for `argos <https://github.com/p-e-w/argos>`"""
|
||||
# <bitbar.title>httping</bitbar.title>
|
||||
# <bitbar.version>v1.0</bitbar.version>
|
||||
|
@ -11,10 +10,11 @@
|
|||
# <bitbar.dependencies>python,requests</bitbar.dependencies>
|
||||
# <bitbar.abouturl>https://github.com/schtobia/argos-httping/blob/master/httping.py</bitbar.abouturl>
|
||||
|
||||
import sys #for redirecting print to stderr
|
||||
import datetime #for the whole ms → s and vice versa stuff
|
||||
import requests #for the central HTTP HEAD request
|
||||
import statistics #for median and stdev
|
||||
import datetime # for the whole ms → s and vice versa stuff
|
||||
import statistics # for median and stdev
|
||||
import sys # for redirecting print to stderr
|
||||
|
||||
import requests # for the central HTTP HEAD request
|
||||
|
||||
__author__ = "Tobias Schmidl"
|
||||
__copyright__ = "Copyright 2018, Tobias Schmidl"
|
||||
|
@ -22,19 +22,21 @@ __license__ = "MIT"
|
|||
__version__ = "0.0.1"
|
||||
__maintainer__ = "Tobias Schmidl"
|
||||
|
||||
max_ping = datetime.timedelta(milliseconds = 1000) # in seconds
|
||||
max_ping = datetime.timedelta(milliseconds=1000) # in seconds
|
||||
targets = ["https://www.google.de", "https://www.bing.com", "https://www.wikipedia.org"]
|
||||
|
||||
max_ping_in_ms = max_ping.total_seconds() * 1000
|
||||
in_bin = lambda x, bin: x >= bin[0] and x <= bin[1]
|
||||
|
||||
|
||||
class Themes:
|
||||
# Themes are from http://colorbrewer2.org/
|
||||
purple_green = ["#762a83", "#9970ab","#c2a5cf","#a6dba0","#5aae61","#1b7837"]
|
||||
red_green = ["#d73027", "#fc8d59","#fee08b","#d9ef8b","#91cf60","#1a9850"]
|
||||
original = ["#acacac","#ff0101","#cc673b","#ce8458","#6bbb15","#0ed812"]
|
||||
purple_green = ["#762a83", "#9970ab", "#c2a5cf", "#a6dba0", "#5aae61", "#1b7837"]
|
||||
red_green = ["#d73027", "#fc8d59", "#fee08b", "#d9ef8b", "#91cf60", "#1a9850"]
|
||||
original = ["#acacac", "#ff0101", "#cc673b", "#ce8458", "#6bbb15", "#0ed812"]
|
||||
selected_colors = red_green
|
||||
generate_bins = lambda min_val, max_val, step_width = 2: [[x, x + step_width - 1] for x in range(min_val, max_val, step_width)]
|
||||
generate_bins = lambda min_val, max_val, step_width=2: [[x, x + step_width - 1] for x in range(
|
||||
min_val, max_val, step_width)]
|
||||
bins = generate_bins(0, int(max_ping_in_ms), int(max_ping_in_ms / (len(selected_colors) - 1)))
|
||||
|
||||
def colorize(response_time):
|
||||
|
@ -43,11 +45,12 @@ class Themes:
|
|||
return Themes.selected_colors[len(Themes.selected_colors) - 1 - index]
|
||||
return Themes.selected_colors[0]
|
||||
|
||||
|
||||
def httping(targets):
|
||||
responses = {}
|
||||
for target in targets:
|
||||
try:
|
||||
responses[target] = requests.head(target, timeout = max_ping.total_seconds()).elapsed.total_seconds() * 1000
|
||||
responses[target] = requests.head(target, timeout=max_ping.total_seconds()).elapsed.total_seconds() * 1000
|
||||
except requests.exceptions.RequestException as ex:
|
||||
print(str(ex), file=sys.stderr)
|
||||
responses[target] = None
|
||||
|
@ -60,12 +63,13 @@ def httping(targets):
|
|||
else:
|
||||
return responses, None, None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
response_times, median, stddev = httping(targets)
|
||||
if isinstance(median, float) and median != max_ping_in_ms:
|
||||
print("⦿ " + str(round(median,2)) + "±" + str(round(stddev, 2)) + " | color=" + Themes.colorize(median))
|
||||
print("⦿ " + str(round(median, 2)) + "±" + str(round(stddev, 2)) + " | color=" + Themes.colorize(median))
|
||||
else:
|
||||
print("☠ | color=" + Themes.selected_colors[0]);
|
||||
print("☠ | color=" + Themes.selected_colors[0])
|
||||
print("---")
|
||||
for target, response_time in response_times.items():
|
||||
if isinstance(response_time, float):
|
||||
|
|
Loading…
Reference in a new issue