def __init__(self): super(Main, self).__init__() self.ui = Ui_EnergyAuditor() self.ui.setupUi(self) self.ui.refreshButton.clicked.connect(self.get_values) self.ui.graphButton.clicked.connect(self.plot_graph) self.ui.exitButton.clicked.connect(self.close) self.ui.documentationLink.setOpenExternalLinks(True) self.ui.documentationLink.setText( "<a href='https://github.com/hpreshit/Energy-Auditor'>Documentation Link</a>" ) global table1, counter, table2, keys_list keys_list = [] previous_list = [] initial = 0 counter = 0 dynamodb_session = Session( aws_access_key_id=''.join(access_key_id), aws_secret_access_key=''.join(secret_access_key), region_name=''.join(region)) dynamodb = dynamodb_session.resource('dynamodb') table1 = dynamodb.Table('energy_auditor_data_log') table2 = dynamodb.Table('energy_data_latest')
def lambda_handler(event, context): AWS_PASS, AWS_KEY = get() DYNAMODB_REGION = 'us-west-2' dynamodb = boto3.resource('dynamodb', aws_secret_access_key=AWS_PASS, aws_access_key_id=AWS_KEY, region_name=DYNAMODB_REGION) table = dynamodb.Table('request_table') menu_id = event['menu_id'] try: table.update_item( Key={'menu_id': menu_id}, UpdateExpression="SET selection = list_append(selection, :i)", ExpressionAttributeValues={ ':i': ['Vegetable'], }, ReturnValues="UPDATED_NEW") return (200, "OK") except Exception, e: return e, '400'
def fetch(): dynamodb = boto3.resource('dynamodb', region_name='us-west-2') table_attendance = dynamodb.Table('permanent-attendance') responseData = table_attendance.scan(ProjectionExpression='date_time') print(responseData) return responseData
def lambda_handler(event, context): global key gene = event["gene"] disease = event["disease"] score = event["score"] dynamodb = boto3.resource('dynamodb') table = dynamodb.Table("Gene_Disease") try: table.put_item(Item={'Gene': gene, 'Disease': disease, 'Score': score}) except Exception as e: return e return "Success"
def lambda_handler(event, context): AWS_KEY, AWS_PASS = get() DYNAMODB_REGION = 'us-west-2' dynamodb = boto3.resource('dynamodb', aws_secret_access_key=AWS_PASS, aws_access_key_id=AWS_KEY, region_name=DYNAMODB_REGION) TABLE_NAME = 'request_table' table = dynamodb.Table(TABLE_NAME) client = boto3.client('dynamodb') store_hours = {} for item in event["store_hours"]: it = dict() it["S"] = event["store_hours"][item] store_hours[item] = it try: client.put_item(TableName="request_table", Item={ "menu_id": { "S": event["menu_id"] }, "store_name": { "S": event["store_name"] }, "selection": { "L": format_data(event["selection"], "S") }, "size": { "L": format_data(event["size"], "S") }, "price": { "L": format_data(event["price"], "N") }, "store_hours": { "M": store_hours }, "sequence": { "L": [{ "S": "selection" }, { "S": "size" }] } }) except Exception, e: return 400, e
def lambda_handler(event, context): AWS_PASS, AWS_KEY = get() DYNAMODB_REGION = 'us-west-2' dynamodb = boto3.resource('dynamodb', aws_secret_access_key=AWS_PASS, aws_access_key_id=AWS_KEY, region_name=DYNAMODB_REGION) table = dynamodb.Table('request_table') menu_id = event['menu_id'] try: response = table.delete_item(Key={'menu_id': menu_id}) return 200, "OK" except: return '400'
def block_device_by_mac_address(self, mac_address, block_message): try: authentic_devices_table = dynamodb.Table('authentic_devices') response = authentic_devices_table.update_item( Key={'mac_address': mac_address}, UpdateExpression="set is_blocked = :is_blocked, block_message = :block_message", ExpressionAttributeValues={ ':is_blocked': 1, ':block_message': block_message }, ReturnValues="UPDATED_NEW") if 'Attributes' in response: return response else: return None except Exception as e: Util().log(e) return None
def login(): error_msg = None username = None #if index.get_username() is not None and index.get_auth() is True: # username = index.get_username() # return redirect(url_for('index', username=username)) if 'username' in session and session['authenticated'] is True: username = session['username'] return redirect(url_for('index', username=username)) elif request.method == 'GET': return render_template('login.html') try: if request.method == 'POST': username = request.form['userID'] table = dynamodb.Table('Users') response = table.query( KeyConditionExpression=Key('username').eq(username)) if response['Count'] == 0: raise Error('Invalid name') o_password = request.form['password'] password = md5() password.update(bytes(o_password)) for row in response['Items']: if password.hexdigest() == row['password']: #index.set_username(request.form['userID']) #index.set_auth(True) session['username'] = request.form['userID'] session['authenticated'] = True return redirect(url_for('index', username=username)) raise Error('password error') except Error as error_catch: error_msg = str(error_catch) return render_template('login.html', error_msg=error_msg, username=username)
def register(): if request.method == 'GET': return render_template("register.html") if request.method == 'POST': # get username and password u = request.form.get('username', "") o_p = request.form.get('password', "") error = False # judge the inputs are empty if u == "" or o_p == "": error = True error_msg = "Error: All fields are required!" # add salt to password p = md5() p.update(bytes(o_p)) # check the username in db table = dynamodb.Table('Users') response = table.query( KeyConditionExpression=Key('username').eq(u) ) if response['Count'] != 0: error = True error_msg = "Error: This username has existed" # if error return to register.html if error: return render_template("register.html", title="Error", error_msg=error_msg, username=u) # write username and password into db table.put_item( Item={ 'username': u, 'password': p.hexdigest(), } ) return redirect(url_for('frontpage'))
def lambda_handler(event, context): AWS_PASS, AWS_KEY = get() DYNAMODB_REGION = 'us-west-2' dynamodb = boto3.resource('dynamodb', aws_secret_access_key=AWS_PASS, aws_access_key_id=AWS_KEY, region_name=DYNAMODB_REGION) table = dynamodb.Table('request_table') response = table.scan() data = response['Items'] menu_id = event['menu_id'] for item in data: if item["menu_id"] == menu_id: return item return '400'
def create_entry(event, context): dynamodb = boto3.resource('dynamodb') table = dynamodb.Table(os.environ['DYANMODB_TABLE']) json_body = json.loads(event['body']) print("Received journal entry for: " + json_body['date']) entry_key: int = int(json_body['date']) try: # Try to get an item by that entryDate table.get_item(Key={'date': entry_key}) # Since we didn't throw, we need to append this message to the # existing item list. table.update_item( Key={'date': entry_key}, UpdateExpression='SET entries = list_append(entries, :msg)', ExpressionAttributeValues={ ':msg': [json_body['text']] } ) print("Updated existing dynamodb item entry") except: # If we threw here, the item didn't exist, so create a new item table.put_item( Item={ 'date': entry_key, 'entries': [json_body['text']] } ) print("Writing new dynamodb item entry") return helper.return_success_json({'success': True})
def lambda_handler(event, context): AWS_KEY, AWS_PASS = get() DYNAMODB_REGION = 'us-west-2' dynamodb = boto3.resource('dynamodb', aws_secret_access_key=AWS_PASS, aws_access_key_id=AWS_KEY, region_name=DYNAMODB_REGION) table = dynamodb.Table('request_table') menu_id = event['menu_id'] order_id = event['order_id'] customer_name = event['customer_name'] customer_email = event['customer_email'] client = boto3.client("dynamodb") try: table.put_item( Item={ "order_id": order_id, "menu_id": menu_id, "customer_name": customer_name, "customer_email": customer_email, "order_status": "selecting", "order": { "selection": "null", "size": "null", "costs": "null", "order_time": "null" } }) msg = "{Message: Hi " + customer_name + ",please choose one of these selection: 1. Cheese, 2. Pepperoni, 3.Vegetable.}" return 200, "OK", msg except Exception, e: return 400, e
import boto3 from boto3 import dynamodb from boto3.session import Session import uuid import json dynamodb_session = Session(aws_access_key_id='', aws_secret_access_key='', region_name='us-west-2') dynamodb = dynamodb_session.resource('dynamodb') table = dynamodb.Table('menu') def handler(event, context): methodtype = event['httpMethod'] if methodtype == 'POST': response = table.put_item( Item={ "menu_id": event['body']['menu_id'], "store_name": event['body']['store_name'], "selection": event['body']['selection'], "size": event['body']['size'], "price": event['body']['price'], "sequence": event['body']['sequence'], "store_hours": event['body']['store_hours'] }) return "POSTED" elif methodtype == 'GET':
import boto3 from boto3 import dynamodb from boto3.session import Session import uuid import json # Get the service resource. dynamodb = boto3.resource('dynamodb', region_name='us-west-2', aws_access_key_id='', aws_secret_access_key='') table = dynamodb.Table('pizza') def handler(event, context): methodtype = event['method'] if methodtype == 'POST': response = table.put_item( Item={ "menu_id": event['body']['menu_id'], "store_name": event['body']['store_name'], "selection": event['body']['selection'], "size": event['body']['size'], "price": event['body']['price'], "sequence": event['body']['sequence'], "store_hours": event['body']['store_hours'] }) return "POST COMPLETED" elif methodtype == 'GET': response = table.get_item(Key={"menu_id": event['body']['menu_id']})
import boto3 import json from boto3 import dynamodb from boto3.session import Session db_session = Session(aws_access_key_id='*****', aws_secret_access_key='*****', region_name='us-west-1') dynamodb = db_session.resource('dynamodb') menu_table = dynamodb.Table('Menu') def handler(event, context): method_type = event['httpMethod'] if method_type == 'POST': menuId = event['body']['menu_id'] response = menu_table.put_item( Item={ "menu_id": event['body']['menu_id'], "store_name": event['body']['store_name'], "selection": event['body']['selection'], "size": event['body']['size'], "price": event['body']['price'], "store_hours": event['body']['store_hours'] }) return "POSTED with menu_id: " + menuId elif method_type == 'GET': response = menu_table.get_item( Key={"menu_id": event['body']['menu_id']}) return response['Item'] elif method_type == 'DELETE':
# Get current metadata for geolocation city = document.get_meta_data_value('myzip') mylog("Zip:" + ' '.join(city)) # If city is there get the Lon/Lat from dynamoDB if (city): try: found = False #Now we fetch the lat/lon from the db dynamodb_session = Session(aws_access_key_id='xxxx', aws_secret_access_key='xxxx', region_name='us-east-1') dynamodb = dynamodb_session.resource('dynamodb') table = dynamodb.Table('GEOCODE') mycity = city[0].lower() mycity2 = mycity if (mycity.isdigit()): #Pad with zeros mycity2 = format(mycity, '05') mylog("Execute query with city " + str(mycity2)) response = table.query( KeyConditionExpression=Key('City').eq(str(mycity2))) for i in response['Items']: document.add_meta_data({"mylat2": str(i['Lat'])}) document.add_meta_data({"mylon2": str(i['Lon'])}) mylog("Getting lat" + str(i['Lat'])) found = True
import boto3 from boto3 import dynamodb from boto3.session import Session from boto3.dynamodb.conditions import Key, Attr dynamodb_session = Session(profile_name="mayama-cli", region_name="ap-northeast-1") dynamodb = dynamodb_session.resource('dynamodb') type_garbage_table = dynamodb.Table("borderless-type-of-garbage") def main(): update() scan() def update(): file = open("../conf/type-of-garbage.csv", "r") # ハウス名を入力 house_name = "Oimachi" garbage_type_day = {} for line in file: line = line.rstrip() items = line.split(",") garbage_type = items[0] days = items del days[0:1]
import boto3 from boto3 import dynamodb from boto3.session import Session import uuid import json dynamodb = boto3.resource('dynamodb', region_name='us-west-2', aws_access_key_id='', aws_secret_access_key='') table = dynamodb.Table('Pizza') def handler(event, context): methodtype = event['method'] if methodtype == 'POST': response = table.put_item( Item={ "menu_id": event['body']['menu_id'], "store_name": event['body']['store_name'], "selection": event['body']['selection'], "size": event['body']['size'], "price": event['body']['price'], "sequence": event['body']['sequence'], "store_hours": event['body']['store_hours'] }) return "Posted successfully" elif methodtype == 'GET': response = table.get_item(Key={"menu_id": event['body']['menu_id']}) return response['Item']
def get_stock_data_from_db(): table = dynamodb.Table('stockit') data = table.scan() return data['Items']
import boto3 from boto3 import dynamodb from boto3.session import Session from boto3.dynamodb.conditions import Key, Attr dynamodb_session = Session(profile_name="mayama-cli", region_name="ap-northeast-1") dynamodb = dynamodb_session.resource('dynamodb') house_member_table = dynamodb.Table("borderles-this-week-garbage-charge") def main(): update() scan() # query() def update(): file = open("../conf/this-week-garbage-gharge.csv", "r") groupIds = [] rooms = [] house_name = [] names = [] for line in file: items = line.split(",") groupIds.append(items[0]) rooms.append(items[1]) house_name.append(items[2]) names.append(items[3]) file.close()
break ext = filename.split('.')[-1] encoded_filename = encode_fn(symbol, lang, ext) identifiers = [] identifiers.append(Identifier('symbol', symbol)) #key = "{}/{}/PDF/{}".format(base_path, subfolder, filename) print(encoded_filename) save_file = "{}/{}".format(tmpdir, filename) if args.skipdb: key = f"{base_path}/{subfolder}/{filename}" else: table = dynamodb.Table(args.table) # Use the filename to query the DigitizationIndex response = table.query( IndexName=args.index, KeyConditionExpression=Key('filename').eq(filename)) #print(response) key = '' for i in response['Items']: this_k = i['Key'] #print(this_k) if "/PDF/" in this_k: key = this_k print("Found key: {}".format(key)) if key == '': print(
def lambda_handler(event, context): AWS_KEY, AWS_PASS = get() DYNAMODB_REGION = 'us-west-2' pizza_type_map = {"1": "Cheese", "2": "Pepperoni", "3": "Vegetable"} pizza_size_map = {"1": "Slide", "2": "Small", "3": "Medium", "4": "Large", "5": "X-Large"} pizza_prize_map = {"Slide": "3.50", "Small": "7.0", "Medium": "10.0", "Large": "15.00", "X-Large": "20.00"} dynamodb = boto3.resource('dynamodb', aws_secret_access_key=AWS_PASS, aws_access_key_id=AWS_KEY, region_name=DYNAMODB_REGION ) table = dynamodb.Table('user_order_table') order_id = event['order_id'] # 'uuid' user_selection = event['input'] response = table.scan() data = response['Items'] for item in data: if item['order_id'] == order_id: res = item try: if res['order_status'] == 'selecting': table.update_item( Key={'order_id': order_id }, UpdateExpression="SET order_status = :val1", ExpressionAttributeValues={ ':val1': 'selecting_type', } ) pizza_type = pizza_type_map[user_selection] table.update_item( Key={'order_id': order_id }, UpdateExpression="SET selection = :val1", ExpressionAttributeValues={ ':val1': pizza_type, } ) msg = "{Message: Which size do you want? 1. Slide, 2. Small, 3. Medium, 4. Large, 5. X-Large " return 200, "OK", msg if res['order_status'] == 'selecting_type': table.update_item( Key={'order_id': order_id }, UpdateExpression="SET order_status = :val1", ExpressionAttributeValues={ ':val1': 'selecting_size', } ) pizza_size = pizza_size_map[user_selection] table.update_item( Key={'order_id': order_id }, UpdateExpression="SET size = :val1", ExpressionAttributeValues={ ':val1': pizza_size, } ) price = pizza_prize_map[pizza_size] table.update_item( Key={'order_id': order_id }, UpdateExpression="SET costs = :val1", ExpressionAttributeValues={ ':val1': price, } ) msg = "{Message: Your order costs " + price + "$ We will email you when the order is ready. Thank you!" return 200, "OK", msg if res['order_status'] == 'selecting_size': table.update_item( Key={'order_id': order_id }, UpdateExpression="SET order_status = :val1", ExpressionAttributeValues={ ':val1': 'processing', } ) out = table.get_item( Key={ 'order_id': order_id } ) return 200, "OK", out except Exception, e: return 400, e
def query_profiles(): table = dynamodb.Table("Profiles") profiles = table.scan(ProjectionExpression="#name,picture", ExpressionAttributeNames={"#name": "name"}) return profiles['Items']
Daynamodatabase = "DDB" Parquedatabase = "Athena" JobRole = "DYNAMODBGLUEROLE" Parqueprefix = "ddb-s3-athena-" s3datalocation = 's3://ddb-with-athena/glue/ddb-output-' + TableNameForGlue + '/' s3bucket = 'ddb-with-athena' s3prefix = 'glue/ddb-output-' + TableNameForGlue + '/' s3scriptlocation = 's3://ddb-with-athena/[email protected]/' s3scriptname = 'Script.py' awsprofile = 'dynamoglueprod' executionSuccess = {} boto3.setup_default_session(profile_name=awsprofile) dynamodb = boto3.resource('dynamodb') ddt = dynamodb.Table(TableName) if ddt.item_count > 0: logger.info("Starting Glue process") glue = boto3.client('glue') try: response = glue.delete_crawler(Name=TableNameForGlue) logger.info("Glue job removed:" + TableNameForGlue) except: logger.info("Glue crawler job not exists!") # Create Crawler Job # -------------------------- response = glue.create_crawler( Name=TableNameForGlue, Role=JobRole,
from threading import Thread import pandas as pd from datetime import datetime import sys import os.path import time from boto3 import dynamodb import numpy as np from boto3.session import Session from boto3.dynamodb.conditions import Key pd.set_option('display.max_columns', 7) dynamodb_session = Session(aws_access_key_id = access_key, aws_secret_access_key = secret_key, region_name = region_name) dynamodb = dynamodb_session.resource('dynamodb') table = dynamodb.Table('machine_learning') table.put_item(Item = {'billboard_audience_segment_id': 'test', 'week_of_year': 'test', 'test' :'test'}) overwrite = False print('------------------------------------------') print('Creating timeseries dataset...') print('------------------------------------------') if len(sys.argv) == 2: if sys.argv[1] == 'overwrite': print('Overwrite Mode On') overwrite = True else: print('Overwrite Mode Off')
import boto3 import json from boto3 import dynamodb import uuid from boto3.session import Session import time db_session = Session(aws_access_key_id='******', aws_secret_access_key='*******', region_name='us-west-1') dynamodb = db_session.resource('dynamodb') order_table = dynamodb.Table('Order') menu_table = dynamodb.Table('Menu') selection_map = {} def handler(event, context): method_type = event['httpMethod'] if method_type == 'PUT': size_option = event['body']['input'] print size_option response_order = order_table.get_item( Key={"order_id": event['body']['order_id']}) response_menu = menu_table.get_item( Key={"menu_id": response_order['Item']['menu_id']}) selection = response_order['Item']['order_details']['selection'] size = response_menu['Item']['size'][int(size_option) - 1] price = response_menu['Item']['price'][int(size_option) - 1]
import boto3 from boto3 import dynamodb from boto3.session import Session import uuid import json import time dynamodb_session = Session(aws_access_key_id='', aws_secret_access_key='', region_name='us-west-2') dynamodb = dynamodb_session.resource('dynamodb') table = dynamodb.Table('order') table2 = dynamodb.Table('menu') def handler(event, context): methodtype = event['httpMethod'] if methodtype == 'GET': response = table.get_item(Key={"order_id": event['body']['order_id']}) return response['Item'] if methodtype == 'POST': response = table.put_item( Item={ 'menu_id': event['body']['menu_id'], 'order_id': event['body']['order_id'], 'customer_name': event['body']['customer_name'], 'customer_email': event['body']['customer_email'], 'order_status': "processing", 'order': {}
def insert_stock_data(stockList): table = dynamodb.Table('stockit') with table.batch_writer() as batch: for i in range(1, len(stockList)): batch.put_item(Item=stockList[i])
import boto3 from boto3 import dynamodb from boto3.session import Session from boto3.dynamodb.conditions import Key, Attr dynamodb_session = Session(profile_name="mayama-cli", region_name="ap-northeast-1") dynamodb = dynamodb_session.resource('dynamodb') house_member_table = dynamodb.Table("borderless-house-members") def main(): update() scan() # query() def update(): file = open("../conf/borderless-house-member.csv", "r") groupIds = [] rooms = [] house_name = [] names = [] for line in file: items = line.split(",") groupIds.append(items[0]) rooms.append(items[1]) house_name.append(items[2]) names.append(items[4]) file.close()
from credentials import access_key, secret_key, region_name import boto3 from boto3 import dynamodb from boto3.session import Session from boto3.dynamodb.conditions import Key dynamodb_session = Session(aws_access_key_id = access_key, aws_secret_access_key = secret_key, region_name = region_name) dynamodb = dynamodb_session.resource('dynamodb') table = dynamodb.Table('location-audience-2019-08-17') location_hashs = ["ac2959cc7ac7466bd91b08e58e5490d2", "ac0e4be8494c4c34a4c8c4e1ca47253c", "aeafeac6a78c548227f37bdd32cfb516", "eb54b7e048c7353be69954ea451d0276", "3c8da0f4e53ecd2e20fb620962bda2f3", "ea2c659d3b5fead1b7ced561722e9216"] segment_ids = [[61],[755],[77],[61,755,77]] def calculateAdomniScore(table, locationHash, segment_ids): for segment_id in segment_ids: string_id = map(str, segment_id) list_string = ', '.join(string_id) print("For segment id: " + list_string) for id in segment_id: response = table.query(KeyConditionExpression=Key('locationHash').eq(locationHash) & Key('audienceSegmentId').eq(id)) if len(response['Items']) > 0: count = str(response['Items'][0]['count']) print("Count: " + count) else: print("Count: 0") return 0 return 1 for location_hash in location_hashs: