Skip to content

Instantly share code, notes, and snippets.

@poguez
Created September 16, 2014 00:23
Show Gist options
  • Save poguez/f6667f660b5855456519 to your computer and use it in GitHub Desktop.
Save poguez/f6667f660b5855456519 to your computer and use it in GitHub Desktop.
Este es un script para sacar algunas métricas de ckan mediante API
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import urllib2
def ckan_action(call_action):
url = "http://datamx.io/api/3/action/" + call_action
organization_list = json.load(urllib2.urlopen(url))
return organization_list['result']
def main():
print "El número total de organizaciones son:" + str(len(ckan_action("organization_list")))
print "El número de total de paquetes son:" + str(len(ckan_action("current_package_list_with_resources")))
package_list_with_resources = ckan_action("current_package_list_with_resources")
print "El número total de paquetes secretos: " + str(len(filter( lambda x: x['private'] == True , package_list_with_resources)))
print "El número total de paquetes públicos: " + str(len(filter( lambda x: x['private'] == False , package_list_with_resources)))
secret_packages_list_with_resources = filter( lambda x: x['private'] == True , package_list_with_resources)
print "El número total de recursos en paquetes privados: " + str(sum(map(lambda x: len(x['resources']) , secret_packages_list_with_resources)))
public_packages_list_with_resources = filter( lambda x: x['private'] == False , package_list_with_resources)
print "El número total de recursos en paquetes públicos: " + str(sum(map(lambda x: len(x['resources']), public_packages_list_with_resources)))
#print "DICT \n" + str(ckan_action("current_package_list_with_resources"))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment