Skip to content

Instantly share code, notes, and snippets.

@marcoi
Forked from bootandy/query_nowa.py
Created December 4, 2012 11:48
Show Gist options
  • Save marcoi/4202988 to your computer and use it in GitHub Desktop.
Save marcoi/4202988 to your computer and use it in GitHub Desktop.
how2 query ingenia/nowa in python
import requests
import pymongo
import json
# Requires crunchbase data loaded by this gist: https://gist.github.com/4202360
NOWA_API_KEY = 'NOWA_KEY'
NOWA_URL = 'http://ingeniapi.com/train'
db_connection = pymongo.Connection('localhost', 27017)
db = db_connection['tc']
def main():
load_companies()
def load_companies():
tagged_companies = db.tagged_companies.find()
for company in tagged_companies:
if company['tag_list']:
query_nowa(company)
def query_nowa(company):
print 'analyzing ' + company['name']
tags = [t.strip() for t in company['tag_list'].split(",")]
payload = {
'auth_token': NOWA_API_KEY,
'text': company['overview'],
'tag_sets': json.dumps({'tc_category_code': [company['category_code']], 'tc_tags': tags})
#'tags': json.dumps(tags),
}
#print payload
r = requests.post(NOWA_URL, data=payload)
print r.text
if "status" in r.json and not r.json["status"] == 'okay':
print "******** FAIL ********"
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment