コード例 #1
0
 def cl_insert_git_repos(self):
     ob_db = database()
     ob_db.connect("coding_club")
     ob_db.cursor.execute(
         '''INSERT INTO git_repos VALUES
       (%s,%s) ''', (self.sl_no, self.name_of_repos))
     ob_db.close()
コード例 #2
0
 def insert_contribution(self):
     ob_db = database()
     ob_db.connect("coding_club")
     ob_db.cursor.execute(
         '''INSERT INTO contribution (scholar_id,score,start_date,type_of_contest,id) VALUES
       (%s,%s,
       %s,%s,
       %s) ''', (self.scholar_id, self.score, self.start_date_of_contest,
                 self.type_of_contest, self.id_of_contest))
     ob_db.close()
コード例 #3
0
    def ins(self):

        ob_database = database()
        ob_database.connect("coding_club")
        print "p: ", self.placeholder
        for key, value in kwargs.iteritems():
            print key, value
        self.st1 = "INSERT INTO %s (%s) VALUES (%s) " % (
            self.table_name, self.columns, self.placeholder)
        ob_database.cursor.execute(self.st1, kwargs.values())
        ob_database.close()
コード例 #4
0
    def insert_student_info(self):
        ob_db = database()
        ob_db.connect("coding_club")

        #print (self.scholar_id,self.mail_id,self.name,self.codeforces_h,self.earth_h,self.spoj_h,self.codechef_h,self.github_h), "taken+p"  '''
        ob_db.cursor.execute(
            '''INSERT INTO student_info (sl_no,scholar_id,mail_id,name,codeforces_h,earth_h,spoj_h,codechef_h,github_h,validate,processed) VALUES
                          (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ''',
            (self.sl_no, self.scholar_id, self.mail_id, self.name,
             self.codeforces_h, self.earth_h, self.spoj_h, self.codechef_h,
             self.github_h, self.validate, self.processed))
        ob_db.close()
コード例 #5
0
import urllib2
import json
import pymysql
from json_connection import json_l
from json_connection import database
from util import cl_insert_contribution
from cl_calculation import calculation
from util import gen_ins
from class_contribution import contribution
from contest_list import cl_contest_list

conn = database()
conn.connect("coding_club")
ob_contest_list = cl_contest_list()
ob_contest_list.insert_contest_list()
ob_con = contribution()
ob_con.fetch_id_of_contest()
for current_contest in ob_con.id_contest:
    print("enter")
    ob_con.assign_contest_details(current_contest)
    if ob_con.process == "0":
        ob_con.generate_complete_url(ob_con.id_of_contest)
        print ob_con.url
        ob_data = json_l()
        data = ob_data.fetch_data_from_api(ob_con.url)
        length_of_row = len(data['result']['rows'])
        if length_of_row == 0:
            ob_con.update_processed_of_contest(ob_con.id_of_contest)
            continue
        for i in range(length_of_row):
            handle = data['result']['rows'][i]['party']['members'][0]['handle']
コード例 #6
0
class contribution:
    conn = database()
    conn.connect("coding_club")

    def fetch_scholar_id_and_handle(self):
        self.conn.cursor.execute(
            "SELECT scholar_id,codeforces_h  FROM student_info")
        self.scholar_id_and_handle = self.conn.cursor.fetchall()

    def fetch_scholar_id_and_handle_for_new_user(self):
        self.conn.cursor.execute(
            "SELECT scholar_id,codeforces_h  FROM student_info WHERE validated_user=(%s) AND new_user=(%s)",
            ("1", "1"))
        self.scholar_id_and_handle_new = self.conn.cursor.fetchall()

    def fetch_id_of_contest(self):
        self.conn.cursor.execute(
            "SELECT id ,start_date, processed FROM codeforces_contests ")
        self.id_contest = self.conn.cursor.fetchall()

    def generate_complete_url(self, id_of_contest, status):
        if (status == "old"):
            self.fetch_scholar_id_and_handle()
            self.list_of_scholar_id_and_handle = self.scholar_id_and_handle
        else:
            self.fetch_scholar_id_and_handle_for_new_user()
            self.list_of_scholar_id_and_handle = self.scholar_id_and_handle_new

        self.id_of_contest = id_of_contest
        self.url = "http://codeforces.com/api/contest.standings?contestId="
        self.url += (self.id_of_contest + '&handles=')
        self.e = 0
        for self.row in self.list_of_scholar_id_and_handle:
            self.scholar_no = self.row[0]
            self.c_h = str(self.row[1])
            if self.c_h != None:
                if self.e == 0:
                    self.url = self.url + self.c_h
                    self.e = self.e + 1
                else:
                    self.url = self.url + ';' + self.c_h
        self.url += '&showUnofficial=false'

    def update_processed_of_contest(self, id_of_contest):
        self.conn.cursor.execute(
            '''UPDATE codeforces_contests SET processed=
                  (%s) WHERE id=(%s)''', (True, self.id_of_contest))
        self.conn.db.commit()

    def update_user_status(self):
        self.fetch_scholar_id_and_handle_for_new_user()
        for self.rows in self.scholar_id_and_handle_new:
            self.conn.cursor.execute(
                '''UPDATE student_info SET new_user=
                      (%s) WHERE scholar_id=(%s)''', ("0", self.rows[0]))
        self.conn.db.commit()

    def select_scholar_id_of_a_handle(self, handle):
        self.handle = handle
        self.conn.cursor.execute(
            "SELECT scholar_id from student_info WHERE codeforces_h=(%s)",
            (str(self.handle)))
        self.scholar_id = self.conn.cursor.fetchone()

    def assign_contest_details(self, current_contest):
        self.current_contest = current_contest
        self.process = self.current_contest[2]
        self.id_of_contest = str(self.current_contest[0])
        self.start_date_of_contest = self.current_contest[1]