def main(): """Shows basic usage of the Google Calendar API. Creates a Google Calendar API service object and outputs a list of the next 10 events on the user's calendar. """ if len(sys.argv) < 1: raise(NameError('No user added to path')) credentials = get_credentials(2) http = credentials.authorize(httplib2.Http()) service = discovery.build('calendar', 'v3', http=http) now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time print('Getting the upcoming 10 events') eventsResult = service.events().list( calendarId='primary', timeMin=now, maxResults=10, singleEvents=True, orderBy='startTime').execute() events = eventsResult.get('items', []) if not events: print('No upcoming events found.') client = mqtt.Client() client.connect("54.229.54.240", 1883, 60) for event in events: start = event['start'].get('dateTime', event['start'].get('date')) loc = 'unknown' if 'location' in event: loc = event['location'] client.publish("carai/usr/cal",json.dumps(event)) client.loop(1) #timeout 1 sec print(start, event['summary'],loc)
def send_sms_message(number, msg): client = boto3.client('sns') response = client.publish(PhoneNumber=number, Message=msg, MessageStructure='', MessageAttributes={}) # log text sent print('\n#MessageSent', 'number: ' + number, ', message: ' + msg, ', response: ' + str(response), ', time: ' + str(datetime.datetime.now(datetime.timezone.utc)), '\n')
def send_sms_message(number, msg): client = boto3.client('sns') response = client.publish(PhoneNumber=number, Message=msg, MessageStructure='', MessageAttributes={}) # log text sent fh = open(LOG_FILE, "a") fh.writelines([ 'number: ' + number, ', message: ' + msg, ', response: ' + str(response), ', time: ' + str(datetime.datetime.now(datetime.timezone.utc)), "\n" ]) fh.close
def publish_data(path_to_data, topic_name, repeats, client): for i in range(1, repeats): firstline = True with open(path_to_data) as data: print("Publishing data iteration {}".format(i)) reader = csv.reader(data) for line in reader: if firstline: firstline = False continue line[1] = '"' + line[1] + '"' line[2] = '"' + line[2] + '"' # print(len(line)) encoded_line = ','.join(line).encode('utf-8') print(encoded_line, '\n') future = client.publish(topic_name, encoded_line) print(future.result())
def mqtt_send(msg): printBetter(f"Sending message to esp8266: {msg}") #client.publish('/leds/esp8266', 'TOGGLE') client.publish('/leds/esp8266', msg)
def send_feed_data(self, feed_id, value): client = self.client[self.pump[feed_id]['owner']] client.publish(feed_id, value)