Created
October 11, 2016 02:43
-
-
Save rodorgas/fb02c792784f01b60594491261860131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3 | |
import requests | |
import re | |
CHROME_URL = 'https://chrome.google.com/webstore/detail/burlesco/lpamnanbhgpgkkpmilbifikmikfghlgh' | |
FIREFOX_URL = 'https://addons.mozilla.org/pt-BR/firefox/addon/burlesco/' | |
OPERA_URL = 'https://addons.opera.com/pt-br/extensions/details/burlesco/?display=pt' | |
def count_site(name, url, regex): | |
page = requests.get(url).text | |
users = re.search(regex, page).group(1) | |
users = users.replace(',', '') | |
users = int(users) | |
return users | |
def count_all(): | |
sites = [ | |
('chrome', (CHROME_URL, r'"([0-9,\.]+) users')), | |
('firefox', (FIREFOX_URL, r'([0-9,\.]+) usuários')), | |
('opera', (OPERA_URL, r'Downloads.+?([0-9,\.]+)')), | |
] | |
total = 0 | |
users_sites= [] | |
for site in sites: | |
users_sites.append(count_site(site[0], *site[1])) | |
total = sum(users_sites) | |
print(' + '.join(map(str, users_sites)) + ' = ' + str(total)) | |
return total | |
if __name__ == '__main__': | |
print('Total: ' + str(count_all())) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment