Permalink
Browse files

Added the tick url, rearranged a few things and added changelog

  • Loading branch information...
1 parent afe6d57 commit 593a08ab1cb4a09eb953045a7f7383a7b889811c @Hugoagogo committed Sep 13, 2010
Showing with 36 additions and 12 deletions.
  1. +4 −0 CHANGELOG.txt
  2. +4 −1 README.txt
  3. +28 −11 main.py
View
@@ -0,0 +1,4 @@
+Changelog
+13/9/10
+ - Added tick url
+ - Rearranged stuff a bit
View
@@ -7,4 +7,7 @@ Example
To use the tracker visit
http://open-track.appspot.com/trk/
The tracker does not need to be setup beforhand It will return a list of IP adresses that have visited that tracker and add yours to the list
-Optionally add "?tick=" to the url where seconds is how recently it has been visited the default tick is 60 seconds
+Optionally add "?tick=" to the url where seconds is how recently it has been visited the default tick is 60 seconds
+
+NEW: http://%s/tick/<tracker name>
+provides a way of refreshing yourself in a tracker without retrieveing a list
View
39 main.py
@@ -12,7 +12,6 @@
from models import Tracker, Peer
from datetime import datetime, timedelta
-
class MainHandler(webapp.RequestHandler):
def get(self):
if os.environ.get('HTTP_HOST'):
@@ -35,6 +34,9 @@ def get(self):
Optionally add "?tick=<seconds>" to the url where seconds
is how recently it has been visited the default tick is 60 seconds
+
+NEW: http://%s/tick/<tracker name>
+provides a way of refreshing yourself in a tracker without retrieveing a list
\nCurrent Trackers (activity last 24 hours)\n"""%(url))
trackers = Tracker.all()
@@ -46,17 +48,9 @@ def get(self,key):
self.response.headers['Content-Type'] = 'text/plain'
if re.match(r"\w{3,25}",key): ## check if a tracker is valid
## Check if the tracker exists, if not create it
- tracker = Tracker.all().filter('name =',key).get()
- if tracker==None:
- tracker = Tracker(name=key)
- tracker.put()
-
+ tracker = GetTracker(key)
## Check if the peer making the request is already in the DB, if not add them
- p = Peer.all().filter('address =',self.request.remote_addr).filter('tracker =',tracker).get()
- if p != None:
- p.put()
- else:
- Peer(address=self.request.remote_addr,tracker=tracker).put()
+ Tick(tracker,self.request.remote_addr)
## try getting a given tick if not set the default
try:
@@ -72,6 +66,14 @@ def get(self,key):
else:
self.response.out.write('Tracker must contain only numbers, letters and the underscore, it must also be between 3 and 25 charachters')
+class TickHandler(webapp.RequestHandler):
+ def get(self,key):
+ if re.match(r"\w{3,25}",key): ## check if a tracker is valid
+ ## Check if the tracker exists, if not create it
+ tracker = GetTracker(key)
+ ## Check if the peer making the request is already in the DB, if not add them
+ Tick(tracker,self.request.remote_addr)
+
class CleanHandler(webapp.RequestHandler):
def get(self):
## remove any old peers
@@ -95,6 +97,20 @@ def get(self):
if trackercount and peercount:
logging.info("Cleaned %d trackers and %d peers"%(trackercount,peercount))
+def GetTracker(key):
+ """Get a tracker, or create one if it dosent exist"""
+ tracker = Tracker.all().filter('name =',key).get()
+ if tracker==None:
+ tracker = Tracker(name=key)
+ tracker.put()
+ return tracker
+
+def Tick(tracker,address):
+ p = Peer.all().filter('address =',address).filter('tracker =',tracker).get()
+ if p != None:
+ p.put()
+ else:
+ Peer(address=address,tracker=tracker).put()
def main():
## Set up logging, ready for cleaning
@@ -103,6 +119,7 @@ def main():
## Set Up URLS
application = webapp.WSGIApplication([('/', MainHandler),
('/trk/(.*?)/?', TrackerHandler),
+ ('/tick/(.*?)/?', TickHandler),
('/clean/', CleanHandler)],
debug=True)
run_wsgi_app(application)

0 comments on commit 593a08a

Please sign in to comment.