Browse Source

Implement basic api export of all active hosts

Done by zzz request. Export all seen hosts in json format { b32: last_seen }.
pull/1/head
Hidden Z 11 years ago
parent
commit
3880aa9f0f
  1. 0
      pyi2phosts/api/__init__.py
  2. 5
      pyi2phosts/api/urls.py
  3. 16
      pyi2phosts/api/views.py
  4. 1
      pyi2phosts/urls.py

0
pyi2phosts/api/__init__.py

5
pyi2phosts/api/urls.py

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
from django.conf.urls import *
urlpatterns = patterns('pyi2phosts.api.views',
url(r'^all/$', 'all'),
)

16
pyi2phosts/api/views.py

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
import simplejson as json
from django.http import HttpResponse
from pyi2phosts.postkey.models import i2phost
from pyi2phosts.lib.utils import get_b32
def all(request):
"""Return all hosts in { "b32": "last seen timestamp" } form. Implemented by zzz request. """
# all hosts seen at least once
queryset = i2phost.objects.exclude(last_seen=None)
json_dict = {}
for host in queryset:
# pass last_seen to json in unixtime
json_dict[get_b32(host.b64hash)] = host.last_seen.strftime("%s")
return HttpResponse(json.dumps(json_dict), mimetype="application/json")

1
pyi2phosts/urls.py

@ -23,6 +23,7 @@ urlpatterns = patterns('', @@ -23,6 +23,7 @@ urlpatterns = patterns('',
(r'^search/$', include('pyi2phosts.search.urls')),
(r'^postkey/', include('pyi2phosts.postkey.urls')),
(r'^jump/', include('pyi2phosts.jump.urls')),
(r'^api/', include('pyi2phosts.api.urls')),
(r'^i18n/', include('django.conf.urls.i18n')),
# Example:
# (r'^pyi2phosts.', include('pyi2phosts.foo.urls')),

Loading…
Cancel
Save