Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 593a08ab1cb4a09eb953045a7f7383a7b889811c 1 parent afe6d57
Hugoagogo authored

Showing 3 changed files with 36 additions and 12 deletions. Show diff stats Hide diff stats

  1. +4 0 CHANGELOG.txt
  2. +4 1 README.txt
  3. +28 11 main.py
4 CHANGELOG.txt
... ... @@ -0,0 +1,4 @@
  1 +Changelog
  2 +13/9/10
  3 + - Added tick url
  4 + - Rearranged stuff a bit
5 README.txt
@@ -7,4 +7,7 @@ Example
7 7 To use the tracker visit
8 8 http://open-track.appspot.com/trk/
9 9 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
10   -Optionally add "?tick=" to the url where seconds is how recently it has been visited the default tick is 60 seconds
  10 +Optionally add "?tick=" to the url where seconds is how recently it has been visited the default tick is 60 seconds
  11 +
  12 +NEW: http://%s/tick/<tracker name>
  13 +provides a way of refreshing yourself in a tracker without retrieveing a list
39 main.py
@@ -12,7 +12,6 @@
12 12 from models import Tracker, Peer
13 13 from datetime import datetime, timedelta
14 14
15   -
16 15 class MainHandler(webapp.RequestHandler):
17 16 def get(self):
18 17 if os.environ.get('HTTP_HOST'):
@@ -35,6 +34,9 @@ def get(self):
35 34
36 35 Optionally add "?tick=<seconds>" to the url where seconds
37 36 is how recently it has been visited the default tick is 60 seconds
  37 +
  38 +NEW: http://%s/tick/<tracker name>
  39 +provides a way of refreshing yourself in a tracker without retrieveing a list
38 40
39 41 \nCurrent Trackers (activity last 24 hours)\n"""%(url))
40 42 trackers = Tracker.all()
@@ -46,17 +48,9 @@ def get(self,key):
46 48 self.response.headers['Content-Type'] = 'text/plain'
47 49 if re.match(r"\w{3,25}",key): ## check if a tracker is valid
48 50 ## Check if the tracker exists, if not create it
49   - tracker = Tracker.all().filter('name =',key).get()
50   - if tracker==None:
51   - tracker = Tracker(name=key)
52   - tracker.put()
53   -
  51 + tracker = GetTracker(key)
54 52 ## Check if the peer making the request is already in the DB, if not add them
55   - p = Peer.all().filter('address =',self.request.remote_addr).filter('tracker =',tracker).get()
56   - if p != None:
57   - p.put()
58   - else:
59   - Peer(address=self.request.remote_addr,tracker=tracker).put()
  53 + Tick(tracker,self.request.remote_addr)
60 54
61 55 ## try getting a given tick if not set the default
62 56 try:
@@ -72,6 +66,14 @@ def get(self,key):
72 66 else:
73 67 self.response.out.write('Tracker must contain only numbers, letters and the underscore, it must also be between 3 and 25 charachters')
74 68
  69 +class TickHandler(webapp.RequestHandler):
  70 + def get(self,key):
  71 + if re.match(r"\w{3,25}",key): ## check if a tracker is valid
  72 + ## Check if the tracker exists, if not create it
  73 + tracker = GetTracker(key)
  74 + ## Check if the peer making the request is already in the DB, if not add them
  75 + Tick(tracker,self.request.remote_addr)
  76 +
75 77 class CleanHandler(webapp.RequestHandler):
76 78 def get(self):
77 79 ## remove any old peers
@@ -95,6 +97,20 @@ def get(self):
95 97 if trackercount and peercount:
96 98 logging.info("Cleaned %d trackers and %d peers"%(trackercount,peercount))
97 99
  100 +def GetTracker(key):
  101 + """Get a tracker, or create one if it dosent exist"""
  102 + tracker = Tracker.all().filter('name =',key).get()
  103 + if tracker==None:
  104 + tracker = Tracker(name=key)
  105 + tracker.put()
  106 + return tracker
  107 +
  108 +def Tick(tracker,address):
  109 + p = Peer.all().filter('address =',address).filter('tracker =',tracker).get()
  110 + if p != None:
  111 + p.put()
  112 + else:
  113 + Peer(address=address,tracker=tracker).put()
98 114
99 115 def main():
100 116 ## Set up logging, ready for cleaning
@@ -103,6 +119,7 @@ def main():
103 119 ## Set Up URLS
104 120 application = webapp.WSGIApplication([('/', MainHandler),
105 121 ('/trk/(.*?)/?', TrackerHandler),
  122 + ('/tick/(.*?)/?', TickHandler),
106 123 ('/clean/', CleanHandler)],
107 124 debug=True)
108 125 run_wsgi_app(application)

0 comments on commit 593a08a

Please sign in to comment.
Something went wrong with that request. Please try again.