Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from simple_salesforce import Salesforce
- import requests
- import json
- import pprint
- import time
- import getpass
- class Gecko(object):
- def __init__(self, api_key):
- self.api_key = api_key
- def push(self, widget_key, data):
- ret = requests.post("https://push.geckoboard.com/v1/send/%s" % widget_key, json.dumps({'api_key' : self.api_key, 'data' : data}), verify=False)
- if not (ret.status_code == 200 and ret.json().get('success') == True):
- raise ValueError(ret.content)
- def line(self, widget_key, values, **kwargs):
- data = {'item' : [], 'settings' :kwargs}
- for item in values:
- data['item'].append(item)
- return self.push(widget_key, data)
- username = raw_input("Provide sf username:")
- password = getpass.getpass("Provide sf pass:")
- token = getpass.getpass("Provide sf token:")
- while 1:
- print "**** update data ****"
- sf = Salesforce(username=username, password=password, security_token=token)
- run = Gecko('')
- orders = sf.query_all("SELECT count(Id) FROM Order WHERE Country_Code__c = '77' and CreatedDate = TODAY")
- pprint.pprint(orders)
- run.push('191582-0a1efc5a-6f98-4fbc-8436-0d681b1c085f', {'item': orders[u'records'][0][u'expr0'],'min':{'value':0}, 'max':{'value':100} })
- newCases = sf.query_all("SELECT count(Id) FROM Case where OwnerId='00G24000000hU9qEAE' and Status = 'New'")
- pprint.pprint(newCases)
- run.push('191582-5d37b6d9-d9e6-4bb2-b7d0-dac9c0c0907b', {'item': newCases[u'records'][0][u'expr0'],'min':{'value':0}, 'max':{'value':10} })
- closedCasesThisWeek = sf.query_all("SELECT count(Id) FROM Case where OwnerId='00G24000000hU9qEAE' and LastModifiedDate = THIS_WEEK and Status = 'Closed'")
- pprint.pprint(closedCasesThisWeek)
- run.push('191582-6f189e29-26d5-4ad6-8af1-46e23ad7a455', {'item': closedCasesThisWeek[u'records'][0][u'expr0'],'min':{'value':0}, 'max':{'value':20} })
- time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement