Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bottle, time
- from bottle.ext import sqlite
- app = bottle.Bottle()
- plugin = sqlite.Plugin(dbfile="data.db")
- app.install(plugin)
- def counter2(db):
- ip = bottle.request["REMOTE_ADDR"]
- now = int(time.time())
- print(now)
- strin = db.execute("select ip, last_time from ips where ip=? ", (ip,))
- string = strin.fetchone()
- if string:
- t = int(string[1])
- if now - t > 60:
- db.execute('insert into ips values(?,?)', (ip, str(now)))
- else:
- db.execute('insert into ips values(?,?)', (ip, str(now)))
- countCurs = db.execute('select count(*) as counter from ips')
- return countCurs.fetchone()["counter"]
- @app.route('/')
- def root(db):
- return "<h1>hello</h1>"+str(counter2(db))
- app.run(host='localhost', port=8080, debug=True, reloader=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement