title: Run a python script on schedule on Google App Engine
body: <p>I'm looking for a good samaritan that can provide with a very basic skeleton to run a python script using Google App Engine. I have read the documentation, check on related SO questions but I'm lost with the WebApp format. All I want to do is run one python script which accepts arguments or several python scripts, 6 times a week to listen to for changes in a website and then post them to Firestore.</p>
  <p>I understand the cron format and most of the configurations files. I'm stuck on how to arrange my files for the project, and how the url's works.</p>
  <p>All I'm asking is a very basic sample on how to effectively run the python scripts.
  <a href="https://tuhrig.de/writing-an-online-scraper-on-google-app-engine-python/" rel="noreferrer">This</a> is by far the best resource that I have found, but I can't really understand what is going on with this code from that site:</p>
  <pre><code>`#!/usr/bin/python
  # -*- coding: utf-8 -*- 
  from __future__ import unicode_literals   
  from google.appengine.ext import webapp 
  from google.appengine.ext.webapp.util import run_wsgi_app 
  from google.appengine.ext import db   
  import feedparser  
  import time   
  
  class Item(db.Model): 
      title = db.StringProperty(required=False)
      link = db.StringProperty(required=False)
      date = db.StringProperty(required=False)   class Scrawler(webapp.RequestHandler):
      
      def get(self):
          self.read_feed()      
          self.response.out.write(self.print_items())
          
      def read_feed(self):
          
          feeds = feedparser.parse( &quot;http://www.techrepublic.com/search?t=14&amp;o=1&amp;mode=rss&quot; )
          
          for feed in feeds[ &quot;items&quot; ]:
              query = Item.gql(&quot;WHERE link = :1&quot;, feed[ &quot;link&quot; ])
              if(query.count() == 0):
                  item = Item()
                  item.title = feed[ &quot;title&quot; ]
                  item.link = feed[ &quot;link&quot; ]
                  item.date = time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;, time.gmtime(time.time()))
                  item.put()
      
      def print_items(self):
          s = &quot;All items:&lt;br&gt;&quot;
          for item in Item.all():
              s += item.date + &quot; - &lt;a href='&quot; + item.link + &quot;'&gt;&quot; + item.title + &quot;&lt;/a&gt;&lt;br&gt;&quot;
          return s   application = webapp.WSGIApplication([('/', Scrawler)], debug=True)   def main():
      run_wsgi_app(application)   if __name__ == &quot;__main__&quot;:
      main() `
  </code></pre>
  <p>This is the python script I tried to run for testing only, using python3.7:</p>
  <pre><code>import sys
  from datetime import datetime
  
  import firebase_admin
  from firebase_admin import firestore
  
  app = firebase_admin.initialize_app()
  db = firestore.client()
  
  
  def hello_firestore(user_name):
      db.collection('firestore_test').document('test').set({
          'time': str(datetime.now()),
          'user_name': user_name
      })
  
  
  if __name__ == &quot;__main__&quot;:
      try:
          user_name = sys.argv[1]
      except:
          print('Error with the argument', file=sys.stderr)
      try:
          hello_firestore(user_name)
      except:
          print('Error accessing the database', file=sys.stderr)
          sys.exit(0)
  </code></pre>
  <p>For what I understand I have to use Flask or something similar to make it work, but I don't really understand how it works, all I'm asking is a small sample and and brief explanation, and from there I'll add two and two.</p>
  <p>Best Regards</p>