Initial
This commit is contained in:
parent
b780c6657c
commit
03a33e7641
79
sc_real_reach.py
Normal file
79
sc_real_reach.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import requests
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
MAX_REQUESTS=15000
|
||||||
|
CLIENT_ID="5db3773ba0ba11c7398dad1f61011bdb"
|
||||||
|
|
||||||
|
def setup_logger(name):
|
||||||
|
_ch = logging.StreamHandler()
|
||||||
|
_ch.setLevel("DEBUG")
|
||||||
|
_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
_ch.setFormatter(_formatter)
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
logger.addHandler(_ch)
|
||||||
|
logger.setLevel("DEBUG")
|
||||||
|
logger.debug("Logger initialized")
|
||||||
|
return logger
|
||||||
|
|
||||||
|
def log(msg):
|
||||||
|
logger.info(msg)
|
||||||
|
|
||||||
|
|
||||||
|
logger = setup_logger(__name__)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('accounts', nargs='+', help='Accounts ID to check')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
accounts = args.accounts
|
||||||
|
|
||||||
|
followers = {}
|
||||||
|
|
||||||
|
log("Fetching followers")
|
||||||
|
|
||||||
|
# fetch followers
|
||||||
|
i=0
|
||||||
|
for account in accounts:
|
||||||
|
log("Fetching followers for account "+account)
|
||||||
|
# followers[i] = [1,2,3,4]
|
||||||
|
followers[i] = get_acct_followers(account)
|
||||||
|
log("Got "+str(len(followers[i]))+" followers")
|
||||||
|
i+=1
|
||||||
|
|
||||||
|
# calculate duplicates
|
||||||
|
log("Calculating duplicates between acct 1 and 2")
|
||||||
|
common_followers = set(followers[0]).intersection(followers[1])
|
||||||
|
log(str(len(common_followers))+" in common")
|
||||||
|
|
||||||
|
for j in range(2,len(accounts)-1):
|
||||||
|
log("Calculating duplicated between common_followers and "+j)
|
||||||
|
|
||||||
|
def get_acct_followers(acct):
|
||||||
|
followers = []
|
||||||
|
acct = str(acct)
|
||||||
|
# info req
|
||||||
|
r = requests.get("https://api.soundcloud.com/users/"+acct+"?client_id="+CLIENT_ID).json()
|
||||||
|
followers_count = r["followers_count"]
|
||||||
|
|
||||||
|
# 1st req
|
||||||
|
r = requests.get("https://api.soundcloud.com/users/"+acct+"/followers?page_size=200&client_id="+CLIENT_ID).json()
|
||||||
|
for follower in r["collection"]:
|
||||||
|
followers.append(follower["id"])
|
||||||
|
|
||||||
|
log("{0}/{1} done ({2}%)...".format(len(followers), followers_count, len(followers)/followers_count*100))
|
||||||
|
|
||||||
|
# next reqs
|
||||||
|
while r["next_href"]:
|
||||||
|
r = requests.get(r["next_href"]).json()
|
||||||
|
for follower in r["collection"]:
|
||||||
|
followers.append(follower["id"])
|
||||||
|
log("{0}/{1} done ({2}%)...".format(len(followers), followers_count, len(followers)/followers_count*100))
|
||||||
|
|
||||||
|
log("Done!")
|
||||||
|
|
||||||
|
return followers
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user