Ejemplo n.º 1
0
 def match_info(self, html):
     title = use_re(RE_Problem[self.oj][1], html)
     if self.oj == 'poj':
         time_limit_c = use_re(RE_Problem[self.oj][2], html)
         memory_limit_c = use_re(RE_Problem[self.oj][3], html)
         time_limit_java = str(2 * int(time_limit_c))
         memory_limit_java = memory_limit_c
     else:
         time_limit_java, time_limit_c = use_re(RE_Problem[self.oj][2], html, 2)
         memory_limit_java, memory_limit_c = use_re(RE_Problem[self.oj][3], html, 2)
     path = '/upload/' + self.oj + "/" + str(self.problem_id) + "/"
     path = path.encode("utf-8")
     description = use_re(RE_Problem[self.oj][4], html)
     problem_input = use_re(RE_Problem[self.oj][5], html)
     problem_output = use_re(RE_Problem[self.oj][6], html)
     s_input = use_re(RE_Problem[self.oj][7], html)
     s_output = use_re(RE_Problem[self.oj][8], html)
     hint = use_re(RE_Problem[self.oj][9], html)
     self.find_img(description + problem_input + problem_output + hint)
     if hint:
         if self.oj == 'hdu':
             s_output = s_output[0:-4]
         hint = re.sub(IMG_Replace[self.oj], path, hint.replace('../', ''))
     description = re.sub(IMG_Replace[self.oj], path, description.replace('../', ''))
     problem_input = re.sub(IMG_Replace[self.oj], path, problem_input.replace('../', ''))
     problem_output = re.sub(IMG_Replace[self.oj], path, problem_output.replace('../', ''))
     source = use_re(RE_Problem[self.oj][10], html)
     sql = """
           UPDATE problem_problem SET
             title='%s',
             time_limit_c='%s',
             time_limit_java='%s',
             memory_limit_c='%s',
             memory_limit_java='%s',
             description='%s',
             input='%s',
             output='%s',
             sample_input='%s',
             sample_output='%s',
             hint='%s',
             source='%s',
             defunct=100
             WHERE id='%s'
           """ % (
         self.mysql.db.escape_string(title),
         self.mysql.db.escape_string(time_limit_c),
         self.mysql.db.escape_string(time_limit_java),
         self.mysql.db.escape_string(memory_limit_c),
         self.mysql.db.escape_string(memory_limit_java),
         self.mysql.db.escape_string(description),
         self.mysql.db.escape_string(problem_input),
         self.mysql.db.escape_string(problem_output),
         self.mysql.db.escape_string(s_input),
         self.mysql.db.escape_string(s_output),
         self.mysql.db.escape_string(hint),
         self.mysql.db.escape_string(source),
         self.pid
     )
     self.mysql.update(sql)
     logging.info("Download Problem: " + self.oj + "-" + str(self.problem_id) + " Info Over")
Ejemplo n.º 2
0
 def save_img(self, url, problem_id=''):
     filename = url.split('/')[-1]
     path = os.path.join(STATIC_PATH, 'upload', self.oj, str(problem_id))
     make_dir(path)
     path = os.path.join(path, filename)
     if url[0:4] != 'http':
         if self.oj == 'hdu_std':
             url = OJ_Index['hdu'] + url
         else:
             url = OJ_Index[self.oj] + url
     try:
         urllib.urlretrieve(url, path)
     except:
         logging.warning("Get Image ERROR!!!")
     else:
         logging.info("Download image <%s> over" % (filename))
Ejemplo n.º 3
0
 def login(self, cid=None):
     if cid is not None:
         url = Login_URL[self.oj] % cid
     else:
         url = Login_URL[self.oj]
     try:
         html = self.visit(url, self.postdata)
     except VisitError:
         logging.info("OJ:" + self.oj + " USER: "******" NOT Login!!!")
         return False
     if not self.judge_password(html):
         logging.warning("Login ERRER!!! No Such User!!!")
         return False
     else:
         if self.is_login(cid):
             logging.info("OJ:" + self.oj + " USER: "******" Logined")
             return True
         else:
             logging.info("OJ:" + self.oj + " USER: "******" NOT Login!!!")
             return False