Last active
December 20, 2015 11:59
-
-
Save bsullins/6127012 to your computer and use it in GitHub Desktop.
bit.ly script to get clicks by country by day for popular links
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 sys | |
import bitly_api | |
import os | |
import datetime | |
from datetime import date | |
from config import config | |
import time | |
#connect to bitly | |
conn_btly = bitly_api.Connection(access_token=config['ACCESS_TOKEN']) | |
#get links | |
pop_links = conn_btly.user_popular_links(limit=5) | |
print 'got links!' | |
#links loop | |
for pop_link in pop_links: | |
print "**** Processing: " + pop_link['link'] + " ***" | |
link = conn_btly.link_info(pop_link['link']) | |
print link | |
#get clicks | |
clicks = conn_btly.link_clicks(pop_link['link'], rollup=False, unit="day") | |
print "got clicks for ", pop_link['link'] | |
#clicks loop | |
for click in clicks: | |
print "*** processing " + pop_link['link'] + " for " + time.strftime("%m/%d/%Y", time.localtime(click['dt'])) | |
#get country clicks | |
#country_click = conn_btly._call_oauth2_metrics("v3/link/countries", {'link': pop_link, 'unit_reference_ts': click['dt']}, rollup=False, unit='day') | |
country_click = conn_btly.link_countries(pop_link['link'], unit_reference_ts=click['dt'], rollup=False, unit='day') | |
print country_click | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output:
File "build\bdist.win32\egg\bitly_api\bitly_api.py", line 185, in link_countries
data = self._call_oauth2_metrics("v3/link/countries", params, **kwargs)
TypeError: _call_oauth2_metrics() got an unexpected keyword argument 'unit_reference_ts'