I have an web app (written in python) that is part of a service that has an ongoing enrollment. Part of the enrollment process involves users filling out a Qualtrics survey and choosing dates and times they would like to get text messages (from Twilio). Users don't use their Google accounts or interact with the web app directly. It's main function is just to integrate these services.
I currently have two cron jobs. 1. One that gets user preferences from an external source's API. 2. The other cron job is supposed to send the SMSes based on user preferences. I have a couple of issues. 1. The first cron job works to a limited extent. It only writes the last person's preferences into the Datastore, not the whole batch of people. My hunch is that it might be writing entities at a higher rate than allowed, and that I might have to use a *task queue or use deferred*. I haven't really found any similar examples that I can use in the official GAE documentation or anywhere else. However, even if I am able to write all of these people's preferences into the Datastore I am left with *duplicate entities* that are created every time the cron job runs. This is a big problem when running the second cron job that sends the texts because it will end up sending multiple texts to each person. This brings me to issue number two. 2. What I understood from the documentation is that GAE doesn't distinguish between creating entities and updating them. So, with that in mind I would just like to completely *overwrite the existing Datastore with the new data* gathered from the the cron job that runs a few times a day but haven't come across any code explaining how to do this. I'm a newbie, so I based my code on the GAE Getting Started example<https://developers.google.com/appengine/docs/python/gettingstartedpython27/usingdatastore>with the Greeting entity. I kept the html form bit to be able to directly input data into the Datastore to test it out. These are the important bits from my main.py: Enter code here... class Greeting(db.Model): """Models an individual Guestbook entry with an author, content, and date.""" date = db.DateTimeProperty(auto_now_add=True) author = db.StringProperty() phone = db.PhoneNumberProperty() email = db.EmailProperty() recipientid = db.StringProperty() preference = db.StringProperty() gaeTuesday1 = db.IntegerProperty(default=0) gaeTuesday2 = db.IntegerProperty(default=0) gaeTuesday3 = db.IntegerProperty(default=0) gaeTuesday4 = db.IntegerProperty(default=0) gaeTuesday5 = db.IntegerProperty(default=0) gaeWednesday1 = db.IntegerProperty(default=0) gaeWednesday2 = db.IntegerProperty(default=0) gaeWednesday3 = db.IntegerProperty(default=0) gaeWednesday4 = db.IntegerProperty(default=0) gaeWednesday5 = db.IntegerProperty(default=0) gaeThursday1 = db.IntegerProperty(default=0) gaeThursday2 = db.IntegerProperty(default=0) gaeThursday3 = db.IntegerProperty(default=0) gaeThursday4 = db.IntegerProperty(default=0) gaeThursday5 = db.IntegerProperty(default=0) content = db.StringProperty(multiline=True) class Preferences(webapp2.RequestHandler): """Gets user schedule preferences from submitted Qualtrics survey""" def get(self): guestbook_name = self.request.get('guestbook_name') greeting = Greeting(parent=guestbook_key(guestbook_name)) for i in range(0, Recipients): recipient = people[i] recipient = people[i] email = recipient.Email.text guid = recipient.RecipientID.text fname = recipient.FirstName.text ED = recipient.EmbeddedData interested = [] if ED.find("./PhoneNumber") != None: phone = convert_to_e164(ED.PhoneNumber.text) if ED.find("./A_Tuesday") != None: greeting.recipientid = recipient.RecipientID.text greeting.phone = phone greeting.preference = ED.Sprint_Option.text greeting.gaeTuesday1 = int(ED.A_Tuesday.text) greeting.gaeTuesday2 = int(ED.B_Tuesday.text) greeting.gaeTuesday3 = int(ED.C_Tuesday.text) greeting.gaeTuesday4 = int(ED.D_Tuesday.text) greeting.gaeTuesday5 = int(ED.E_Tuesday.text) greeting.gaeWednesday1 = int(ED.A_Wednesday.text) greeting.gaeWednesday2 = int(ED.B_Wednesday.text) greeting.gaeWednesday3 = int(ED.C_Wednesday.text) greeting.gaeWednesday4 = int(ED.D_Wednesday.text) greeting.gaeWednesday5 = int(ED.E_Wednesday.text) greeting.gaeThursday1 = int(ED.A_Thursday.text) greeting.gaeThursday2 = int(ED.B_Thursday.text) greeting.gaeThursday3 = int(ED.C_Thursday.text) greeting.gaeThursday4 = int(ED.D_Thursday.text) greeting.gaeThursday5 = int(ED.E_Thursday.text) greeting.put() app = webapp2.WSGIApplication([('/', MainPage), ('/sign', Guestbook), ('/cron/userprefs', Preferences)], debug=True) In the second cron job that sends the texts I borrowed from a Queue script<http://www.blog.pythonlibrary.org/2012/08/01/python-concurrency-an-example-of-a-queue/>. Instead of downloading files I made it send texts. It works in the development environment to a certain extent. I haven't completely figured out if it's compatible with GAE, though, as an alternative to native GAE task queue. Any help is appreciated. -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-appengine?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
