-
-
Save amgalan-sp/74c7388ac459173c52c8d0bc1b87eee6 to your computer and use it in GitHub Desktop.
WaterloggedOfficialStatistics created by amgalan_sp - https://repl.it/@amgalan_sp/WaterloggedOfficialStatistics
This file contains hidden or 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
| token=bcd583b3edfc9bc674113f41fca35be194e62def |
This file contains hidden or 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
| import requests | |
| import os | |
| from dotenv import load_dotenv | |
| def get_link(long_url, api_token): | |
| url = 'https://api-ssl.bitly.com/v4/bitlinks' | |
| data = {"long_url": "{}".format(long_url)} | |
| headers = {"Authorization": "Bearer {}".format(api_token)} | |
| response = requests.post(url, headers=headers, json=data) | |
| return response.json()['link'] | |
| def get_stat(formatted_url, api_token): | |
| payload= { | |
| "unit": "day", | |
| } | |
| url = 'https://api-ssl.bitly.com/v4/bitlinks/{}/clicks/summary'.format(formatted_url) | |
| headers = {"Authorization": "Bearer {}".format(api_token)} | |
| response = requests.get(url, headers=headers, params=payload) | |
| return response.json() | |
| def get_check_bit(formatted_url, api_token): | |
| payload= { | |
| } | |
| url = 'https://api-ssl.bitly.com/v4/bitlinks/{}'.format(formatted_url) | |
| headers = {"Authorization": "Bearer {}".format(api_token)} | |
| response = requests.get(url, headers=headers, params=payload) | |
| return response.status_code | |
| #def get_check_long_url(url): | |
| # response = requests.get(url) | |
| # return response.status_code | |
| if __name__ == "__main__": | |
| api_token = os.getenv("token") | |
| input_url = input() | |
| for parts in input_url.split('//'): | |
| formatted_url = parts | |
| if get_check_bit(formatted_url, api_token) == 200: | |
| bit_link = get_stat(formatted_url, api_token)["total_clicks"] | |
| print("Количество переходов:", bit_link) | |
| else: | |
| long_url = 'https://' + '{}'.format(formatted_url) | |
| print(get_link(long_url, api_token)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment