# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
import warnings

# +
from collections import deque
import re
import csv

import json
import requests
import pandas as pd
import numpy as np

# from selenium.webdriver import Firefox
# from selenium.webdriver.firefox.options import Options

# Change the parser below to try out different options
bs_parser = 'html.parser'
# bs_parser = 'lxml'
# bs_parser = 'lxml-xml'
# bs_parser = 'html5lib'

import bs4
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen

import time
# import warnings
# warnings.filterwarnings('ignore')
import github
# from config import token as token
from github import Github
# g = Github(token)

# reviews_pattern = re.compile("Reviews \((\d+)\)")
# item_code_pattern = re.compile("Item code: (\d+)")
# product_id_mapping = re.compile('&productId=(\d+)')

# selenium = None

# +
token = "your Github token"

g = Github(token)
# -

# ---

#

data = pd.read_csv('reposInfo_test.csv');data

data['UniqueContributorsNum']=float('NaN')


def getUniqueContributorsEachProject2(data1):
    dataset = data1.reset_index()
    Ucontributors=[]

    for i in range(len(dataset)):
        if dataset.repoNum[i]==0:
            Ucontributors.append(int(0))
            print(i)
            print("contributor is 0")
            data['UniqueContributorsNum'][i]=0
        elif dataset.repoNum[i]<30:
            print(i)
            n=[]
            
            for j in range(dataset.repoNum[i]):
                k=0
                
                
                status = True
                while status:
                    try:
                        g = Github(token)
                        n.append(g.get_user(dataset.Name[i]).get_repos()[j].get_contributors()[k].id)
                        k+=1
                        time.sleep(1)
                        '''
                        change sleep(45-60), if you run overnight
                        '''
                        #print(k)

                    except IndexError:
                        status=False
                g = 0
                # print(k)
                print(n)
            
            print('contributor count is {}'.format(len(list(set(n)))))
            Ucontributors.append(len(list(set(n))))
            data['UniqueContributorsNum'][i]=len(list(set(n)))
        else:
            print(i)
            print("Repos is larger than 30")
            pass
        if i ==(len(dataset)-1):
            print('finished_parsing!')
#         data.to_csv('Argo_CSV_2_progress.csv',index=False)



    for p in range(len(Ucontributors)):
        data['UniqueContributorsNum'][data1.index[dataset.index[p]]]=Ucontributors[p]
        print (Ucontributors[p])
    print("exported")
#     data.to_csv('Argo_CSV_2done.csv',index=False)

getUniqueContributorsEachProject2(data[300:305])



StarcoderdataJupyterScriptsDedupFiltered