Ejemplo n.º 1
0
sys.path.append("../Utilities")
from driverUtil import getDriver

sys.path.append("../DataBase")
import sqlDB

current_progress = {
    'link': "http://codeforces.com/problemset/",
    'problem_no': 0,
    'total_problems': 0
}
logging.basicConfig(filename='exceptScenarios.log', level=logging.ERROR)

h = HTMLParser()
driver = getDriver()
try:
    with open('current_progress.pickle', 'r+b') as f:
        current_progress = pickle.load(f)
        print 'Resuming Progress from page ' + str(
            current_progress['link']) + ' and problem no ' + str(
                current_progress['problem_no'])
except Exception as e:
    print(e)
    exc_type, exc_obj, exc_tb = sys.exc_info()
    print 'Exception at line ' + str(exc_tb.tb_lineno)
    logging.error('Time: {0} File: {1} Line: {2} Caused By: {3}'.format(
        datetime.datetime.now(), os.path.basename(__file__), exc_tb.tb_lineno,
        e))
# logging.error(str(datetime.datetime.now()) + ' :File Name: '+ str(os.path.basename(__file__)) +
# 		' :Line Number: '+ str(exc_tb.tb_lineno) + ' :Caused By: ' + str(e))
Ejemplo n.º 2
0
    except Exception as e:
        # print(e)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        # print('Exception at line '+ str(exc_tb.tb_lineno))
        logging.error(
            'Time: {0} File: {1} Line: {2} User: {3} Caused By: {4}'.format(
                datetime.datetime.now(), os.path.basename(__file__),
                exc_tb.tb_lineno, uname, e))
        prob = None
    else:
        pass
    finally:
        pass


driver = getDriver()
logging.basicConfig(filename='exceptScenarios.log', level=logging.ERROR)

statusPageDriver = getDriver()

# try:
# 	with open('curr_progress', 'r+b') as f:
# 		count = pickle.load(f)
# 		print(count)
# except Exception as e:
# 	# print e
# 	print(e)
# 	exc_type, exc_obj, exc_tb = sys.exc_info()
# 	print('Exception at line '+ str(exc_tb.tb_lineno))
# 	logging.error('Time: {0} File: {1} Line: {2} Caused By: {3}'.format(datetime.datetime.now(), os.path.basename(__file__),
# 				exc_tb.tb_lineno, e))
Ejemplo n.º 3
0
        exc_type, exc_obj, exc_tb = sys.exc_info()
        print 'Exception at line ' + str(exc_tb.tb_lineno)
        logging.error('Time: {0} File: {1} Line: {2} Caused By: {3}'.format(
            datetime.datetime.now(), os.path.basename(__file__),
            exc_tb.tb_lineno, e))
        # logging.error(str(datetime.datetime.now()) + ' :File Name: '+ str(os.path.basename(__file__)) +
        # 		' :Line Number: '+ str(exc_tb.tb_lineno) + ' :Caused By: ' + str(e))
        prob = None
    else:
        pass
    finally:
        pass


# driver = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
driver = getDriver()
# driver = webdriver.Chrome()
# statusDriver = webdriver.Chrome()
statusDriver = getDriver()

logging.basicConfig(filename='exceptScenarios.log', level=logging.ERROR)

count = 0

try:
    with open('curr_progress', 'r+b') as f:
        count = pickle.load(f)
        print count
except Exception as e:
    # print e
    print(e)
def getCodechefProblem(problemUrl, difficulty='unknown'):
    print problemUrl
    driver = getDriver()
    count = 0
    print problemUrl
    # driver = webdriver.Chrome('C:\Users\Pranay\Downloads\Setups\Drivers\chromedriver.exe')
    # submissionPageQuery = "?sort_by=All&sorting_order=asc&language=All&status=15&handle=&Submit=GO"
    #Get problem Name
    problemName = ''
    for c in problemUrl[::-1]:
        if c == '/':
            break
        problemName = problemName + c
    problemName = problemName[::-1]

    driver.get(problemUrl)
    print('reach problem page ' + problemUrl)
    try:
        problemText = ''
        divProblem = WebDriverWait(driver, 5).until(
            EC.presence_of_element_located((By.ID, "problem-page-complete")))

        divProblem = driver.find_element_by_id('problem-page-complete')

        print('problem content got')
        all_children_by_xpath = divProblem.find_elements_by_xpath(".//*")

        for child in all_children_by_xpath:
            problemText = problemText + ' ' + child.text

        allHrefTags = driver.find_elements_by_tag_name('a')
        problemTags = ''
        for hrefTag in allHrefTags:
            if 'tag' in hrefTag.get_attribute('href'):
                problemTags = problemTags + ' ' + hrefTag.text

        medianSubmissionSize = 0.0
        submissionSizes = []
        totalSub = 0

        successDiv = driver.find_element_by_id('success-submissions')
        plusButton = successDiv.find_element_by_tag_name('button')
        plusButton.click()

        flag = True
        while flag:
            tableTag = WebDriverWait(driver, 5).until(
                EC.presence_of_element_located((By.CLASS_NAME, "dataTable")))
            tableTag = driver.find_element_by_class_name('dataTable')
            bodyTag = tableTag.find_element_by_tag_name('tbody')
            allRowTags = bodyTag.find_elements_by_tag_name('tr')
            for rowTag in allRowTags:
                if len(submissionSizes) >= 100:
                    flag = False
                    break

                allDataTags = rowTag.find_elements_by_tag_name('td')
                if len(allDataTags) > 3:
                    if "c" in allDataTags[3].text.lower():
                        totalSub = totalSub + 1
                        submissionSizes.append(
                            float(re.sub("[^0-9, .]", "",
                                         allDataTags[2].text)))
                        totalSub = totalSub + 1

            if flag == False:
                break

            successDiv = driver.find_element_by_id('success-submissions')
            aTags = successDiv.find_elements_by_tag_name('a')
            if aTags is None:
                break

            flag = False
            #print 'searching onclick for next'
            for aTag in aTags:
                try:
                    onclickAttr = aTag.get_attribute('onclick')
                    if onclickAttr is not None and 'next' in onclickAttr:
                        flag = True
                        #print 'clicking next button'
                        aTag.click()
                        time.sleep(2)
                        break
                except Exception as e:
                    print(e)
                    exc_type, exc_obj, exc_tb = sys.exc_info()
                    print 'Exception at line ' + str(exc_tb.tb_lineno)
                    logging.error(
                        'Time: {0} File: {1} Line: {2} Caused By: {3}'.format(
                            datetime.datetime.now(),
                            os.path.basename(__file__), exc_tb.tb_lineno, e))
                    # logging.error(str(datetime.datetime.now()) + ' :File Name: '+ str(os.path.basename(__file__)) +
                    # 		' :Line Number: '+ str(exc_tb.tb_lineno) + ' :Caused By: ' + str(e))
                    # print e
                    # exc_type, exc_obj, exc_tb = sys.exc_info()
                    # print exc_tb.tb_lineno
                    onclickAttr = None

        submissionSizes.sort()
        medianSubmissionSize = submissionSizes[(len(submissionSizes) - 1) / 2]
        print str(medianSubmissionSize) + " median submission size"

        prob = Problem(problemName, problemUrl, problemTags, problemText,
                       difficulty, medianSubmissionSize)
        count = count + 1
        driver.close()
        return prob
    except Exception as e:
        print('Exception raised')
        print(e)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        print 'Exception at line ' + str(exc_tb.tb_lineno)
        logging.error(
            'Time: {0} File: {1} Line: {2} Caused By: {3} Problem Name: {4}'.
            format(datetime.datetime.now(), os.path.basename(__file__),
                   exc_tb.tb_lineno, e, problemName))
        # logging.error(str(datetime.datetime.now()) + ' :File Name: '+ str(os.path.basename(__file__)) +
        # 		' :Line Number: '+ str(exc_tb.tb_lineno) + ' :Caused By: ' + str(e))
        try:
            with open('codechef/unscuccessful', 'a') as f:
                f.write(problemName + '\n')
        except:
            pass
        driver.close()
        return None