dyn = DynamoDBConnection.connect(region=FLYWHEEL_REGION, access_key=AWS_ACCESS_KEY, secret_key=AWS_SECRET_ACCESS_KEY) db = Engine(dynamo=dyn) cont = { 'easy': [], 'medium': [], 'hard': [], 'impossible': [], } if __name__ == '__main__': context = db.scan(User).filter(User.mobile != None).gen() print("DONE SCAN") for u in context: try: if u.cpf is not None: for i in u.win.values(): print('*** {}'.format(i.get('level'))) print('*** {}'.format({ 'name': u.name, 'picture': u.avatar.get('big', '') })) cont[i.get('level')].append({ 'name': u.name, 'picture': u.avatar.get('big', '')
self.scrobble = scrobble engine = Engine() #engine.connect_to_host(host='localhost', port=8000) engine.connect_to_region('us-east-1') engine.register(scrobble) # uncomment the following if you actually want to create the database for the first time #engine.create_schema() # below is an example of how you would write to the the DynamoDB if you wanted to create a record # in tft_sonos_instagram.py I am using boto but if it was using flywheel, it would look like the following #z = scrobble("Patty Griffin", datetime.now(), "Making Pies", "Children Running through it", "Date: 1234", "14") #engine.save(z) days = input("How many days do you want to go back? ") # scan may be slow but not looking for this to be particularly fast and can't query with no hash key z = engine.scan(scrobble).filter( scrobble.ts > datetime.now() - timedelta(days=int(days))).all() y = [(x.ts, x.title, x.artist, x.album[:40]) for x in z] y.sort(key=lambda x: x[0], reverse=True) for x in y: #print((x[0]-timedelta(hours=4)).strftime("%a %I %M"),x[1],' - ',x[2]) #print("{}: {} - {}".format(*x)) print("{}: {} - {} - {}".format( (x[0] - timedelta(hours=4)).strftime("%a %I:%M%p"), x[1], x[2], x[3]))
class CLI(): def __init__(self, args): self.engine = Engine() self.engine.connect_to_region('eu-west-1') # Register our model with the engine so it can create the Dynamo table self.engine.register(Approval) # Create the dynamo table for our registered model self.engine.create_schema() self.args = args # Setup logging if args.verbose: loglevel = logging.DEBUG else: loglevel = logging.INFO logging.basicConfig(format="%(levelname)s: %(message)s", level=loglevel) def main(self): if self.args.action == 'list': self.list() elif self.args.action == 'approve': self.approve() elif self.args.action == 'reject': self.reject() else: logging.error('Please use a correct argument') exit(1) def approve(self): if 'id' not in self.args: logging.error('Please give an id') exit(1) approval_lock = self.engine.scan(Approval).filter( id=self.args.id).all() if not approval_lock: logging.info('No lock with the id %s has been found' % self.args.id) exit(1) approval_lock = approval_lock[0] approval_lock.approved = True approval_lock.timestamp = datetime.utcnow() self.engine.save(approval_lock, overwrite=True) logging.info('The lock %s has been approved' % self.args.id) def reject(self): if 'id' not in self.args: logging.error('Please give an id') exit(1) approval_lock = self.engine.scan(Approval).filter( id=self.args.id).all() if not approval_lock: logging.info('No lock with the id %s has been found' % self.args.id) exit(1) approval_lock = approval_lock[0] approval_lock.approved = False approval_lock.timestamp = datetime.utcnow() self.engine.save(approval_lock, overwrite=True) logging.info('The lock %s has been rejected' % self.args.id) def list(self): approval_locks = self.engine.scan(Approval).filter(claimed=True).all() table = [] if approval_locks: headers = sorted(approval_locks[0].keys_()) else: headers = None if approval_locks: for item in approval_locks: row = [] for key in sorted(item.keys_()): row.append(getattr(item, key)) table.append(row) print(tabulate(table, headers)) else: print('There is no waiting approval')
self.title = title self.date = date self.scrobble = scrobble engine = Engine() #engine.connect_to_host(host='localhost', port=8000) engine.connect_to_region('us-east-1') engine.register(scrobble) # uncomment the following if you actually want to create the database for the first time #engine.create_schema() # below is an example of how you would write to the the DynamoDB if you wanted to create a record # in tft_sonos_instagram.py I am using boto but if it was using flywheel, it would look like the following #z = scrobble("Patty Griffin", datetime.now(), "Making Pies", "Children Running through it", "Date: 1234", "14") #engine.save(z) days = input("How many days do you want to go back? ") # scan may be slow but not looking for this to be particularly fast and can't query with no hash key z = engine.scan(scrobble).filter(scrobble.ts > datetime.now()-timedelta(days=int(days))).all() y = [(x.ts, x.title, x.artist, x.album[:40]) for x in z] y.sort(key = lambda x:x[0], reverse=True) for x in y: #print((x[0]-timedelta(hours=4)).strftime("%a %I %M"),x[1],' - ',x[2]) #print("{}: {} - {}".format(*x)) print("{}: {} - {} - {}".format((x[0]-timedelta(hours=4)).strftime("%a %I:%M%p"), x[1], x[2], x[3]))