10 from serverportfolio
import GlobalDicts
20 if type(stock) == types.ListType :
23 elif type(stock) == types.StringType :
26 list_stock.append( stock )
29 elif type(stock) == types.DictType :
31 list_stock.append( stock )
46 elif type(action) == types.StringType:
59 raise PortfolioError(
"Error in action, not a valid EAction\nOriginal error, %s : %s" % (sys.exc_info()[0].__name__, ex) )
62 self.logger.critical(
"General Exception in stringToEAction, SHOULD NOT HAPPEN !!")
67 raise PortfolioError(
"Cannot convert %s, type: %s, to a valid EAction" % (action,
type(action)) )
81 return datetime.datetime.fromtimestamp( ts ).strftime(
'%Y-%m-%d %H:%M:%S')
88 t1 = time.mktime(datetime.datetime.strptime(str_date,
"%Y-%m-%d %H:%M:%S").timetuple())
193 shift_str=shift_str * shift_nb
195 if (
type(dict) == types.DictType):
199 for key,value
in dict.iteritems():
202 if (
type(value) == types.DictType ) | (
type(value) == types.ListType ):
205 if key ==
'list_dict':
209 out_str += shift_str + key +
' : '
222 out_str +=
'\n======= ' + value +
'\n'
226 out_str += shift_str + key +
' : '
227 out_str += str(value)
232 elif type(dict) == types.ListType :
236 type_elem =
type( dict[0] )
243 if type_elem == types.DictType :
251 out_str += shift_str +
', '.join(str(x)
for x
in dict)
259 if __name__ ==
"__main__":
265 dict2 = {
'symbol':
'CAC40',
'InstValue ': {
'volume': 898.0,
'plusbas': 4224.34,
'state':
'OPEN',
'ouverture': 4294.05,
'variation': -0.22,
'plushaut': 4311.0,
'time':
'14:36:00',
'date':
'2015-01-02',
'value': 4263.39}}
267 dict3 = [{
'symbol':
'"GSZ.PA"',
'list_dict': [
'Fundamental'],
'Fundamental': {
'other': {},
'MarketCapitalization':
'45.753B',
'BVPS': 21.442,
'SharesOwned':
'-',
'PriceBook': 0.9,
'PEG':
'N/A\r',
'DividendYield': 1.67,
'PER':
'N/A'}}]
270 dict4 = [{
'symbol':
'"GSZ.PA"',
'list_dict': [
'Fundamental'],
'Fundamental': {
'other': {},
'MarketCapitalization':
'45.753B',
'BVPS': 21.442,
'SharesOwned':
'-',
'PriceBook': 0.9,
'PEG':
'N/A\r',
'DividendYield': 1.67,
'PER':
'N/A'}},{
'symbol':
'"GSZ2.PA"',
'list_dict': [
'Fundamental'],
'Fundamental': {
'other': {
'subother':
'toto',
'subother2':
'toto2'},
'MarketCapitalization':
'45.753B',
'BVPS': 21.442,
'SharesOwned':
'-',
'PriceBook': 0.9,
'PEG':
'N/A\r',
'DividendYield': 1.67,
'PER':
'N/A'}}]
280 print "\n nice formatting"
Base class of the custom exceptions.
def pretty_dict
Nice string output of python dictionary or list of dictionaries.
def to_list
Always return a list of strings.
def string_to_timestamp
opposite all seems to be in local time, like the rest of the application (1970-01-01 00:00:00 = -3600...
Enumeration for the action to be performed by the parser.
Define custom and specific exceptions for the complete package.
def stringToEAction
Always return a valid EAction from an Eaction or an EAction.name.
def timestamp_to_string
Time function.