Skip to content

Commit

Permalink
Merge pull request matryer#1492 from longpdo/master
Browse files Browse the repository at this point in the history
Fix social_media_stats.1h.py
  • Loading branch information
matryer authored Dec 11, 2020
2 parents 456b137 + a53cf29 commit 14b69ed
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions Web/Instagram/social_media_stats.1h.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Icons made by Freepik (https://www.flaticon.com/authors/freepik)
#
# <bitbar.title>Social Media Stats</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.version>v1.1</bitbar.version>
# <bitbar.author>Long Do</bitbar.author>
# <bitbar.author.github>longpdo</bitbar.author.github>
# <bitbar.desc>Shows YouTube subscribers, Facebook likes, Instagram and Twitter followers.</bitbar.desc>
# <bitbar.desc>Shows YouTube subscribers, Facebook likes and Instagram followers.</bitbar.desc>
# <bitbar.image>https://github.com/longpdo/bitbar-plugins-custom/raw/master/images/social_media_stats.png</bitbar.image>
# <bitbar.dependencies>python3,beautifulsoup4,requests</bitbar.dependencies>
# <bitbar.abouturl>https://github.com/longpdo/bitbar-plugins-custom</bitbar.abouturl>
# <bitbar.abouturl>https://github.com/longpdo/bitbar-plugins-custom/blob/master/README.md#social-media-stats</bitbar.abouturl>
#
# by longpdo (https://github.com/longpdo)

Expand All @@ -23,14 +23,12 @@
# e.g. youtube_url = ''
instagram_url = 'https://www.instagram.com/belle.dara'
facebook_url = 'https://facebook.com/Cristiano'
twitter_url = 'https://twitter.com/billieeilish'
youtube_url = 'https://www.youtube.com/channel/UCtxCXg-UvSnTKPOzLH4wJaQ'


# Base64 Colored Icons
instagram_icon = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAWQAAAFkBqp2phgAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAJESURBVDiNjZGxaxRREMZ/s7cPRbJ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kVeosuSSXBrqnqWkBAzWC6CeKVLF3BJP+MmK/MV4oIYySPisYFSOkWd7guAG8FXkXsBI/BVxB/5DN4EKzPCO5ZZ0yKzdX1kBFMMqqiablks2E6/S1BdToBzOdst6xWVEW3m7FrzBndSXPTMJuxWNAV3TpBU5xwXQ/ZwnPGvli9bYe0sO8P6XDGDRyCpxQRpFTjHlc/uDxqeMfHUfe8iGjTv3/jNy6Ep9IgbWhqAAAAAElFTkSuQmCC'


Expand All @@ -44,7 +42,7 @@ def get_instagram_followers():

if request.status_code == 200:
soup = BeautifulSoup(request.text, 'html.parser')
data = json.loads(soup.find('script', type='application/ld+json').text)
data = json.loads(soup.find('script', type='application/ld+json').contents[0])
result = data['mainEntityofPage']['interactionStatistic']['userInteractionCount']
result = '{0:,}'.format(int(result))
result = result.replace(',', '.')
Expand All @@ -66,21 +64,6 @@ def get_facebook_likes():
print(result + ' | image=' + facebook_icon)


def get_twitter_followers():
if twitter_url == '':
return

request = requests.get(twitter_url)
if request.status_code != 200:
return

if request.status_code == 200:
soup = BeautifulSoup(request.text, 'html.parser')
data = soup.find('li', {'class': 'ProfileNav-item--followers'})
result = re.sub('[^0-9.]+', '', str(data.find('a')['title']))
print(result + ' | image=' + twitter_icon)


def get_youtube_subscribers():
if youtube_url == '':
return
Expand All @@ -91,15 +74,15 @@ def get_youtube_subscribers():

if request.status_code == 200:
soup = BeautifulSoup(request.text, 'html.parser')
data = soup.find('span', {'class': 'subscribed'})
result = re.sub('[^0-9.,MK]+', '', str(data['aria-label']))
if result[-1] == '.':
result = result[:-1]
print(result + ' | image=' + youtube_icon)
script = soup.findAll('script')[27].contents[0]
script_content = script[31:-110]
data = json.loads(script_content)
result = data['header']['c4TabbedHeaderRenderer']['subscriberCountText']['runs'][0]['text']
result_filtered = re.sub('[^0-9.]+', '', result)
print(result_filtered + ' | image=' + youtube_icon)


if __name__ == '__main__':
get_instagram_followers()
get_facebook_likes()
get_twitter_followers()
get_youtube_subscribers()

0 comments on commit 14b69ed

Please sign in to comment.