title: Call a function in Python file using Flask
body: <p>I have python file called testing_file.py:</p>
  
  <pre><code>    from datetime import datetime
      import MySQLdb
  
      # Open database connection
      class DB():
          def __init__(self, server, user, password, db_name):
              db = MySQLdb.connect(server, user, password, db_name )
              self.cur = db.cursor()
  
          def time_statistic(self, start_date, end_date):
  
              time_list = {}
  
              sql = "SELECT activity_log.datetime, activity_log.user_id FROM activity_log"
              self.cur.execute(sql)
              self.date_data = self.cur.fetchall()
              for content in self.date_data:
  
                  timestamp = str(content[0])
                  datetime_object = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
                  timestamps = datetime.strftime(datetime_object, "%Y-%m-%d")
  
                  if start_dt &lt;= timestamps and timestamps &lt;= end_dt:
                      if timestamps not in time_list:
                          time_list[timestamps]=1
                      else:
                          time_list[timestamps]+=1
  
                      return json.dumps(time_list)
  
      start_date = datetime.strptime(str('2017-4-7'), '%Y-%m-%d')
      start_dt = datetime.strftime(start_date, "%Y-%m-%d")
      end_date = datetime.strptime(str('2017-5-4'), '%Y-%m-%d')
      end_dt = datetime.strftime(end_date, "%Y-%m-%d")        
  
      db = DB("host","user_db","pass_db","db_name")
      db.time_statistic(start_date, end_date)
  </code></pre>
  
  <p>I want to access the result <code>(time_list)</code> thru API using Flask. This is what i've wrote so far, doesn't work and also I've tried another way:</p>
  
  <pre><code>    from flask import Flask
      from testing_api import *
  
      app = Flask(__name__)
  
      @app.route("/")
      def get():
          db = DB("host","user_db","pass_db","db_name")
          d = db.time_statistic()
          return d
  
      if __name__ == "__main__":
          app.run(debug=True)
  </code></pre>
  
  <p>Question: This is my first time work with API and Flask. Can anyone please help me thru this. Any hints are appreciated. Thank you</p>
  
  <p>I've got empty list as result {}</p>