Skip to content

Instantly share code, notes, and snippets.

@circus2271
Last active May 7, 2019 15:10
Show Gist options
  • Save circus2271/5fbb18f3d64e1c8efaac9040581a8071 to your computer and use it in GitHub Desktop.
Save circus2271/5fbb18f3d64e1c8efaac9040581a8071 to your computer and use it in GitHub Desktop.
Script for finding common following of your following | Soundcloud
from urllib.request import urlopen
from bs4 import BeautifulSoup
name = input('Type your soundcloud username: ')
def getYourFollowingPage(yourUsername):
followingPageUrl = 'https://soundcloud.com/' +\
yourUsername + '/following'
response = urlopen(followingPageUrl)
page = response.read()
return page
def getHrefs(username=name):
page = getYourFollowingPage(username)
soup = BeautifulSoup(page, 'html.parser')
allLinksOnPage = soup.find_all('a')
clearLinks = []
for link in allLinksOnPage:
if ('itemprop' in link.attrs):
dirtyHref = link.get('href')
cleanHref = dirtyHref[1:]
clearLinks.append(cleanHref)
return clearLinks[1:]
def findFriendsOfFriends(username=name):
result = []
initial = getHrefs(username=name)
for link in initial:
result.append(getHrefs(link))
result.append(initial)
return result
def findCommonFriendsOfFriends(username=name):
dict = {}
arr = findFriendsOfFriends()
for row in arr:
for href in row:
if href != username:
if href not in dict:
dict[href] = 1
else:
dict[href] += 1
return dict
#print(findCommonFriendsOfFriends())
def greaterThenOne(username=name):
result = []
for key, value in findCommonFriendsOfFriends().items():
if value > 1:
result.append(key + ' appears ' + str(value) + ' times')
arr = findFriendsOfFriends()
for row in arr:
for href in row:
if href != username:
if href not in dict:
dict[href] = 1
else:
dict[href] += 1
return dict
#print(findCommonFriendsOfFriends())
def greaterThenOne(username=name):
result = []
for key, value in findCommonFriendsOfFriends().items():
if value > 1:
result.append(key + ' appears ' + str(value) + ' times')
if len(result) == 0:
result.append('There are no first step common friends in this network')
return result
def makeSomeOutput(username=name):
for string in greaterThenOne():
print(string)
makeSomeOutput()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment