Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import bottle, time
  2. from bottle.ext import sqlite
  3.  
  4.  
  5. app = bottle.Bottle()
  6. plugin = sqlite.Plugin(dbfile="data.db")
  7. app.install(plugin)
  8.  
  9.  
  10. def counter2(db):
  11. ip = bottle.request["REMOTE_ADDR"]
  12. now = int(time.time())
  13. print(now)
  14. strin = db.execute("select ip, last_time from ips where ip=? ", (ip,))
  15. string = strin.fetchone()
  16. if string:
  17. t = int(string[1])
  18. if now - t > 60:
  19. db.execute('insert into ips values(?,?)', (ip, str(now)))
  20. else:
  21. db.execute('insert into ips values(?,?)', (ip, str(now)))
  22. countCurs = db.execute('select count(*) as counter from ips')
  23. return countCurs.fetchone()["counter"]
  24.  
  25.  
  26. @app.route('/')
  27. def root(db):
  28. return "<h1>hello</h1>"+str(counter2(db))
  29.  
  30. app.run(host='localhost', port=8080, debug=True, reloader=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement