Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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())
Ejemplo n.º 5
0
def mqtt_send(msg):
    printBetter(f"Sending message to esp8266: {msg}")
    #client.publish('/leds/esp8266', 'TOGGLE')
    client.publish('/leds/esp8266', msg)
Ejemplo n.º 6
0
 def send_feed_data(self, feed_id, value):
     client = self.client[self.pump[feed_id]['owner']]
     client.publish(feed_id, value)