Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. from simple_salesforce import Salesforce
  2. import requests
  3. import json
  4. import pprint
  5. import time
  6. import getpass
  7.  
  8. class Gecko(object):
  9. def __init__(self, api_key):
  10. self.api_key = api_key
  11. def push(self, widget_key, data):
  12. ret = requests.post("https://push.geckoboard.com/v1/send/%s" % widget_key, json.dumps({'api_key' : self.api_key, 'data' : data}), verify=False)
  13. if not (ret.status_code == 200 and ret.json().get('success') == True):
  14. raise ValueError(ret.content)
  15. def line(self, widget_key, values, **kwargs):
  16. data = {'item' : [], 'settings' :kwargs}
  17. for item in values:
  18. data['item'].append(item)
  19. return self.push(widget_key, data)
  20.  
  21. username = raw_input("Provide sf username:")
  22. password = getpass.getpass("Provide sf pass:")
  23. token = getpass.getpass("Provide sf token:")
  24. while 1:
  25. print "**** update data ****"
  26. sf = Salesforce(username=username, password=password, security_token=token)
  27. run = Gecko('')
  28.  
  29. orders = sf.query_all("SELECT count(Id) FROM Order WHERE Country_Code__c = '77' and CreatedDate = TODAY")
  30. pprint.pprint(orders)
  31. run.push('191582-0a1efc5a-6f98-4fbc-8436-0d681b1c085f', {'item': orders[u'records'][0][u'expr0'],'min':{'value':0}, 'max':{'value':100} })
  32.  
  33. newCases = sf.query_all("SELECT count(Id) FROM Case where OwnerId='00G24000000hU9qEAE' and Status = 'New'")
  34. pprint.pprint(newCases)
  35. run.push('191582-5d37b6d9-d9e6-4bb2-b7d0-dac9c0c0907b', {'item': newCases[u'records'][0][u'expr0'],'min':{'value':0}, 'max':{'value':10} })
  36.  
  37. closedCasesThisWeek = sf.query_all("SELECT count(Id) FROM Case where OwnerId='00G24000000hU9qEAE' and LastModifiedDate = THIS_WEEK and Status = 'Closed'")
  38. pprint.pprint(closedCasesThisWeek)
  39. run.push('191582-6f189e29-26d5-4ad6-8af1-46e23ad7a455', {'item': closedCasesThisWeek[u'records'][0][u'expr0'],'min':{'value':0}, 'max':{'value':20} })
  40. time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement