-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcreate_profiles.py
More file actions
98 lines (71 loc) · 3.05 KB
/
Copy pathcreate_profiles.py
File metadata and controls
98 lines (71 loc) · 3.05 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
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
import requests
from bs4 import BeautifulSoup
import jinja2
def render_jinja_html(template_loc, file_name, **context):
return jinja2.Environment(
loader=jinja2.FileSystemLoader(template_loc+'/')
).get_template(file_name).render(context)
def pinned_repo_data(soup):
pinned_repositories = []
desired_tags = soup.findAll("li", {"class": "pinned-repo-item"})
for tag in desired_tags:
repo_data = {}
repo_data["name"] = (tag.find("span", {"class": "repo"})).text
div = (tag.find("span", {"class": "d-block"}))
repo_data["url"] = (div.find("a", {"class": "text-bold"}))["href"]
repo_data["url"] = "https://github.com" + repo_data["url"]
desired_tag = (tag.find("p", {"class": "pinned-repo-desc"}))
repo_data["desc"] = desired_tag.text
repo_data["description"] = repo_data["desc"].strip()
pinned_repositories.append(repo_data)
return (pinned_repositories)
def gh_email(soup):
return(input('Enter the respective email-id : '))
def gh_bio(soup):
div = soup.find("div", {"class": "user-profile-bio"})
if div is None:
return ''
return div.find("div").text
def blog_link(soup, gh_link):
blog_tag = (soup.find("a", {"class": "u-url"}))
blog_link = ''
if blog_tag is None:
blog_link = gh_link
else:
blog_link = blog_tag['href']
return(blog_link)
def create_page():
username = input("Enter github username : ")
r = requests.get("https://github.com/" + username)
soup = BeautifulSoup(r.text, 'html.parser')
if r.status_code == 400:
print("Wrong username")
else:
member_info = {}
member_info['name'] = username
img = "http://avatars.githubusercontent.com/" + username
member_info['image'] = img
member_info['gh_link'] = 'https://github.com/' + username
full_name = soup.find("span", {"class": "vcard-fullname"}).text
member_info['full_name'] = full_name
member_info['blog'] = blog_link(soup, member_info['gh_link'])
member_info['bio'] = gh_bio(soup)
member_info['email'] = gh_email(soup)
member_info['position'] = 'Core Team Member' # input("Enter the position in the KOSS")
member_info['pinned_repos'] = pinned_repo_data(soup)
print(member_info)
x = render_jinja_html('templates', 'template.tmpl',
name = member_info['name'],
pinned_repos = member_info['pinned_repos'],
image = member_info['image'],
gh_link = member_info['gh_link'],
bio = member_info['bio'],
full_name = member_info['full_name'],
email = member_info['email'],
blog = member_info['blog'],
position = member_info['position']
)
with open("profiles/" + username + ".html", "w") as f:
f.write(x)
if __name__ == '__main__':
create_page()