]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/updater/base.py
creating some views for the update checker and creating the functions that get the...
[osqa.git] / forum_modules / updater / base.py
1 import string
2 import random
3 import re
4
5 import urllib2
6
7 from forum.models import Question
8 from forum.settings import APP_URL
9
10 def generate_installation_key():
11     gen = lambda length: "".join( [random.choice(string.digits+string.letters) for i in xrange(length)])
12     return '%s-%s-%s-%s' % (gen(4), gen(4), gen(4), gen(4))
13
14 # To get the site views count we get the SUM of all questions views.
15 def get_site_views():
16     views = 0
17
18     # Go through all questions and increase the views count
19     for question in Question.objects.all():
20         views += question.view_count
21
22     return views
23
24 def get_server_name():
25     url = '%s/' % APP_URL
26
27     try:
28         # Make the request
29         request = urllib2.Request(url)
30         response = urllib2.urlopen(request)
31
32         # Get the response information
33         response_info = response.info()
34
35         server_name = re.findall("Server: (?P<server_name>.*)$", str(response_info))[0]
36         server_name = ''.join(server_name.splitlines())
37
38         return server_name
39     except:
40         return 'Unknown'