def __init__(self, uri, email=None, password=None, refresh_token=None, client_id=None, token=None, put_auth_in_header=True, personal_token=None, account_id=None): self.__uri = uri.rstrip('/') parsed = urlparse(uri) if not (parsed.scheme and parsed.netloc): raise HarvestError('Invalid harvest uri "{0}".'.format(uri)) if refresh_token: self.__headers = { "Content-Type": 'application/x-www-form-urlencoded', "Accept": 'application/json', } else: self.__headers = { 'Content-Type' : 'application/json', 'Accept' : 'application/json', 'User-Agent' : 'Mozilla/5.0', # 'TimeTracker for Linux' -- ++ << >> } if email and password: self.__auth = 'Basic' self.__email = email.strip() self.__password = password if put_auth_in_header: self.__headers['Authorization'] = 'Basic {0}'.format(enc64("{self.email}:{self.password}".format(self=self).encode("utf8"))) elif client_id and token: self.__auth = 'OAuth2' self.__client_id = client_id self.__token = token elif account_id and personal_token: self.__auth = 'Bearer' self.__account_id = account_id self.__personal_token = personal_token if put_auth_in_header: self.__headers['Authorization'] = 'Bearer {0}'.format("{self.personal_token}".format(self=self)) self.__headers['Harvest-Account-Id'] = "{self.account_id}".format(self=self)
def __init__(self, uri, email=None, password=None, refresh_token=None, client_id=None, token=None, put_auth_in_header=True): self.__uri = uri.rstrip('/') parsed = urlparse(uri) if not (parsed.scheme and parsed.netloc): raise HarvestError('Invalid harvest uri "{0}".'.format(uri)) if refresh_token: self.__headers = { "Content-Type": 'application/x-www-form-urlencoded', "Accept": 'application/json', } else: self.__headers = { 'Content-Type' : 'application/json', 'Accept' : 'application/json', 'User-Agent' : 'Mozilla/5.0', # 'TimeTracker for Linux' -- ++ << >> } if email and password: self.__auth = 'Basic' self.__email = email.strip() self.__password = password if put_auth_in_header: self.__headers['Authorization'] = 'Basic {0}'.format(enc64('{self.email}:{self.password}'.format(self=self))) elif client_id and token: self.__auth = 'OAuth2' self.__client_id = client_id self.__token = token
def __init__(self, uri, email=None, password=None, client_id=None, token=None, put_auth_in_header=True): """ Init method """ self.__uri = uri.rstrip('/') parsed = urlparse(uri) if not (parsed.scheme and parsed.netloc): raise HarvestError('Invalid harvest uri "{0}".'.format(uri)) self.__headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'Mozilla/5.0', # 'TimeTracker for Linux' -- ++ << >> } if email and password: self.__auth = 'Basic' self.__email = email.strip() self.__password = password if put_auth_in_header: basic_auth = enc64( '{self.email}:{self.password}'.format(self=self)) self.__headers['Authorization'] = 'Basic {0}'.format( basic_auth) elif client_id and token: self.__auth = 'OAuth2' self.__client_id = client_id self.__token = token
def __init__(self, uri, email, password, put_auth_in_header=True): self.__uri = uri.rstrip('/') parsed = urlparse(uri) if not (parsed.scheme and parsed.netloc): raise HarvestError('Invalid harvest uri "{0}".'.format(uri)) self.__email = email.strip() self.__password = password self.__headers = { 'Accept' : 'application/json', 'User-Agent' : 'Mozilla/5.0', # 'TimeTracker for Linux' -- ++ << >> } if put_auth_in_header: self.__headers['Authorization'] = 'Basic {0}'.format(enc64('{self.email}:{self.password}'.format(self=self)))
def __init__(self, uri, email, password, put_auth_in_header=True): self.__uri = uri.rstrip('/') parsed = urlparse(uri) if not (parsed.scheme and parsed.netloc): raise HarvestError('Invalid harvest uri "{0}".'.format(uri)) self.__email = email.strip() self.__password = password self.__headers = { 'Accept': 'application/json', 'User-Agent': 'Mozilla/5.0', # 'TimeTracker for Linux' -- ++ << >> } if put_auth_in_header: self.__headers['Authorization'] = 'Basic {0}'.format( enc64('{self.email}:{self.password}'.format(self=self)))
def __init__(self, uri, email, password, put_auth_in_header=True): self.__uri = uri.rstrip("/") parsed = urlparse(uri) if not (parsed.scheme and parsed.netloc): raise HarvestError('Invalid harvest uri "{0}".'.format(uri)) self.__email = email.strip() self.__password = password self.__headers = { "Accept": "application/json", "User-Agent": "Mozilla/5.0", # 'TimeTracker for Linux' -- ++ << >> } if put_auth_in_header: self.__headers["Authorization"] = "Basic {0}".format( enc64("{self.email}:{self.password}".format(self=self)) )
def __init__(self, uri="your harvest URL", email="your harvest email", password="******", ifttt_key="yourIFTTT Maker Channel key", ifttt_event="ifttt event prefix", num_events=3, frequency=300): self.__uri = uri.rstrip('/') parsed = urlparse(uri) if not (parsed.scheme and parsed.netloc): raise HarvestError('Invalid harvest uri "{0}".'.format(uri)) self.__headers = { 'Content-Type' : 'application/json', 'Accept' : 'application/json', 'User-Agent' : 'Mozilla/5.0', # 'TimeTracker for Linux' -- ++ << >> } self.__auth = 'Basic' self.__email = email.strip() self.__password = password self.__headers['Authorization'] = 'Basic {0}'.format(enc64('{self.email}:{self.password}'.format(self=self))) self.__ifttt_key = ifttt_key self.__ifttt_event = ifttt_event self.__num_events = num_events self.__frequency = frequency
def callback(ch, method, properties, body): channel1 = connection.channel() channel1.queue_declare(queue='to_server', durable=True) message = body.decode('utf-8') l = message.split(flag) print("Received msg_id splitted ", l) msg_id = l[0] if (l[1] == 'upload_post'): # msg_id ÿ 'upload_post' ÿ access_token ÿ access_tok_secret ÿ text ÿ photo (path) consumer_key = 'VyP9pdp6VC1M0qkfS4m14oxqM' consumer_secret = 'udtYapVuIU3vFalBjRmHWIVPPE6yA9BK4Zwzj6XB1kRcg8ekQq' access_token = l[2] access_token_secret = l[3] text = l[4] photo = l[5] flag_photo = False oauth = OAuth1Session(consumer_key, client_secret=consumer_secret, resource_owner_key=access_token, resource_owner_secret=access_token_secret) if len(photo) > 0: flag_photo = True media_info_resp = oauth.post( 'https://upload.twitter.com/1.1/media/upload.json', data={'media_data': enc64(open(photo, 'rb').read())}) media_info = media_info_resp.json() if (not ('200' in str(media_info_resp))): stringa_invio = msg_id + flag + 'twtÿupload_postÿ' + 'image error' channel1.basic_publish(exchange='', routing_key='to_server', body=stringa_invio) if (flag_photo): media_id = media_info['media_id_string'] params = {'status': text, 'media_ids': [media_id]} else: params = {'status': text} r = oauth.post('https://api.twitter.com/1.1/statuses/update.json', data=params, json=None) risposta = 1 if ('200' in str(r)): risposta = 0 if not risposta: stringa_invio = msg_id + flag + 'twtÿupload_postÿ' + str(risposta) channel1.basic_publish(exchange='', routing_key='to_server', body=stringa_invio) else: stringa_invio = msg_id + flag + 'twtÿupload_postÿ' + 'exception_occurred' channel1.basic_publish(exchange='', routing_key='to_server', body=stringa_invio) else: stringa_invio = msg_id + flag + 'twtÿupload_postÿ' + 'unknow command' channel1.basic_publish(exchange='', routing_key='to_server', body=stringa_invio)