-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathutils.py
More file actions
70 lines (59 loc) · 1.86 KB
/
Copy pathutils.py
File metadata and controls
70 lines (59 loc) · 1.86 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
from typing import NoReturn, List
import requests
import config
def get_default_programming_language(
language: str
) -> str:
"""Returns default appearance of language
"""
language = language.lower()
for lang in config.DEFAULT_PROGRAMMING_LANGUAGES:
if lang.replace('\\', '').lower() == language:
return lang
return ""
def contains_string(
strings: List[str],
matched_string: str,
ignore_case: bool
) -> bool:
"""Returns True if `matched_string` in `strings`.
:param strings: list of strings where contains matched string.
:param matched_string: source string
"""
if ignore_case:
matched_string = matched_string.lower()
for string in strings:
if string.lower() == matched_string:
return True
else:
return matched_string in strings
return False
def contains_all_strings(
strings: List[str],
matched_strings: List[str],
ignore_case: bool
) -> bool:
"""Returns True if `strings` in `matched_strings`.
"""
matched_strings_count = len(matched_strings)
for string in strings:
if contains_string(matched_strings, string, ignore_case):
matched_strings_count -= 1
if matched_strings_count == 0:
return True
return False
def karma_limit(karma: int) -> int:
"""Returns karma hours limit.
"""
for limit_item in config.KARMA_LIMIT_HOURS:
if not limit_item["min_karma"] or karma >= limit_item["min_karma"]:
if not limit_item["max_karma"] or karma < limit_item["max_karma"]:
return limit_item["limit"]
return 168 # hours (a week)
def is_available_ghpage(
profile: str
) -> bool:
"""Returns True if github profile is available.
"""
return requests.get(f'https://github.com/{profile}').status_code == 200