Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Use python-tabulate to print tables
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Sep 5, 2023
1 parent cd382b8 commit a65716e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pygithub>=1.59.0
python-dateutil>=2.8.2
requests>=2.31.0
requests>=2.31.0
tabulate>=0.9.0
30 changes: 13 additions & 17 deletions sync/cli/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path

from dateutil.parser import parse
from tabulate import tabulate

from .Parameters import Parameters
from .TypeDict import ConfigDict, TrackDict
Expand Down Expand Up @@ -317,29 +318,24 @@ def print_json(obj: dict, __stdout: bool = False):
print(string)


def format_text(text: str, _len: int, left: bool = True):
if len(text) < _len:
if left:
return text.ljust(_len)
else:
return text.rjust(_len)
else:
return text[:_len - 3] + "..."


def print_modules_list(modules_folder: Path, tracks: list):
print("# tracks in repository at {}:".format(modules_folder))
print("#")
print("# {:<28} {:<15} {:<15} {}".format(
"ID", "Add Date", "Last Update", "Versions"
))

table = []
headers = ["id", "add time", "last update", "versions"]

for track in tracks:
if track.versions is None:
track.last_update = 0
track.versions = 0

print("{:<30}".format(format_text(track.id, 30, left=True)), end=" ")
print("{:<15}".format(str(datetime.fromtimestamp(track.added).date())), end=" ")
print("{:<15}".format(str(datetime.fromtimestamp(track.last_update).date())), end=" ")
print("{:^10}".format(track.versions))
table.append([
track.id,
datetime.fromtimestamp(track.added).date(),
datetime.fromtimestamp(track.last_update).date(),
track.versions
])

markdown_text = tabulate(table, headers, tablefmt="github")
print(markdown_text)

0 comments on commit a65716e

Please sign in to comment.