Merge pull request #52 from ajmeese7/master

Removed duplicate code
This commit is contained in:
Anmol Pratap Singh
2020-08-10 19:47:47 +05:30
committed by GitHub

49
main.py
View File

@@ -85,15 +85,7 @@ query {
get_loc_url = Template("""/repos/$owner/$repo/stats/code_frequency""") get_loc_url = Template("""/repos/$owner/$repo/stats/code_frequency""")
get_profile_view = Template("""/repos/$owner/$repo/traffic/views?per=week""") get_profile_view = Template("""/repos/$owner/$repo/traffic/views?per=week""")
get_profile_traffic = Template("""/repos/$owner/$repo/traffic/popular/referrers""") get_profile_traffic = Template("""/repos/$owner/$repo/traffic/popular/referrers""")
truthy = ['true', '1', 't', 'y', 'yes']
def human_format(num):
magnitude = 0
while abs(num) >= 1000:
magnitude += 1
num /= 1000.0
# add more suffixes if you need them
return '%.2f%s' % (num, ['', 'K', 'M', 'G', 'T', 'P'][magnitude])
def run_v3_api(query): def run_v3_api(query):
@@ -272,7 +264,7 @@ def generate_commit_list(tz):
string = string + '**' + title + '** \n\n' + '```text\n' + make_commit_list(one_day) + '\n\n```\n' string = string + '**' + title + '** \n\n' + '```text\n' + make_commit_list(one_day) + '\n\n```\n'
if show_days_of_week.lower() in ['true', '1', 't', 'y', 'yes']: if show_days_of_week.lower() in truthy:
max_element = { max_element = {
'percent': 0 'percent': 0
} }
@@ -290,52 +282,52 @@ def get_waka_time_stats():
stats = '' stats = ''
request = requests.get( request = requests.get(
f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}") f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}")
no_activity = "No Activity tracked this Week"
if request.status_code == 401: if request.status_code == 401:
print("Error With WAKA time API returned " + str(request.status_code) + " Response " + str(request.json())) print("Error With WAKA time API returned " + str(request.status_code) + " Response " + str(request.json()))
else: else:
empty = True empty = True
data = request.json() data = request.json()
if showCommit.lower() in ['true', '1', 't', 'y', 'yes']: if showCommit.lower() in truthy:
empty = False empty = False
stats = stats + generate_commit_list(tz=data['data']['timezone']) + '\n\n' stats = stats + generate_commit_list(tz=data['data']['timezone']) + '\n\n'
stats += '📊 **This week I spent my time on** \n\n' stats += '📊 **This week I spent my time on** \n\n'
stats += '```text\n' stats += '```text\n'
if showTimeZone.lower() in ['true', '1', 't', 'y', 'yes']: if showTimeZone.lower() in truthy:
empty = False empty = False
tzone = data['data']['timezone'] tzone = data['data']['timezone']
stats = stats + '⌚︎ Timezone: ' + tzone + '\n\n' stats = stats + '⌚︎ Timezone: ' + tzone + '\n\n'
if showLanguage.lower() in ['true', '1', 't', 'y', 'yes']: if showLanguage.lower() in truthy:
empty = False empty = False
if len(data['data']['languages']) == 0: if len(data['data']['languages']) == 0:
lang_list = "No Activity tracked this Week" lang_list = no_activity
else: else:
lang_list = make_list(data['data']['languages']) lang_list = make_list(data['data']['languages'])
stats = stats + '💬 Languages: \n' + lang_list + '\n\n' stats = stats + '💬 Languages: \n' + lang_list + '\n\n'
if showEditors.lower() in ['true', '1', 't', 'y', 'yes']: if showEditors.lower() in truthy:
empty = False empty = False
if len(data['data']['editors']) == 0: if len(data['data']['editors']) == 0:
edit_list = "No Activity tracked this Week" edit_list = no_activity
else: else:
edit_list = make_list(data['data']['editors']) edit_list = make_list(data['data']['editors'])
stats = stats + '🔥 Editors: \n' + edit_list + '\n\n' stats = stats + '🔥 Editors: \n' + edit_list + '\n\n'
if showProjects.lower() in ['true', '1', 't', 'y', 'yes']: if showProjects.lower() in truthy:
empty = False empty = False
if len(data['data']['projects']) == 0: if len(data['data']['projects']) == 0:
project_list = "No Activity tracked this Week" project_list = no_activity
else: else:
project_list = make_list(data['data']['projects']) project_list = make_list(data['data']['projects'])
stats = stats + '🐱‍💻 Projects: \n' + project_list + '\n\n' stats = stats + '🐱‍💻 Projects: \n' + project_list + '\n\n'
if showOs.lower() in ['true', '1', 't', 'y', 'yes']: if showOs.lower() in truthy:
empty = False empty = False
if len(data['data']['operating_systems']) == 0: if len(data['data']['operating_systems']) == 0:
os_list = "No Activity tracked this Week" os_list = no_activity
else: else:
os_list = make_list(data['data']['operating_systems']) os_list = make_list(data['data']['operating_systems'])
stats = stats + '💻 Operating Systems: \n' + os_list + '\n\n' stats = stats + '💻 Operating Systems: \n' + os_list + '\n\n'
@@ -394,8 +386,7 @@ def get_line_of_code():
def get_short_info(github): def get_short_info(github):
string = '' string = '**🐱 My GitHub Data** \n\n'
string += '**🐱 My GitHub Data** \n\n'
user_info = github.get_user() user_info = github.get_user()
if user_info.disk_usage is None: if user_info.disk_usage is None:
disk_usage = humanize.naturalsize(0) disk_usage = humanize.naturalsize(0)
@@ -434,24 +425,24 @@ def get_stats(github):
stats = '' stats = ''
repositoryList = run_query(repositoryListQuery.substitute(username=username, id=id)) repositoryList = run_query(repositoryListQuery.substitute(username=username, id=id))
if show_profile_view.lower() in ['true', '1', 't', 'y', 'yes']: if show_profile_view.lower() in truthy:
data = run_v3_api(get_profile_view.substitute(owner=username, repo=username)) data = run_v3_api(get_profile_view.substitute(owner=username, repo=username))
stats += '![Profile Views](http://img.shields.io/badge/Profile%20Views-' + str(data['count']) + '-blue)\n\n' stats += '![Profile Views](http://img.shields.io/badge/Profile%20Views-' + str(data['count']) + '-blue)\n\n'
if show_loc.lower() in ['true', '1', 't', 'y', 'yes']: if show_loc.lower() in truthy:
stats += '![Lines of code](https://img.shields.io/badge/From%20Hello%20World%20I\'ve%20written-' + quote( stats += '![Lines of code](https://img.shields.io/badge/From%20Hello%20World%20I\'ve%20written-' + quote(
str(get_line_of_code())) + '%20Lines%20of%20code-blue)\n\n' str(get_line_of_code())) + '%20Lines%20of%20code-blue)\n\n'
if show_short_info.lower() in ['true', '1', 't', 'y', 'yes']: if show_short_info.lower() in truthy:
stats += get_short_info(github) stats += get_short_info(github)
if show_waka_stats.lower() in ['true', '1', 't', 'y', 'yes']: if show_waka_stats.lower() in truthy:
stats += get_waka_time_stats() stats += get_waka_time_stats()
if showLanguagePerRepo.lower() in ['true', '1', 't', 'y', 'yes']: if showLanguagePerRepo.lower() in truthy:
stats = stats + generate_language_per_repo(repositoryList) + '\n\n' stats = stats + generate_language_per_repo(repositoryList) + '\n\n'
if showLocChart.lower() in ['true', '1', 't', 'y', 'yes']: if showLocChart.lower() in truthy:
loc = LinesOfCode(id, username, ghtoken, repositoryList) loc = LinesOfCode(id, username, ghtoken, repositoryList)
loc.calculateLoc() loc.calculateLoc()
stats += '**Timeline**\n\n' stats += '**Timeline**\n\n'