-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest_top10.py
36 lines (29 loc) · 976 Bytes
/
request_top10.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
import requests
from bs4 import BeautifulSoup
def get_data(driver, username):
try:
url = "https://hacktoberfest.digitalocean.com/stats/%s" % username
req = requests.get(url)
assert req.ok
driver.get(url)
html_string = driver.page_source
parser = BeautifulSoup(html_string, 'lxml')
image = parser.find('img', {'class': 'userstats--card-image'})
name = parser.find('h2')
progress = parser.find('span', {'data-js': 'userPRCount'})
return {
"nama": name.text,
"foto": image.get('src'),
"progress": progress.text,
"detail": url
}
except Exception:
return {
"nama": "%s - Akun belum dibuat" % username,
"foto": "https://bestbath.com/wp-content/uploads/2016/01/image-coming-soon.png",
"progress": "0",
"detail": "https://hacktoberfest.digitalocean.com/stats/%s" % username
}
def post_data(data):
req = requests.post('localhost:5000/broadcast-top10', data=data)
print(req.json())