-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitly.py
35 lines (30 loc) · 1.15 KB
/
bitly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import requests
import json
import os
class Bitly:
def __init__(self, token):
self.token = token
self.headers={'Authorization': 'Bearer ' + token}
self.user_url = 'https://api-ssl.bitly.com/v4/user'
self.bitlink_url='https://api-ssl.bitly.com/v4/groups/{}/bitlinks'
self.clicks_url ='https://api-ssl.bitly.com/v4/bitlinks/{}/countries'
def group_getter(self):
try:
response = requests.get(self.user_url, headers = self.headers)
return json.loads(response.text)
except Exception as e:
print(e)
def bitlink_getter(self,group):
full_bitlink_url = self.bitlink_url.format(group)
try:
response = requests.get( full_bitlink_url, headers = self.headers)
return json.loads(response.text)
except Exception as e:
print(e)
def clicks_getter(self, bitlink):
full_clicks_url = self.clicks_url.format(bitlink)
try:
response = requests.get( full_clicks_url, headers = self.headers)
return json.loads(response.text)
except Exception as e:
print(e)