-
Notifications
You must be signed in to change notification settings - Fork 3
/
groupname.py
52 lines (39 loc) · 1.67 KB
/
groupname.py
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
52
#!/usr/bin/python
#Licensed under the GPLv2 (not later versions)
#see LICENSE.txt for details
import os
import lindenip
import logging
import string
import wsgiref.handlers
from google.appengine.api import urlfetch
from google.appengine.ext import webapp
class GetGroupName(webapp.RequestHandler):
def get(self):
if lindenip.inrange(os.environ['REMOTE_ADDR']) != 'Production':
self.error(403)
else:
groupKey = self.request.get('group')
uplook_url = 'http://world.secondlife.com/group/%s' % groupKey
answer = urlfetch.fetch(uplook_url, method="GET", follow_redirects=True)
if answer.status_code == 200:
body = answer.content
if 'AccessDenied' in body:
logging.info ('Group not found: %s' % groupKey)
self.response.out.write('X')
else:
startpos = string.find(body,"<title>") + 7
endpos = string.find(body,"</title>")
groupname = body[startpos:endpos]
logging.info ('Group name for %s resolved: %s' % (groupKey, groupname))
self.response.out.write(groupname)
else:
logging.info ('Error on group lookup answer: %d' % answer.status_code)
self.response.out.write('X')
def main():
application = webapp.WSGIApplication([
(r'/.*?/GetGroupName',GetGroupName)
], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()