-
Notifications
You must be signed in to change notification settings - Fork 20
/
generate_index.py
158 lines (131 loc) · 5.67 KB
/
generate_index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from github import Github
from themes.level_1.level1 import genHTMLLevel1
from themes.level_2.level2 import genHTMLLevel2
from utils.convertors import Convertors
from utils.adders import Adder
import sys
import os
import re
git = Github(sys.argv[1])
theme_selected = sys.argv[2]
blogs = eval(sys.argv[3].title())
include_hackathon = eval(sys.argv[4].title())
stats_choice = sys.argv[5]
currentRepoName = sys.argv[6].split('/')[-1]
currentRepoBranch = sys.argv[7].split('/')[-1]
resume_link = sys.argv[8]
allow_footer = eval(sys.argv[9].title())
projects_sort_by = sys.argv[10]
stats_customization = sys.argv[11]
social_links = sys.argv[12:]
convert = Convertors()
adder = Adder()
start = git.rate_limiting[0]
print(f'Request left at start of the script: {start}')
user_object = git.get_user()
git_username = user_object.login
user_data = {'username': git_username,
'git_photo_url': user_object.avatar_url,
'git_bio': user_object.bio,
'git_email': user_object.email,
'git_followers': user_object.followers,
'git_following': user_object.following,
'name': user_object.name,
'latest_updated': str(user_object.updated_at)}
repo_list = [repo.name for repo in git.get_user().get_repos()]
project_data = {}
hackathon_data = {}
if include_hackathon:
for repo in repo_list:
print(f'Repo being checked: {repo}')
try:
repo_object = git.get_repo(git_username + '/' + repo)
repo_topics = repo_object.get_topics()
if len(repo_topics) != 0:
if 'project' in repo_topics:
project_data[f'{repo}'] = {'repo_topics': repo_topics,
'repo_description': repo_object.description,
'repo_stars': int(repo_object.stargazers_count),
'repo_forks': int(repo_object.forks_count)}
if 'hackathon' in repo_topics:
hackathon_data[f'{repo}'] = {'repo_topics': repo_topics,
'repo_description': repo_object.description,
'repo_stars': int(repo_object.stargazers_count),
'repo_forks': int(repo_object.forks_count)}
else:
continue
else:
continue
except:
continue
else:
for repo in repo_list:
print(f'Repo being checked: {repo}')
try:
repo_object = git.get_repo(git_username + '/' + repo)
repo_topics = repo_object.get_topics()
if len(repo_topics) != 0:
if 'project' in repo_topics:
project_data[f'{repo}'] = {'repo_topics': repo_topics,
'repo_description': repo_object.description,
'repo_stars': int(repo_object.stargazers_count),
'repo_forks': int(repo_object.forks_count)}
else:
continue
else:
continue
except:
continue
end = git.rate_limiting[0]
print(f'Request left at end of the script: {end}')
print(f'Requests Consumed in this process: {start - end}')
project_repos = convert.repoDataToHTML(
project_data, git_username, projects_sort_by)
if include_hackathon:
hackathon_repos = convert.repoDataToHTML(
hackathon_data, git_username, projects_sort_by)
else:
hackathon_repos = None
social_data = convert.soicalLinksListToHTML(
social_links, user_data['username'])
if theme_selected == '1':
newIndex = genHTMLLevel1(
user_data, project_repos, hackathon_repos, blogs, social_data, resume_link, allow_footer)
elif theme_selected == '2':
newIndex = genHTMLLevel2(user_data, project_repos,
hackathon_repos, blogs, social_data, resume_link, allow_footer)
newIndex = adder.addGitHubStats(
newIndex, stats_choice, git_username, theme_selected, stats_customization)
if 'index.html' in os.listdir(sys.argv[6]):
index_path = sys.argv[6] + '/index.html'
with open(index_path, 'r', encoding='utf-8') as f:
oldIndex = f.read()
indexRepo = git.get_repo(f"{git_username}/{currentRepoName}")
oldContents = indexRepo.get_contents('index.html')
if blogs:
blogPattern = "<!-- BLOG-POST-LIST:START -->(.*?)<!-- BLOG-POST-LIST:END -->"
blogData = re.search(blogPattern, oldIndex)
try:
oldData = blogData.group(1)
if oldData == '':
print("Blog content initially empty")
else:
print("Adding old blog content to new index!")
formatedContent = f"<!-- BLOG-POST-LIST:START -->{oldData}<!-- BLOG-POST-LIST:END -->"
newIndex = newIndex.replace(
"<!-- BLOG-POST-LIST:START --><!-- BLOG-POST-LIST:END -->", formatedContent)
except:
print("Error in Blogs updation content")
else:
print("Blogs content updation not enabled by user, therefore skipping blogs content addition.")
if oldIndex != newIndex:
print("Index Contents Updated")
indexRepo.update_file(oldContents.path, "Updating Index file",
newIndex, oldContents.sha)
else:
print("No changes Detected")
else:
print("Writing index.html for first time")
indexRepo = git.get_repo(f"{git_username}/{currentRepoName}")
indexRepo.create_file('index.html', "Adding index file",
newIndex, branch=currentRepoBranch)