-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (39 loc) · 1.2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from pathlib import Path
from pyaction import PyAction
from pyaction.workflow import annotations as A
from chart import Badge
from pypi import PyPI
workflow = PyAction()
def get_or_create_path(path: str) -> str:
"""gets or creates the path then returns it
Args:
path (str): path
Returns:
str: path
"""
if not os.path.exists(path):
A.warning(f"Couldn't find `{path}` path in the repo. Creating it!")
os.makedirs(path)
return path
@workflow.action
def action(
package_name: str,
badge_width: int,
badge_height: int,
badge_color: str,
badge_dark_color: str,
days_limit: int,
output_path: str,
file_name: str,
) -> None:
package = PyPI(package_name)
rates_df = package.get_rates(days_limit)
badge = Badge(rates_df).create(badge_height, badge_width, badge_color)
dark_badge = Badge(rates_df).create(badge_height, badge_width, badge_dark_color)
badge_path = Path(get_or_create_path(output_path)).joinpath(file_name)
dark_badge_path = Path(get_or_create_path(output_path)).joinpath(
f"dark_{file_name}"
)
badge.write_image(badge_path)
dark_badge.write_image(dark_badge_path)