<s> '''<STR_LIT>''' <EOL> from bbio import * <EOL> import json , urllib , os , urllib2 <EOL> class PhantStream ( object ) : <EOL> def __init__ ( self , public_key , private_key = "<STR_LIT>" , url = "<STR_LIT>" ) : <EOL> '''<STR_LIT>''' <EOL> self . public_key = str ( public_key ) <EOL> self . private_key = str ( private_key ) <EOL> self . url = url <EOL> self . url_read = os . path . join ( url , "<STR_LIT>" , self . public_key ) <EOL> self . url_send = os . path . join ( url , "<STR_LIT:input>" , self . public_key ) <EOL> def send ( self , samples ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> assert self . private_key != "<STR_LIT>" , "<STR_LIT>" <EOL> data = urllib . urlencode ( samples ) <EOL> headers = { <EOL> '<STR_LIT>' : self . private_key , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> req = urllib2 . Request ( self . url_send , data , headers ) <EOL> response = urllib2 . urlopen ( req ) <EOL> return response . read ( ) <EOL> except urllib2 . HTTPError as hpe : <EOL> print hpe <EOL> def getJSON ( self ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> f = urllib2 . urlopen ( self . url_read + "<STR_LIT>" ) <EOL> return f . read ( ) <EOL> except urllib2 . HTTPError as hpe : <EOL> print hpe <EOL> def getCSV ( self ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> f = urllib2 . urlopen ( self . url_read + "<STR_LIT>" ) <EOL> return f . read ( ) <EOL> except urllib2 . HTTPError as hpe : <EOL> print hpe <EOL> def getJSONinFile ( self , file_name ) : <EOL> '''<STR_LIT>''' <EOL> data = self . getJSON ( ) <EOL> with open ( file_name , '<STR_LIT:w>' ) as outfile : <EOL> json . dump ( data , outfile ) <EOL> def getCSVinFile ( self , file_name ) : <EOL> '''<STR_LIT>''' <EOL> csv = self . getCSV ( ) <EOL> fp = open ( file_name , "<STR_LIT:wb>" ) <EOL> fp . write ( csv ) <EOL> fp . close ( ) <EOL> def clear ( self ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> assert self . private_key != "<STR_LIT>" , "<STR_LIT>" <EOL> url_send = self . url_send + "<STR_LIT>" + self . private_key <EOL> f = urllib2 . urlopen ( url_send ) <EOL> return f . read ( ) <EOL> except urllib2 . HTTPError as hpe : <EOL> print hpe </s>
