Exemplo n.º 1
0
    def run(self):
        if not self.args.lightcommand:
            self.parser.print_help(sys.stderr)
            return
        if self.args.lightcommand == 'inc':
            self.logger.info('Increase brightness of %d%%' % self.args.value)
            check_output(self.values['increase_cmd'] % (self.args.value),
                         shell=True)
        elif self.args.lightcommand == 'dec':
            self.logger.info('Decrease brightness of %d%%' % self.args.value)
            check_output(self.values['decrease_cmd'] % (self.args.value),
                         shell=True)
        else:
            self.logger.info('Set brightness to %d%%' % self.args.value)
            check_output(self.values['set_cmd'] % (self.args.value),
                         shell=True)

        current_value = int(
            float(check_output(self.values['get_cmd'], shell=True)))
        if current_value < 50:
            icon = self.values['icon-low']
        elif current_value < 75:
            icon = self.values['icon-medium']
        elif current_value < 100:
            icon = self.values['icon-high']
        else:
            icon = self.values['icon-full']
        Notification.sendNotification("Brightness", icon, current_value)
Exemplo n.º 2
0
def lambda_handler(event, context):
    # This is the function that is called by Lambda (like a Main function)

    # Fetch all records from the last week
    dynamoService = database.DynamoService()
    now = int(time.time())
    oneWeekAgo = now - (7 * 24 * 60 * 60)
    print("Getting items")
    identifierList = dynamoService.getItemIdentifiersAfterTimestamp(oneWeekAgo)

    # Get nutrition data on all food
    nutritionService = NutritionService()
    nutrition = nutritionService.getMockNutritionData()
    print("Querying for nutrition")
    for identifiers in identifierList:
        n = nutritionService.getNutritionByIdentifiers(identifiers)
        if n is not None:
            nutrition.append(n)

    # Generate HTML report
    nutritionReport = NutrtritionReport()
    url = nutritionReport.getHTML(nutrition)

    # Send user notification
    notificationService = Notification()
    message = "Your weekly Nutrition Report is ready. Download here: " + str(
        url)
    notificationService.sendNotification(message)
    return message