-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpythontincan.py
executable file
·59 lines (53 loc) · 1.86 KB
/
pythontincan.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
import urllib2
from threading import Thread
import json
import urllib
import requests
from requests.auth import HTTPBasicAuth
import uuid
import random
import argparse
def sendToLRS(whoDid,whoDidEmail,didWhat,whoDidObject,hashtag,reason):
#Call functions to get account variables
statement_id = str(_ruuid())
objectID = str(_randomID())
url = str(getURL())
#Creates the TinCan statement
tc_star =[{
"id":statement_id,
'actor':{'name':[whoDid],'mbox':['mailto:'+whoDidEmail]},
'verb':didWhat,
'object':{'id':objectID,'definition':{'name':{"en-US":'with '+ whoDidObject},'description':{"en-US":whoDid+' gave a gold star to '+whoDidObject+' for '}}},
'context':{'extensions':{'Hashtag':'#'+hashtag, 'Reason':reason }}
}]
try:
resp = requests.post(url,data=json.dumps(tc_star),auth=HTTPBasicAuth(getUsername(),getsecretKey()),headers={"Content-Type":"application/json"})
except IOError as e:
print e
def main():
#Thread(None,sendToLRS,None,(Who,Did,toWho)).start()
print "Hi"
def startThread(Who,whoEmail,Did,toWho, hashtag,starReason):
Thread(None,sendToLRS,None,(Who,whoEmail,Did,toWho,hashtag,starReason)).start()
def _randomID():
return str(random.randint(1,10000000))
def getUsername():
#Change to your app ID
userName ='RLC4BXEK09'
#'UU3N64YGT2'
return userName
def getsecretKey():
#Change to your secret key
SecretKey = 'CcP5PLO8qaJUZYoDF7mFJKCxhz0TODC0rrznipcS'
#'9VU0MxwcogqhZYKc9Vn734oohTSOFoZohFJBJf5m'
return SecretKey
def getURL():
#Change to your Tin Can endpoint
URL = 'https://cloud.scorm.com/ScormEngineInterface/TCAPI/RLC4BXEK09/statements/'
#'https://cloud.scorm.com/ScormEngineInterface/TCAPI/UU3N64YGT2/statements/'
return URL
def _ruuid():
return uuid.uuid1()
if __name__ =="__main__":
main()
#thread.start_new_thread(sendToLRS,('Roger','Awesomed','Rick'))