Skip to content

Instantly share code, notes, and snippets.

@shiplunc
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiplunc/38d895470afffe63f7fb to your computer and use it in GitHub Desktop.
Save shiplunc/38d895470afffe63f7fb to your computer and use it in GitHub Desktop.
Generate Publishers list by month
from datetime import datetime
from analytics import tasks
from analytics.reporting import getty_reporter as gr
from theplatform.newscred.models import User
import calendar
import sys
def get_publisher_of_month(credentials, year, month):
_, end_day = calendar.monthrange(year, month)
start_date = datetime(year, month, 1, 0, 0, 0)
end_date = datetime(year, month, end_day, 23, 59, 59)
usage_reporter = gr.GettyUsageReporter(credentials, start_date, end_date)
return usage_reporter.get_publisher_list()
if __name__ == '__main__':
publishers = get_publisher_of_month(tasks.ThinkStockCredentials(),
int(sys.argv[1]),
int(sys.argv[2]))
for access_key, count in publishers:
users = User.objects.filter(access_key__in=[access_key])
for user in users:
print "%s\t%40s\t%s" % (user.access_key, user.name, count)
@figpope
Copy link

figpope commented May 12, 2015

Hmm, okay, you don't need to manually specify an end date, I believe it defaults to the last day of the month provided. Also, you're only querying PPI images here by using the ThinkStockCredentials.

@figpope
Copy link

figpope commented May 12, 2015

Scratch that, seems like the changes to the class removed that feature.

@shiplunc
Copy link
Author

The problem was found on actually PPI usage. Not sure about the CPV usage. Jenn S. can confirm that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment