From 371d73484729fd74e71fe55c3d5424e6d7117ca5 Mon Sep 17 00:00:00 2001 From: codesleep-Beperfect Date: Fri, 24 Feb 2023 01:16:04 +0530 Subject: [PATCH] get_contributions() function completed --- documentation.md | 1 + src/scrape_up/github/respository.py | 17 ++++++++++++++++- src/scrape_up/github/users.py | 10 ++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/documentation.md b/documentation.md index 82961adf..74217e81 100644 --- a/documentation.md +++ b/documentation.md @@ -62,6 +62,7 @@ repository = github.Repository(username="nikhil25803", repository_name="scrape-u | Methods | Details | |---|-------------------------------------------------------------| | `.fork_count()` | Returns the number of forks of a repository. | +| `.get_contributors()` | Returns the number of contributors of a repository. | | `.topics()` | Returns the topics of a repository. | | `.pull_requests()` | Returns the number of pull requests opened in a repository. | | `.tags()` | Returns the last ten tags of a repository. | diff --git a/src/scrape_up/github/respository.py b/src/scrape_up/github/respository.py index 9a79a76a..529d06ee 100644 --- a/src/scrape_up/github/respository.py +++ b/src/scrape_up/github/respository.py @@ -97,6 +97,7 @@ def topics(self): try: topics = data.find_all(class_="topic-tag topic-tag-link") allTopics = [] + print(allTopics) for item in topics: allTopics.append(item.text) return allTopics # return list of topics @@ -120,6 +121,7 @@ def star_count(self): message = "Oops! No Stars found" return message + def pull_requests(self): """ Get the number of pull requests opened in a repository. @@ -128,7 +130,7 @@ def pull_requests(self): try: pull_requests = ( data.find_all(class_="UnderlineNav-item mr-0 mr-md-1 mr-lg-3")[2] - .find_all("span")[1] + .find_all("span")[1] .text.strip() ) return pull_requests @@ -228,3 +230,16 @@ def get_issues(self): except: message = "Failed to fetch list of issues" return message + + def get_contributors(self): + data= self.__scrape_page() + + try: + contributors = data.find_all("a", href=f"/{self.username}/{self.repository}/graphs/contributors") + contributor=[] + for it in contributors: + contributor.append(it.get_text()) + return contributor[0].strip() + except: + message="Oops! No contributors found" + return message diff --git a/src/scrape_up/github/users.py b/src/scrape_up/github/users.py index 8e955ad0..bfdd37ff 100644 --- a/src/scrape_up/github/users.py +++ b/src/scrape_up/github/users.py @@ -32,6 +32,7 @@ def following(self): page = self.__scrape_page() try: following=page.find_all(class_="text-bold color-fg-default") + # print(page.find_all("span")) return following[1].text except: message = f"{self.username} not found !" @@ -251,3 +252,12 @@ def get_following_users(self): except: message = f"Following users not found for username {self.username}" return message + def company(self): + page=self.__scrape_following_page() + try: + cmp=page.find(class_="Link--primary") + print(cmp.text) + # print(page.find_all("a")) + except: + message=f"Following users not found for username {self.username}" +