Created
February 16, 2018 04:29
Star
You must be signed in to star a gist
This will produce an SQL to query Google BigQuery for a certain author packages downloads monthly statistics.
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
"""This will produce an SQL to query Google BigQuery | |
for a certain author packages downloads monthly statistics. | |
""" | |
try: | |
import xmlrpclib | |
except ImportError: | |
import xmlrpc.client as xmlrpclib | |
AUTHOR = 'idlesign' | |
DATE_FILTER = '2018*' | |
SQL = ''' | |
SELECT file.project AS project, FORMAT_TIMESTAMP("%%Y-%%m", timestamp) AS month, COUNT(*) AS downloads | |
FROM `the-psf.pypi.downloads%(date)s` | |
WHERE file.project IN (%(projects)s) | |
GROUP BY project, month | |
ORDER BY project, month | |
''' | |
rpc = xmlrpclib.ServerProxy('https://pypi.python.org/pypi') | |
packages = sorted((pkg for role, pkg in rpc.user_packages(AUTHOR))) | |
sql = SQL % { | |
'projects': '"%s"' % '", "'.join(packages), | |
'date': DATE_FILTER, | |
} | |
print(sql.replace('\n', ' ').strip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment