This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathvoidexams-noindex.py
76 lines (68 loc) · 2.9 KB
/
voidexams-noindex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Find students within a country
# A Cloud Guru - Dynamo DB Course\
# USES V3 DATA MODEL
import boto3, botocore, tqdm, random, time
from time import gmtime, strftime
from boto3.dynamodb.conditions import Attr
from botocore.exceptions import ClientError
from sys import version_info
py3 = version_info[0] > 2 #creates boolean value for test that Python major version > 2
lesson = '4-014' ## UDPATE ME
loadmin_session = boto3.Session(profile_name='loadmin')
db_c = loadmin_session.client('dynamodb')
db_r = loadmin_session.resource('dynamodb')
## PREREQS - images/ folder in same directory as this scripts
## configured AWS tools
## installed python2.7+
## installed boto3 (pip install boto3)
## Installed faker module
## Installed tqdm module
## 'loadmin' AWS configuration profile - with admin rights
## Data Model v2 loaded.
## _retry.json file from lesson files - adjusted for 1mil+ auto retries
## for retryable operations
if __name__ == "__main__":
student_id = ""
capacityconsumed = 0
scannedcount = 0
starttime = time.time()
response=db_r.Table("lo_exams").scan(\
ReturnConsumedCapacity='TOTAL', \
ExpressionAttributeValues={':true' : 'true'}, \
ExpressionAttributeNames={'#V' : 'void'}, \
FilterExpression="#V = :true" \
)
capacityconsumed = response['ConsumedCapacity']['CapacityUnits']
scannedcount = response['ScannedCount']
data=response['Items']
while 'LastEvaluatedKey' in response:
#print "hi"
response=db_r.Table("lo_exams").scan(\
ReturnConsumedCapacity='TOTAL', \
ExpressionAttributeValues={':true' : 'true'}, \
ExpressionAttributeNames={'#V' : 'void'}, \
ExclusiveStartKey=response['LastEvaluatedKey'], \
FilterExpression="#V = :true" \
)
#print response
capacityconsumed = capacityconsumed + response['ConsumedCapacity']['CapacityUnits']
scannedcount = scannedcount + response['ScannedCount']
data.extend(response['Items'])
finishtime=time.time()
timetocomplete = finishtime - starttime
print "Script Started on %s, finished on %s, took %0.2fs to complete without indexes" % (time.ctime(starttime),\
time.ctime(finishtime), timetocomplete)
print "Operation required %i capacity units to complete" % capacityconsumed
print "Total number of items scanned [%i]" % scannedcount
print "Located [%i] results voided" % (len(data))
print "Press Q to quit... or any other key to list voided exams "
if py3:
entry = str(input()).lower()
else:
entry = str(raw_input()).lower()
if entry == 'q':
exit(0)
print "#\tE_ID\tStudentID\tCourseInstaceID"
for i, s_instance in enumerate(data):
print "%d\t%s\t%s\t%s" % (i+1, \
s_instance['id'], s_instance['s_id'], s_instance['ci_id'])