import json import time import gspread from oauth2client.client import SignedJwtAssertionCredentials from twilio.rest import TwilioRestClient # # json, json_key = json.load(open('.json')) scope = ['https://spreadsheets.google.com/feeds'] credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'].encode(), scope) gc = gspread.authorize(credentials) wks = gc.open("wedding_guests") # workbook- wks_attendees = wks.get_worksheet(0) # ACCOUNT_SID = 'TWILIO_ACCOUNT_SID' AUTH_TOKEN = 'TWILIO_AUTH_TOKEN' client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) # , range for num in range(2, 60): print "sleeping for 2 seconds" time.sleep(2) # guest_number = wks_attendees.acell('B'+str(num)).value guest_name = wks_attendees.acell('A'+str(num)).value Message_body = <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2B50</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2764</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2B50</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2764</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2B50</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2764</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2B50</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2764</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n\n</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2709</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span><span class="pl-s"><span class="pl-pds">"</span> Save the date! <span class="pl-pds">"</span></span><span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2709</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span><span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n\n</span>Lauren Pang and Thomas Curtis are delighted to invite you to our wedding.<span class="pl-cce">\n\n</span>Saturday 3rd September 2016. <span class="pl-cce">\n\n</span>Colville Hall,<span class="pl-cce">\n</span>Chelmsford Road,<span class="pl-cce">\n</span>White Roding,<span class="pl-cce">\n</span>CM6 1RQ.<span class="pl-cce">\n\n</span>The Ceremony begins at 2pm.<span class="pl-cce">\n\n</span>More details will follow shortly!<span class="pl-cce">\n\n</span>Please text YES if you are saving the date and can join us or text NO if sadly, you won't be able to be with us.<span class="pl-cce">\n\n</span><span class="pl-pds">"</span></span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2B50</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2764</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2B50</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2764</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2B50</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2764</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2B50</span><span class="pl-pds">"</span></span> <span class="pl-k">+</span> <span class="pl-s"><span class="pl-k">u</span><span class="pl-pds">"</span><span class="pl-cce">\u2764</span><span class="pl-pds">"</span></span>, if not guest_number: # print guest_name + ' telephone number empty not messaging' wks_attendees.update_acell('E'+str(num), '0') else: print 'Sending message to ' + guest_name client.messages.create( to="+" + guest_number, # + e.164 from_="", # Twillio body=message_body, ) wks_attendees.update_acell('E'+str(num), int(wks_attendees.acell('E'+str(num)).value) + 1) # increment the message count row else: # else- print 'finished'
@app.route("/messages", methods=['GET', 'POST']) def hello_guest(): if "yes" in body_strip: # confirmation_status wks_attendees.update_acell("F"+str(guest_confirmation_cell.row), 'Accepted') # « » resp.message(u"\u2665" + "Thanks for confirming, we'll be in touch!" + u"\u2665") # r , elif "no" in from_body.lower(): # « » wks_attendees.update_acell("F"+str(guest_confirmation_cell.row), 'Declined') # resp.message("Sorry to hear that, we still love you though!") else: # , resp.message("You sent a different keyword, we need a yes or a no, you sent: "+ from_body) return str(resp)
# guest_confirmed = wks_attendees.acell('C70').value guest_unconfirmed = wks_attendees.acell('C71').value guest_no_response = wks_attendees.acell('C72').value guest_acceptance = wks_attendees.acell('C73').value elif "numbers" in from_body.lower(): # ( - , ) resp.message("RSVP update:\n\nTotal Accepted: " + guest_confirmed "\n\nTotal declined: " guest_unconfirmed "\n\nTotal no response: "+ guest_no_response + "\n\nTotal acceptance rate: " + guest_acceptance)
import json import time import gspread from oauth2client.client import SignedJwtAssertionCredentials from twilio.rest import TwilioRestClient # json, json_key = json.load(open('')) scope = ['https://spreadsheets.google.com/feeds'] credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'].encode(), scope) gc = gspread.authorize(credentials) wks = gc.open("") # wks_attendees = wks.get_worksheet(0) # wks_food = wks.get_worksheet(1) # ACCOUNT_SID = 'TWILIO_ACCOUNT_SID' AUTH_TOKEN = 'TWILIO_AUTH_TOKEN' client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) # . - for num in range(2, 60): food_guest_name = wks_food.acell('B'+str(num)).value # if food_guest_name: attendees_name = wks_attendees.find(val_food_guest_name).value attendees_name_row = wks_attendees.find(val_food_guest_name).row menu_status = wks_attendees.acell("G"+str(attendees_name_row)).value if food_guest_name == attendees_name: print if menu_status == 'Y': # , print('Skipping') else: # , print ('Food sheet name ' + food_guest_name + 'Attendees sheet name ' + attendees_name) # wks_attendees.update_acell("G"+str(attendees_name_row), 'Y') else: print('nothing found, moving on') wks_attendees.update_acell('E'+str(num), int(wks.acell('E'+str(num)).value) + 1) # else: # client.messages.create(from_="", # Twillio to="", # body="Finished processing current meal listnnGuest meals confirmed" + guest_meals_confirmed + "\n\nGuest meals unconfirmed: " + guest_meals_unconfirmed)
# elif "food" in body_strip.strip(): resp.message("Guest meals decided:" + guest_meals_confirmed + "\nGuest meals undecided: " + guest_meals_unconfirmed + "\n\nMenu breakdown:\n\n" + starter_option_1 +": " + starter_option_1_amount + "\n" + starter_option_2 +": " + starter_option_2_amount + "\n" + starter_option_3 +": " + starter_option_3_amount + "\n" + main_option_1 +": " + main_option_1_amount + "\n" + main_option_2 +": " + main_option_2_amount + "\n" + main_option_3 +": " + main_option_3_amount + "\n" + dessert_option_1 + ": " + dessert_option_1_amount + "\n" + dessert_option_2 + ": " + dessert_option_2_amount)
for num in range(2, 72): # print "sleeping for 3 seconds" time.sleep(3) # wedding_guest_number = wks_attendees.acell('B'+str(num)).value # wedding_guest_name = wks_attendees.acell('A'+str(num)).value # menu_guest = wks_attendees.acell('G'+str(num)).value if not wedding_guest_number: print wedding_guest_name+' telephone number empty not messaging' # , . wks_attendees.update_acell('H'+str(num), '1') # else: if menu_guest == "N": # ! ! print 'Sending message to '+wedding_guest_name client.messages.create( to="+" + wedding_guest_number, from_="", # Twillio body="If you have received this message, you have not chosen your food options for Tom & Lauren's Wedding!\n\nYou can pick your choices via the website, no paper or postage required!\n\nhttp://www.yourwebsitehere.com/food" ) wks_attendees.update_acell('H'+str(num), int(wks_attendees.acell('H'+str(num)).value) + 1) # else: # else- print 'finished'
Source: https://habr.com/ru/post/402827/
All Articles