__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import pandas as pd
  2. import numpy as np
  3. import transport
  4. import datetime
  5. import io
  6. import json
  7. import requests
  8. def subscribe (self,**args) :
  9. """
  10. This function will subscribe an email to a given service (report,notification). If already susbcribed no further action will be performed
  11. :email provide a valid email for the free plan. Upgrades will be done via the website
  12. :id service identifier accepted values are GOOGLE_DRIVE,DROPBOX,BOX,ONE_DRIVE
  13. """
  14. url = "https://the-phi.com/store/smart-top/subscribe"
  15. SERVICES=['GOOGLE','DROPBOX','BOX','ONE_DRIVE']
  16. if args['id'].upper() in SERVICES :
  17. data = {"email":args['email']}
  18. requests.post(url,data=data)
  19. pass
  20. def log(**args) :
  21. """
  22. This function will write to a designated location provided a set of inputs
  23. :store mongo,file,couch,api
  24. """
  25. #
  26. # @TODO: Provide facility to write to a given cloud store (google,one-drive ...)
  27. # This will have to be supported by some sort of subscription service
  28. #
  29. STORE_MAP = {"mongo":"MongoWriter","disk":"DiskWriter","couch":"CouchWriter",'sqlite':'SQLiteWriter'}
  30. if 'store' not in args :
  31. _id = 'console'
  32. else:
  33. _id = 'disk' if args['store'] == 'file' else args['store']
  34. _id = 'disk' if _id == 'sqlite' else _id
  35. if _id == 'console' :
  36. """
  37. We are going to print whatever we have to the console ... using the tool in cli mode
  38. """
  39. print()
  40. print (args['data'])
  41. print ()
  42. # stream = args['memory']
  43. # stream.write(json.dumps(args['row']) if isinstance(args['row'],dict) else args['row'])
  44. # stream.write("\n")
  45. else:
  46. store_type = ".".join([args['store'],STORE_MAP[_id]])
  47. store_args = args['params']
  48. store = transport.factory.instance(type=store_type,args=store_args)
  49. store.write( args['row'])