Skip to content

Instantly share code, notes, and snippets.

@Widdershin
Last active December 20, 2015 22:49
Show Gist options
  • Save Widdershin/6207931 to your computer and use it in GitHub Desktop.
Save Widdershin/6207931 to your computer and use it in GitHub Desktop.
A wrapper for Chocolatey's cinst, to allow searching. Usage: ci (search/package name)
"""
ci.py
A wrapper for Chocolatey's cinst, to allow searching.
Usage: ci (search/package name)
"""
import os
import sys
import urllib
from BeautifulSoup import BeautifulSoup
request = sys.argv[1]
URL = "http://chocolatey.org/packages?q={}".format
REGEX = r'.* cinst (.*)'
choc_page = urllib.urlopen(URL(request))
soup = BeautifulSoup(choc_page.read())
packages = soup.findAll('code')
if len(packages) > 0:
for package in packages:
result = package.text.split()[-1]
print result
if result.lower().strip() == request.lower().strip():
print "Package found, running cinst."
os.system("cinst {}".format(request))
else:
print "No packages found."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment