-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.py
More file actions
51 lines (40 loc) · 1.38 KB
/
Copy pathscrape.py
File metadata and controls
51 lines (40 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python2.4
"""One-line documentation for helloworld module.
A detailed description of helloworld.
"""
__author__ = 'allen@thebends.org (Allen Porter)'
import os
import base64
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext import db
import model
import util
from BTL import bencode
class MainPage(webapp.RequestHandler):
def __init__(self):
self._files = { }
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
info_hash = util.GetParam('info_hash')
if len(info_hash) == 20:
torrents = model.Torrent.gql("WHERE info_hash = :1",
base64.b64encode(info_hash))
else:
torrents = model.Torrent.gql("ORDER BY downloaded")
for torrent in torrents:
self.AddResult(torrent)
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write(bencode.bencode(self._files))
def AddResult(self, torrent):
self._files[base64.b64decode(torrent.info_hash)] = {
'complete' : 0, # of seeders
'downloaded' : 0, # 'event=complete' seen
'incomplete' : 0, # leechers
# Optional 'name' in the .torrent
}
application = webapp.WSGIApplication(
[ ( '/scrape', MainPage ) ],
debug=True)
#os.environ['CONTENT_TYPE'] = "%s;charset=utf8" % os.environ['CONTENT_TYPE']
wsgiref.handlers.CGIHandler().run(application)