title: How to update and insert records after every 1 minute in sqlite?
body: <p>I have created a django project which contains one table. I want to automatically update the records in sqlite databse after every minute. How can be this done?</p>
  <p>I have already used time.sleep(18000) library of python but it didn't worked.</p>
  <p>In if:else statement insert and update operations are performed.</p>
  <p><strong>views.py:</strong></p>
  <pre><code>
  def index(request):
      while True: 
          r1 = requests.get(&quot;http://127.0.0.1:2000/_nodes&quot;)
          script = r1.json()
          write = script['nodes']['data']
          ts1 = script['nodes']['time']
          print(&quot;write   &quot;,write)
          print(&quot;ts1  &quot;,ts1)
  
          r2 = requests.get(&quot;http://127.0.0.1:2000/_nodes&quot;)
          script = r2.json()
          read = script['nodes']['total']
          ts2 = script['nodes']['time']
          print(&quot;read   &quot;,read)
          print(&quot;ts2  &quot;,ts2)
  
          new_count = write+read
          new_t = (ts1+ts2)/2
          print (&quot;new count&quot;, new_count)
          print(&quot;new ts&quot;, new_t)
  
          q = data.objects.filter()
  
          if q.exists():
              test1 = data.fetch()
              for row in test1:
                  test1={
                      'id':row.id,
                      'sum': row.sum,
                      'ts': row.ts,
                      'status': row.status
                      }
              prev_t = test1['ts']
              prev_count = test1['sum']
  
              if(test1['id']==1):
                  if(new_count &lt; prev_count):
                      test2 = data.objects.get(id=1)
                      print(&quot;TEST2 Type&quot;, type(test2))
                      print(test2)
                      test2 = data(id=1,sum=new_count,ts=new_t,status=&quot;restarted&quot;)
                      test2.save()
                      print(test2)
                      print(type(test2))
                  else:
                      test1 = data.fetch()
                      test2 = data.objects.get(id=1)
                      print(&quot;TEST2 Type&quot;, type(test2))
                      print(test2)
                      test2 = data(id=1,sum=new_count,ts=new_t,status=&quot;updated&quot;)
                      test2.save()
                      print(test2)
                      print(type(test2))
     
          else:
              test2 = data(id=1,sum=new_count,ts=new_t,status=&quot;firstQuery&quot;)
              test2.save()
              print (test2)
              print(&quot;Fresh record created&quot;)
              test2 = data.fetch()
              for row2 in test2:
                  test2={
                      'id':row2.id,
                      'sum': row2.sum,
                      'ts': row2.ts,
                      'status': row2.status
                  }
                  print(test2)
                  print(type(test2))
  
  </code></pre>