In the first part it was shown how to write the simplest wrapper around the existing http API. In this part we will continue and write the current monitoring with notification to the post office. The project site is still
here and
here spare .
In the first part, the application was
not threadsafe, i.e. in the
app.yaml settings,
it appeared:
threadsafe: false
correct this situation, change:
def main(): application.run() if __name__ == "__main__": main()
on:
app = webapp2.WSGIApplication([ ('/', MainPage), ], debug=False)
')
Naturally, I also had to rewrite some code, the gain from all of this is the following: with
threadsafe: false, appengine puts new sessions in a queue and starts a new instance for each session (with a small time lag), with
threadsafe enabled,
it is assumed that the developer correctly implemented multi-threaded logic.
Next, it was necessary to solve two questions: mail and launching over the crown, let's start with the crown: to do this, create the cron.yaml file in the working
directory and specify where and how often the cron daemon should be addressed:
cron: - description: mail summary job url: /summary_mail schedule: every 1 hours
On
/summary_mail
hang up the handler for mailing to active accounts, and in order for bad uncles to pull it themselves and as a result - to eat all our quotas and spam active users, you need to restrict access to it only for admins and google krone, add to
app.yaml lines :
- url: /summary_mail script: web.app login: admin
The list of admins for the application is configured from the administrator's console (guys are
schoolchildren hackers, do not worry, there is no admin in this application and you don’t need to try to “punch” it, because as it followed from the logs when publishing last post, there were experts ..., this console is provided by appengine).
For a while, I thought about what to do with the mailing list, screwing a third-party captcha or doing my own, eventually went the simplest way - I use Google account and after going through Google authorization (naturally everything goes through the redirect and I don’t store any passwords) user's mailbox to which he will receive letters about free places. Functions for working with mail is the simplest:
def sendMail(account, body): mail.send_mail(sender = "rzd wrapper support <robot.sender.rzd@gmail.com>", to = account.email(), subject = "train report", html = body, body = body)
Yes, the body of the letter in the textual representation and html is the same for me, but I will soon fix it.
For the sake of completeness, it’s necessary to say
that the radioactive sources are still here , of course, I will bring order there over time, rare ones can also be observed, but errors occur during operation, because Russian Railways is not perfect, and I could put straw where I think it’s not everywhere , in general, the functionality is quite working; everyone can start their local application from source and finish it to their own needs. Kroner polls the availability of tickets once an hour. At the moment, you can only subscribe to one train. In the future plans to fasten
Jinja2 and make a more pleasant interface, just try to implement on APPENGINE an interface to
open source morphology and do something like a spell checker. I hope this service will be useful for someone else.