From a860bf594d7a67aef02934ff5f0eb961595ac806 Mon Sep 17 00:00:00 2001 From: Mark Mayo Date: Tue, 28 Mar 2023 14:27:15 +1300 Subject: [PATCH] Tidy up for pylint + flake8 - removed whitespace - formatting around arithmetic operators - newline where required - sorted imports - simplified conditional --- assets/timelinecss.py | 34 +++++++++++++++++----------------- raycast/tse.py | 6 +++--- raycast/tsl.py | 16 ++++++++-------- raycast/tsn.py | 16 ++++++++-------- raycast/tsr.py | 16 ++++++++-------- raycast/tsv.py | 32 ++++++++++++++++++-------------- 6 files changed, 62 insertions(+), 58 deletions(-) diff --git a/assets/timelinecss.py b/assets/timelinecss.py index 9b3e033..b44a793 100644 --- a/assets/timelinecss.py +++ b/assets/timelinecss.py @@ -4,20 +4,20 @@ * { box-sizing: border-box; } - + /* Set a background color */ body { background-color: #3B4252; font-family: Helvetica, sans-serif; } - + /* The actual timeline (the vertical ruler) */ .timeline { position: relative; max-width: 1200px; margin: 0 auto; } - + /* The actual timeline (the vertical ruler) */ .timeline::after { content: ''; @@ -29,7 +29,7 @@ left: 50%; margin-left: -3px; } - + /* Container around content */ .container { padding: 10px 40px; @@ -37,7 +37,7 @@ background-color: inherit; width: 50%; } - + /* The circles on the timeline */ .container::after { content: ''; @@ -51,17 +51,17 @@ border-radius: 50%; z-index: 1; } - + /* Place the container to the left */ .left { left: 0; } - + /* Place the container to the right */ .right { left: 50%; } - + /* Add arrows to the left container (pointing right) */ .left::before { content: " "; @@ -75,7 +75,7 @@ border-width: 10px 0 10px 10px; border-color: transparent transparent transparent #ECEFF4; } - + /* Add arrows to the right container (pointing left) */ .right::before { content: " "; @@ -89,12 +89,12 @@ border-width: 10px 10px 10px 0; border-color: transparent #ECEFF4 transparent transparent; } - + /* Fix the circle for containers on the right side */ .right::after { left: -16px; } - + /* The actual content */ .content { padding: 20px 30px; @@ -102,21 +102,21 @@ position: relative; border-radius: 6px; } - + /* Media queries - Responsive timeline on screens less than 600px wide */ @media screen and (max-width: 600px) { /* Place the timelime to the left */ .timeline::after { left: 31px; } - + /* Full-width containers */ .container { width: 100%; padding-left: 70px; padding-right: 25px; } - + /* Make sure that all arrows are pointing leftwards */ .container::before { left: 60px; @@ -124,15 +124,15 @@ border-width: 10px 10px 10px 0; border-color: transparent #ECEFF4 transparent transparent; } - + /* Make sure all circles are at the same spot */ .left::after, .right::after { left: 15px; } - + /* Make all right containers behave like the left ones */ .right { left: 0%; } } -""" \ No newline at end of file +""" diff --git a/raycast/tse.py b/raycast/tse.py index 3ea69b6..4170612 100755 --- a/raycast/tse.py +++ b/raycast/tse.py @@ -14,11 +14,11 @@ # @raycast.author Tomasz Sobota # @raycast.authorURL https://techbranch.net -import webbrowser import os +import webbrowser home_path = os.path.expanduser('~') -REPOSITORY_PATH = home_path+"/tsr" +REPOSITORY_PATH = home_path + "/tsr" -webbrowser.open('file://'+os.path.realpath(REPOSITORY_PATH)) +webbrowser.open('file://' + os.path.realpath(REPOSITORY_PATH)) print("Opening") diff --git a/raycast/tsl.py b/raycast/tsl.py index 3a84caa..bcb1c90 100755 --- a/raycast/tsl.py +++ b/raycast/tsl.py @@ -14,8 +14,8 @@ # @raycast.author Tomasz Sobota # @raycast.authorURL https://techbranch.net -import datetime import csv +import datetime import os # ------------ @@ -24,13 +24,13 @@ # modify to your preference home_path = os.path.expanduser('~') -FILE_PATH = home_path+"/tsr/record.csv" +FILE_PATH = home_path + "/tsr/record.csv" # --------- current_timestamp = datetime.datetime.now() -output = f"" +output = "" # make sure directories exist os.makedirs(os.path.dirname(FILE_PATH), exist_ok=True) @@ -38,19 +38,19 @@ with open(FILE_PATH, "r") as csvfile: reader = csv.reader(csvfile) for row in reader: - + if len(row) == 0: # omit empty rows continue - + raw_datetime = row[0] raw_tags = row[1] parsed_datetime = datetime.datetime.fromisoformat(raw_datetime) dt_delta = current_timestamp - parsed_datetime - dt_total_minutes = int(round(dt_delta.total_seconds()/60, 0)) - dt_hours = int(dt_total_minutes/60) - dt_minutes = dt_total_minutes-dt_hours*60 + dt_total_minutes = int(round(dt_delta.total_seconds() / 60, 0)) + dt_hours = int(dt_total_minutes / 60) + dt_minutes = dt_total_minutes - dt_hours * 60 delta_pretty = f"{dt_hours}h {dt_minutes}m" # that way we'll only see the last entry: diff --git a/raycast/tsn.py b/raycast/tsn.py index 88610c3..719de90 100755 --- a/raycast/tsn.py +++ b/raycast/tsn.py @@ -16,8 +16,8 @@ # @raycast.authorURL https://techbranch.net import datetime -import sys import os +import sys # ------------ # PARAMETERS @@ -25,7 +25,7 @@ # modify to your preference home_path = os.path.expanduser('~') -FILE_PATH = home_path+"/tsr/notes.csv" +FILE_PATH = home_path + "/tsr/notes.csv" # ---------------------------- @@ -35,15 +35,15 @@ notes = "" try: - # read notes from input - notes = sys.argv[1] + # read notes from input + notes = sys.argv[1] except IndexError: - # no notes provided - notes = "no note provided" + # no notes provided + notes = "no note provided" if notes == "": - # if we're still seeing empty notes list - notes = "no note provided" + # if we're still seeing empty notes list + notes = "no note provided" # --------- diff --git a/raycast/tsr.py b/raycast/tsr.py index bad1d45..8de8be5 100755 --- a/raycast/tsr.py +++ b/raycast/tsr.py @@ -16,8 +16,8 @@ # @raycast.authorURL https://techbranch.net import datetime -import sys import os +import sys # ------------ # PARAMETERS @@ -25,7 +25,7 @@ # modify to your preference home_path = os.path.expanduser('~') -FILE_PATH = home_path+"/tsr/record.csv" +FILE_PATH = home_path + "/tsr/record.csv" # ---------------------------- @@ -35,15 +35,15 @@ tags = "" try: - # read tags from input - tags = sys.argv[1] + # read tags from input + tags = sys.argv[1] except IndexError: - # no tags provided - tags = "next" + # no tags provided + tags = "next" if tags == "": - # if we're still seeing empty tags list - tags = "next" + # if we're still seeing empty tags list + tags = "next" # --------- diff --git a/raycast/tsv.py b/raycast/tsv.py index cc80a66..31e0e52 100755 --- a/raycast/tsv.py +++ b/raycast/tsv.py @@ -14,16 +14,17 @@ # @raycast.author Tomasz Sobota # @raycast.authorURL https://techbranch.net -import datetime -import webbrowser import csv +import datetime import os +import webbrowser class RecordType: TSR = 1 TSN = 2 + class RecordSide: LEFT = "left" RIGHT = "right" @@ -35,9 +36,9 @@ class RecordSide: # modify to your preference home_path = os.path.expanduser('~') -TSR_FILE_PATH = home_path+"/tsr/record.csv" -TSN_FILE_PATH = home_path+"/tsr/notes.csv" -HTML_OUTPUT_PATH = home_path+"/tsr/record.html" +TSR_FILE_PATH = home_path + "/tsr/record.csv" +TSN_FILE_PATH = home_path + "/tsr/notes.csv" +HTML_OUTPUT_PATH = home_path + "/tsr/record.html" CSS_ASSETS_PATH = "../assets/timeline.css" @@ -52,15 +53,15 @@ class RecordSide: def get_timeline_side(record_type: RecordType): if record_type == RecordType.TSR: return RecordSide.LEFT - elif record_type == RecordType.TSN: + if record_type == RecordType.TSN: return RecordSide.RIGHT - else: - return DEFAULT_ENTRY_SIDE + return DEFAULT_ENTRY_SIDE + def csv_to_timeline_entries(trows: list): containers = [] for row in trows: - + ts_side = get_timeline_side(row[2]) pretty_date = row[0].strftime('%H:%M on %d %b %Y') @@ -68,7 +69,7 @@ def csv_to_timeline_entries(trows: list): html_container += f'

{row[1]}

\n' html_container += f'

{pretty_date}

\n' html_container += '\n\n' - + containers.append(html_container) # return containers as a single string with reversed order return "".join(containers[::-1]) @@ -92,21 +93,23 @@ def generate_html_template(embedded_html: str, stylesheet: str):
{embedded_html} -
+ """ return html_template + def html_template_to_file(html_template: str, file_path: str): """Save html template to file""" fp = file_path - if file_path == None: + if file_path is None: fp = HTML_OUTPUT_PATH - + with open(fp, "w") as f: f.write(html_template) + def read_csv(filepath: str, recordtype: RecordType) -> list: rows_buffer = [] with open(filepath, "r") as csvfile: @@ -123,6 +126,7 @@ def read_csv(filepath: str, recordtype: RecordType) -> list: rows_buffer.append([parsed_datetime, raw_data, recordtype]) return rows_buffer + def read_file_to_str(filepath): with open(filepath, 'r') as file: return file.read() @@ -149,5 +153,5 @@ def read_file_to_str(filepath): html_template = generate_html_template(html_entries, css_stylesheet) _ = html_template_to_file(html_template, HTML_OUTPUT_PATH) -webbrowser.open('file://'+os.path.realpath(HTML_OUTPUT_PATH)) +webbrowser.open('file://' + os.path.realpath(HTML_OUTPUT_PATH)) print("Compiled the html report.")