Last active
December 29, 2015 06:59
-
-
Save danslimmon/7633178 to your computer and use it in GitHub Desktop.
Test of barcode learning opp creation and notification for https://github.com/danslimmon/oscar/issues/13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
os.chdir('/var/oscar') | |
import sys | |
sys.path.append('.') | |
print 'sys.path: ' | |
print sys.path | |
from datetime import datetime | |
import trello | |
from lib import trellodb | |
from lib import conf | |
from twilio.rest import TwilioRestClient | |
def create_barcode_opp(trello_db, barcode): | |
"""Creates a learning opportunity for the given barcode and writes it to Trello. | |
Returns the dict.""" | |
opp = { | |
'type': 'barcode', | |
'opp_id': 'testabc123', | |
'barcode': barcode, | |
'created_dt': datetime.now().strftime('%Y-%m-%d %H:%M:%S') | |
} | |
trello_db.insert('learning_opportunities', opp) | |
return opp | |
def publish_barcode_opp(opp): | |
client = TwilioRestClient(conf.get()['twilio_sid'], conf.get()['twilio_token']) | |
message = client.sms.messages.create(body='''Test for https://github.com/danslimmon/oscar/issues/13''', | |
to='+{0}'.format(conf.get()['twilio_dest']), | |
from_='+{0}'.format(conf.get()['twilio_src'])) | |
trello_api = trello.TrelloApi(conf.get()['trello_app_key']) | |
trello_api.set_token(conf.get()['trello_token']) | |
trello_db = trellodb.TrelloDB(trello_api, conf.get()['trello_db_board']) | |
# First we test the creation of a barcode learning opportunity | |
print 'Before creating barcode opp, the contents of learning_opportunities is:' | |
print trello_db.get_all('learning_opportunities') | |
opp = create_barcode_opp(trello_db, '01234567890') | |
print 'After creating barcode opp, the contents of learning_opportunities is:' | |
print trello_db.get_all('learning_opportunities') | |
# Now we test the notification system | |
print 'Testing notification' | |
publish_barcode_opp(opp) | |
print 'You should receive a text via Twilio now...' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment