OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This Source Code is subject to the terms of the Mozilla Public License | 3 # This Source Code is subject to the terms of the Mozilla Public License |
4 # version 2.0 (the "License"). You can obtain a copy of the License at | 4 # version 2.0 (the "License"). You can obtain a copy of the License at |
5 # http://mozilla.org/MPL/2.0/. | 5 # http://mozilla.org/MPL/2.0/. |
6 | 6 |
7 import os, MySQLdb, simplejson as json | 7 import os, MySQLdb, simplejson as json |
8 from urlparse import parse_qs | 8 from urlparse import parse_qs |
9 from sitescripts.web import url_handler | 9 from sitescripts.web import url_handler |
10 from sitescripts.utils import cached, get_config, setupStderr | 10 from sitescripts.utils import cached, get_config, setupStderr |
11 | 11 |
12 @url_handler("/submitData") | 12 @url_handler("/submitData") |
13 def submit_data(environ, start_response): | 13 def submit_data(environ, start_response): |
14 setupStderr(environ['wsgi.errors']) | 14 setupStderr(environ["wsgi.errors"]) |
15 | 15 |
16 if environ["REQUEST_METHOD"].upper() != "POST": | 16 if environ["REQUEST_METHOD"].upper() != "POST": |
17 return showError("Unsupported request method", start_response) | 17 return showError("Unsupported request method", start_response) |
18 | 18 |
19 params = parse_qs(environ.get("QUERY_STRING", "")) | 19 params = parse_qs(environ.get("QUERY_STRING", "")) |
20 requestVersion = params.get("version", ["0"])[0] | 20 requestVersion = params.get("version", ["0"])[0] |
21 data = "{}" | 21 data = "{}" |
22 try: | 22 try: |
23 data_length = int(environ.get("CONTENT_LENGTH", "0")) | 23 data_length = int(environ.get("CONTENT_LENGTH", "0")) |
24 except ValueError: | 24 except ValueError: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 result = cursor.fetchone() | 67 result = cursor.fetchone() |
68 if result == None: | 68 if result == None: |
69 cursor.execute("INSERT INTO domains(domain) VALUES (%s)", (domain)) | 69 cursor.execute("INSERT INTO domains(domain) VALUES (%s)", (domain)) |
70 return db.insert_id() | 70 return db.insert_id() |
71 else: | 71 else: |
72 return result["id"] | 72 return result["id"] |
73 | 73 |
74 def _increment_entry(db, domain_id, status): | 74 def _increment_entry(db, domain_id, status): |
75 cursor = db.cursor(MySQLdb.cursors.DictCursor) | 75 cursor = db.cursor(MySQLdb.cursors.DictCursor) |
76 cursor.execute("INSERT INTO corrections(domain, status, curr_month, prev_month
, curr_year, prev_year) VALUES (%s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE
curr_month = curr_month + 1, curr_year = curr_year + 1", (domain_id, status, 1,
0, 1, 0)) | 76 cursor.execute("INSERT INTO corrections(domain, status, curr_month, prev_month
, curr_year, prev_year) VALUES (%s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE
curr_month = curr_month + 1, curr_year = curr_year + 1", (domain_id, status, 1,
0, 1, 0)) |
OLD | NEW |