-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
148 lines (114 loc) · 4.33 KB
/
utils.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
import requests
from bs4 import BeautifulSoup
param = 'shrutigupta5555'
def getavatar(param):
url = "https://devpost.com/" + param
res = requests.get(url)
soup = BeautifulSoup(res.text, features="html.parser")
avatarurl = soup.find('img', attrs = {"class": "user-photo"})
# print(avatarurl)
return avatarurl['src']
def getdisplayname(param):
url = "https://devpost.com/" + param
# print(url)
res = requests.get(url)
soup = BeautifulSoup(res.text, features="html.parser")
name = soup.find('h1', attrs = {"id": "portfolio-user-name"}).getText().split("\n")[1].lstrip()
return name
def getTotalProjects(param):
url = "https://devpost.com/" + param
n = getdisplayname(param)
# print(url)
res = requests.get(url)
soup = BeautifulSoup(res.text, features="html.parser")
pagecountul = soup.find('ul', attrs = {'class': 'pagination'})
if pagecountul:
pages = len(pagecountul.find_all('li')) - 2
else:
pages = 1
memberCount = {}
memberLink = {}
projectlist = []
for i in range(pages):
x = i + 1
url = "https://devpost.com/" + param + "?page=" + str(x)
# print(url)
res = requests.get(url)
soup = BeautifulSoup(res.text)
try:
projectsDiv = soup.find_all('div', attrs = {"class": "gallery-item"})
except:
projectsDiv=[]
for projects in projectsDiv:
p = {}
projecturl = projects.find('img', attrs = {"class": "software_thumbnail_image"})['src']
projecttitleDiv = projects.find('div', attrs = {"class": "software-entry-name"})
projecttitle = projecttitleDiv.find('h5').getText().strip()
like = projects.find('span', attrs = {'class': 'like-count'}).getText().strip()
teamDiv = projects.find('div', attrs = {'class': 'members'})
tt = teamDiv.find_all('span')
p['projecturl'] = projecturl
p['like'] = like
p['projecttitle'] = projecttitle
teamlist = []
for team in tt:
name = team.find('img')['alt']
turl = team['data-url']
id = turl.split("/")[-1]
if name != n:
teamlist.append(name)
if id in memberCount:
memberCount[id] += 1
else:
memberCount[id] = 1
if id not in memberLink:
memberLink[id] = name
p['team'] = teamlist
projectlist.append(p)
# print(projectlist)
return projectlist, memberCount, memberLink
def getfriendslocation(param):
projectlist, memberCount, memberLink = getTotalProjects(param)
loc = {}
for key in memberLink.keys():
new_url = "https://devpost.com/" + key
res = requests.get(new_url)
soup = BeautifulSoup(res.text, features="html.parser")
cl = soup.find('ul', attrs = {'id': 'portfolio-user-links'})
location = cl.find('li')
flag = soup.find('span', attrs = {'class':'ss-location'})
if location and flag:
curr = location.getText().strip()
else:
curr = ""
loc[key] = curr
return loc
def getfollowers(param):
url = "https://devpost.com/" + param
res = requests.get(url)
soup = BeautifulSoup(res.text)
try:
followers = soup.find('li', attrs = {"data-followers-tab": "true"}).getText().strip().split(" ")[0]
except:
followers = 0
# print(followers)
return followers
# getfollowers("aakzsh")
def winnerandparticipated(param):
url = "https://devpost.com/"+param+"/achievements"
# print(url)
res = requests.get(url)
soup = BeautifulSoup(res.text)
try:
participatedDiv = soup.find('div', attrs = {'id': 'achievement_3'})
participated = participatedDiv.find('h5').getText().strip().split(" ")[-1]
except:
participated = 0
try:
winnerDiv = soup.find('div', attrs = {'id': 'achievement_5'})
winner = winnerDiv.find('h5').getText().strip().split(" ")[-1]
except:
winner = 0
return winner, participated
# getavatar(param)
# print(getfriendslocation(param))