Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import datetime
- import string,cgi,time
- from os import curdir, sep
- from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
- #import pri
- class MyHandler(BaseHTTPRequestHandler):
- print "wrking"
- book = {'andrew':'test'}
- language = ["English","French","Italian","Russian"];
- translations = [
- ["language","military","economy","culture","country","member","design","study","activity","sound","music","house","war","peace","air","water","land","correct","long","word"],
- ["langage","militaire","économie","culture","pays","membre","conception","étude","activité","bruit","musique","maison","guerre","paix","air","leau","terre","correct","longtemps","mot"],
- ["linguaggio","militare","economia","cultura","paese","membro","disegno","studio","attività","suono","musica","casa","guerra","pace","aria","acqua","terra","corretto","lungamente","parola"],
- ["язык","воинско","экономия","культура","страна","член","конструкция","изучение","деятельность","звук","нот","дом","война","мир","воздух","вода","земля","правильно","длиной","слово"]
- ]
- rating = []
- for i in range(20):
- rating.append([])
- for j in range(4):
- rating[i].append(0)
- user = []
- for i in range(20):
- user.append([])
- for j in range(4):
- user[i].append("default")
- now = datetime.datetime.now()
- time = []
- for i in range(20):
- time.append([])
- for j in range(4):
- time[i].append(str(now.hour)+":"+str(now.minute)+":"+str(now.second))
- currentUser = "default"
- def do_GET(self):
- global translations
- global rating
- global user
- global time
- global currentUser
- try:
- if (self.path.partition('?'))[2].startswith("CT"):
- subS = ((self.path.partition('?'))[2].partition("&"))[2]
- changeT = (subS.partition("="))[0]
- index1 = ((subS.partition("="))[2].partition("="))[0]
- index2 = ((((subS.partition("="))[2].partition("="))[2]).partition("&"))[0]
- translations[index1][index2] = changeT
- time[index1][index2] = ((((subS.partition("="))[2].partition("="))[2]).partition("&"))[2]
- user[index1][index2] = currentUser;
- rating[index1][index2] = 0;
- elif (self.path.partition('?'))[2].startswith("UR"):
- subString = ((self.path.partition('?'))[2].partition("&"))[2]
- changeR = int((subString.partition("="))[0])
- indexR1 = ((subString.partition("="))[2].partition("="))[0]
- indexR2 = ((subString.partition("="))[2].partition("="))[2]
- rating[indexR1][indexR2] = changeR
- else:
- #account = bufferstring
- #password = bufferstring2
- temp = (self.path.partition('?'))[2]
- account = (temp.partition('='))[0]
- password = (temp.partition('='))[2]
- #if account is in dictionary then u check if the password matches
- if book.has_key(account):
- if book[account] == password:
- returnvalue = "true"
- currentUser = account;
- else:
- returnvalue = "false"
- else:
- returnvalue="false"
- self.send_response(200)
- self.send_header('Content-type','text/plain')
- self.end_headers()
- self.wfile.write(returnvalue)
- except IOError:
- self.send_error(404)
- def do_POST(self):
- global translations, rating, user, time
- returnS = ""
- for x in range(20):
- for y in range(4):
- print str(x)+" "+str(y)
- returnS += (translations[y][x])+"&"+str(rating[x][y])+"&"+user[x][y]+"&"+time[x][y]+"&"
- self.send_response(200)
- self.send_header('Content-type','text/plain')
- self.end_headers()
- self.wfile.write(returnS)
- def main():
- try:
- server = HTTPServer(('', 2181), MyHandler)
- print 'started httpserver...'
- server.serve_forever()
- except KeyboardInterrupt:
- print '^C received, shutting down server'
- server.socket.close()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement