Skip to content

Instantly share code, notes, and snippets.

import json
import requests
class MyClass(GeneratedClass):
# ...
def onInput_picture(self, p):
'''
Identify objects in an image by calling an external microservice
def getWikipediaURL(entity, exact_match_only = False):
# wikipedia search URL
url = 'https://en.wikipedia.org/w/index.php?{}'. \
format(urllib.urlencode({'search': entity},'utf-8'))
# send search request
r = requests.head(url)
if r.status_code == 200:
if exact_match_only:
# search term was not found; return nothing
return None
{u'count': 2,
u'relevance': 0.916055,
u'text': u'Neil deGrasse Tyson',
u'type': u'Person'}
response = nlu.analyze(html = summary, \
features = [Features.Categories(), \
Features.Entities(), \
Features.Keywords()], \
language = language)
'author': u'WNYC Studios',
'author_detail': {'name': u'WNYC Studios'},
'authors': [{'name': u'WNYC Studios'}, {'name': u'WNYC Studios'}],
'content': [{'base': u'http://feeds.wnyc.org/radiolab',
'language': None,
'type': u'text/plain',
'value': u"Where the Sun Don't Shine"},
'summary_detail': {'base': u'http://feeds.wnyc.org/radiolab',
'language': None,
'type': u'text/html',
def getWikipediaURL(entity, redirect_match_only = False):
'''
input: entity - wikipedia search term
input: redirect_match_only - True, False
output: returns the wikipedia page for 'entity' (if found) or, if not found, the wikipedia search page (redirect_match_only == False)
or None (redirect_match_only == True)
'''
url = 'https://en.wikipedia.org/w/index.php?{}'.format(urllib.urlencode({'search': entity},'utf-8'))
r = requests.head(url)
if r.status_code == 302:
title publication_month views reads read_ratio fans
Querying Your PouchDB Database with SQL 2017-07 66 39 59 0
Generating Poems: A Way with Words and Code 2017-07 178 95 53 11
A Depth-First Look at Watson Conversation + Gremlin + JanusGraph 2017-07 187 85 45 10
CouchDB Writes: Piecemeal, Bulk, or Batch? 2017-07 116 59 51 8
title author url tags
Querying Your PouchDB Database with SQL GB https://medium.com/ibm-watson-data-lab/querying-your-pouchdb-database-with-sql-c2e43c21b7ce JavaScript,Web Development,Pouchdb,Couchdb,Cloudant
Generating Poems: A Way with Words and Code NM https://medium.com/ibm-watson-data-lab/generating-poems-a-way-with-words-and-code-885e85afac4b Cognitive Computing,Ibm Bluemix,Ibm Watson,Python Flask,Postgres
A Depth-First Look at Watson Conversation + Gremlin + JanusGraph MW https://medium.com/ibm-watson-data-lab/a-depth-first-look-at-watson-conversation-gremlin-janusgraph-42be16335eef Janusgraph,Ibm Watson,Web Development,Graph Database,Cognitive Computing
CouchDB Writes: Piecemeal, Bulk, or Batch? GB https://medium.com/ibm-watson-data-lab/couchdb-writes-piecemeal-bulk-or-batch-8bf8ef9314e0 Couchdb,Cloudant,Database,Web Development,Ibm Bluemix
my_df.printSchema()
root
|-- ...
|-- ACCOUNT_ID: string (nullable = true)
|-- ADDRESS: string (nullable = true)
|-- ...
@ptitzler
ptitzler / pyspark_sql_data_load
Last active May 19, 2017 13:27
PySpark SQL load snippet
jdbcurl = 'jdbc:db2://MYHOST:MYPORT/MYDATABASE'
props = {}
props['user'] = 'MYUSERID'
props['password'] = 'MYPASSWORD'
my_df = sqlContext.read.jdbc(jdbcurl, 'MYSCHEMA.MYTABLE', properties=props)
my_df.cache()