Commits

Brad Montgomery committed 9b6ace9

Added a dirty hack to scrape the number of Forks/Queues for a repo

  • Participants
  • Parent commits 520f168

Comments (0)

Files changed (1)

File bitbucket/api.py

         url = self.base_url + 'followers/'
         return json.loads(self.bb.load_url(url))
 
+    def forks(self):
+        """ This is a dirty hack to get the number of Forks/Queues by scraping by src page """
+        url = 'https://bitbucket.org/%s/%s/src/' % (username, reponame)
+        response = urlopen(Request(url))
+        content = response.read()
+        # Dirty hack to find X in the first occurance of the string: "Forks/Queues (X)"
+        start_search = content.find('Forks/Queues')
+        open_paren_location = content.find('(', start_search)
+        close_paren_location = content.find(')', start_search)
+        num_forks = content[open_paren_location + 1:close_paren_location] # first part of the slice includes the paren
+        return int(num_forks)
+
     def __repr__(self):
         return '<Repository: %s\'s %s>' % (self.username, self.slug)