Skip to content

Commit

Permalink
Update GitStats... (#43)
Browse files Browse the repository at this point in the history
Improve Issue stats
Improve PR stats
PEP8 refactor
Change languages visualization title
  • Loading branch information
R055A committed Oct 20, 2023
1 parent 606f674 commit 3f45714
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 272 deletions.
5 changes: 1 addition & 4 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
__all__ = [
"src",
"git_stats_imgs"
]
__all__ = ["src", "test", "git_stats_imgs"]
4 changes: 2 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
__all__ = [
"db",
"environ_vars",
"env_vars",
"generate_images",
"github_api_queries",
"github_repo_stats",
"templates"
"templates",
]
14 changes: 6 additions & 8 deletions src/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class GitRepoStatsDB:

def __init__(self):
self.__db = None

Expand All @@ -23,10 +22,9 @@ def __init__(self):
with open("../src/db/db.json", "r") as db:
self.__db = load(db)

self.views = int(self.__db['views']['count'])
self.views_from_date = self.__db['views']['from']
self.views_to_date = self.__db['views']['to']

self.views = int(self.__db["views"]["count"])
self.views_from_date = self.__db["views"]["from"]
self.views_to_date = self.__db["views"]["to"]

def __update_db(self) -> None:
try:
Expand All @@ -38,15 +36,15 @@ def __update_db(self) -> None:

def set_views_count(self, count: any) -> None:
self.views = int(count)
self.__db['views']['count'] = str(self.views)
self.__db["views"]["count"] = str(self.views)
self.__update_db()

def set_views_from_date(self, date: str) -> None:
self.views_from_date = date
self.__db['views']['from'] = self.views_from_date
self.__db["views"]["from"] = self.views_from_date
self.__update_db()

def set_views_to_date(self, date: str) -> None:
self.views_to_date = date
self.__db['views']['to'] = self.views_to_date
self.__db["views"]["to"] = self.views_to_date
self.__update_db()
115 changes: 56 additions & 59 deletions src/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@


class EnvironmentVariables:

__DATE_FORMAT = '%Y-%m-%d'

def __init__(self,
username: str,
access_token: str,
exclude_repos: Optional[str] = getenv("EXCLUDED"),
exclude_langs: Optional[str] = getenv("EXCLUDED_LANGS"),
include_forked_repos: str = getenv("INCLUDE_FORKED_REPOS"),
exclude_contrib_repos: str = getenv("EXCLUDE_CONTRIB_REPOS"),
exclude_archive_repos: str = getenv("EXCLUDE_ARCHIVE_REPOS"),
exclude_private_repos: str = getenv("EXCLUDE_PRIVATE_REPOS"),
exclude_public_repos: str = getenv("EXCLUDE_PUBLIC_REPOS"),
repo_views: Optional[str] = getenv("REPO_VIEWS"),
repo_last_viewed: Optional[str] = getenv("LAST_VIEWED"),
repo_first_viewed: Optional[str] = getenv("FIRST_VIEWED"),
store_repo_view_count: str = getenv("STORE_REPO_VIEWS"),
more_collaborators: Optional[str] = getenv("MORE_COLLABS"),
manually_added_repos: Optional[str] = getenv("MORE_REPOS"),
only_included_repos: Optional[str] = getenv("ONLY_INCLUDED"),
exclude_collab_repos: Optional[str] = getenv("EXCLUDED_COLLAB_REPOS"),
more_collab_repos: Optional[str] = getenv("MORE_COLLAB_REPOS")):
__DATE_FORMAT = "%Y-%m-%d"

def __init__(
self,
username: str,
access_token: str,
exclude_repos: Optional[str] = getenv("EXCLUDED"),
exclude_langs: Optional[str] = getenv("EXCLUDED_LANGS"),
include_forked_repos: str = getenv("INCLUDE_FORKED_REPOS"),
exclude_contrib_repos: str = getenv("EXCLUDE_CONTRIB_REPOS"),
exclude_archive_repos: str = getenv("EXCLUDE_ARCHIVE_REPOS"),
exclude_private_repos: str = getenv("EXCLUDE_PRIVATE_REPOS"),
exclude_public_repos: str = getenv("EXCLUDE_PUBLIC_REPOS"),
repo_views: Optional[str] = getenv("REPO_VIEWS"),
repo_last_viewed: Optional[str] = getenv("LAST_VIEWED"),
repo_first_viewed: Optional[str] = getenv("FIRST_VIEWED"),
store_repo_view_count: str = getenv("STORE_REPO_VIEWS"),
more_collaborators: Optional[str] = getenv("MORE_COLLABS"),
manually_added_repos: Optional[str] = getenv("MORE_REPOS"),
only_included_repos: Optional[str] = getenv("ONLY_INCLUDED"),
exclude_collab_repos: Optional[str] = getenv("EXCLUDED_COLLAB_REPOS"),
more_collab_repos: Optional[str] = getenv("MORE_COLLAB_REPOS"),
):
self.__db = GitRepoStatsDB()

self.username = username
Expand All @@ -42,45 +43,41 @@ def __init__(self,
if exclude_repos is None:
self.exclude_repos = set()
else:
self.exclude_repos = (
{x.strip() for x in exclude_repos.split(",")}
)
self.exclude_repos = {x.strip() for x in exclude_repos.split(",")}

if exclude_langs is None:
self.exclude_langs = set()
else:
self.exclude_langs = (
{x.strip() for x in exclude_langs.split(",")}
)
self.exclude_langs = {x.strip() for x in exclude_langs.split(",")}

self.include_forked_repos = (
not not include_forked_repos
and include_forked_repos.strip().lower() == "true"
not not include_forked_repos
and include_forked_repos.strip().lower() == "true"
)

self.exclude_contrib_repos = (
not not exclude_contrib_repos
and exclude_contrib_repos.strip().lower() == "true"
not not exclude_contrib_repos
and exclude_contrib_repos.strip().lower() == "true"
)

self.exclude_archive_repos = (
not not exclude_archive_repos
and exclude_archive_repos.strip().lower() == "true"
not not exclude_archive_repos
and exclude_archive_repos.strip().lower() == "true"
)

self.exclude_private_repos = (
not not exclude_private_repos
and exclude_private_repos.strip().lower() == "true"
not not exclude_private_repos
and exclude_private_repos.strip().lower() == "true"
)

self.exclude_public_repos = (
not not exclude_public_repos
and exclude_public_repos.strip().lower() == "true"
not not exclude_public_repos
and exclude_public_repos.strip().lower() == "true"
)

self.store_repo_view_count = (
not store_repo_view_count
or store_repo_view_count.strip().lower() != "false"
not store_repo_view_count
or store_repo_view_count.strip().lower() != "false"
)

if self.store_repo_view_count:
Expand All @@ -95,9 +92,9 @@ def __init__(self,

if repo_last_viewed:
try:
if repo_last_viewed == datetime\
.strptime(repo_last_viewed, self.__DATE_FORMAT)\
.strftime(self.__DATE_FORMAT):
if repo_last_viewed == datetime.strptime(
repo_last_viewed, self.__DATE_FORMAT
).strftime(self.__DATE_FORMAT):
self.repo_last_viewed = repo_last_viewed
except ValueError:
self.repo_last_viewed = self.__db.views_to_date
Expand All @@ -106,9 +103,9 @@ def __init__(self,

if repo_first_viewed:
try:
if repo_first_viewed == datetime\
.strptime(repo_first_viewed, self.__DATE_FORMAT)\
.strftime(self.__DATE_FORMAT):
if repo_first_viewed == datetime.strptime(
repo_first_viewed, self.__DATE_FORMAT
).strftime(self.__DATE_FORMAT):
self.repo_first_viewed = repo_first_viewed
except ValueError:
self.repo_first_viewed = self.__db.views_from_date
Expand All @@ -124,37 +121,37 @@ def __init__(self,
self.__db.set_views_to_date(self.repo_last_viewed)

try:
self.more_collaborators = int(more_collaborators) if more_collaborators else 0
self.more_collaborators = (
int(more_collaborators) if more_collaborators else 0
)
except ValueError:
self.more_collaborators = 0

if manually_added_repos is None:
self.manually_added_repos = set()
else:
self.manually_added_repos = (
{x.strip() for x in manually_added_repos.split(",")}
)
self.manually_added_repos = {
x.strip() for x in manually_added_repos.split(",")
}

if only_included_repos is None or only_included_repos == "":
self.only_included_repos = set()
else:
self.only_included_repos = (
{x.strip() for x in only_included_repos.split(",")}
)
self.only_included_repos = {
x.strip() for x in only_included_repos.split(",")
}

if exclude_collab_repos is None:
self.exclude_collab_repos = set()
else:
self.exclude_collab_repos = (
{x.strip() for x in exclude_collab_repos.split(",")}
)
self.exclude_collab_repos = {
x.strip() for x in exclude_collab_repos.split(",")
}

if more_collab_repos is None:
self.more_collab_repos = set()
else:
self.more_collab_repos = (
{x.strip() for x in more_collab_repos.split(",")}
)
self.more_collab_repos = {x.strip() for x in more_collab_repos.split(",")}

def set_views(self, views: any) -> None:
self.repo_views += int(views)
Expand Down
Loading

0 comments on commit 3f45714

Please sign in to comment.