
import search
import match
import answer
import hdu

import time
from urllib import request


sleep_time = 5


def search_test():
    for i in range(1003, 1004):
        page = search.search_by_haosou('%s%d' % (hdu, i))
        ans_link = match.get_csdn_urls(page)
        print(i, ': ')
        for url in ans_link:
            print(url)


def code_test():
    page = search.get_page('http://blog.csdn.net/q3498233/article/details/5327770')
    codes = match.get_cpp_code(page)
    for code in codes:
        print(code)


def header_test():
    url = 'http://blog.csdn.net/q3498233/article/details/5327770'
    req = request.Request(url, headers=search.header)
    page = request.urlopen(req).read().decode()
    print(page)


def ans_test():
    for i in range(1011, 1012):
        print("No.", i)
        page = search.search_by_haosou('%s%d' % (hdu, i))
        ans_link = match.get_csdn_urls(page)
        for link in ans_link:
            print(link)
            p = search.get_page(link)
            codes = match.get_cpp_code(p)
            for code in codes:
                print('------')
                print(code)


def submit_test():
    name = input("Your username: ")
    password = input("Your password: ")
    src = '''
        #include<stdio.h>
        int main()
        {
            int a,b;
            while(scanf("%d%d",&a,&b)!=EOF)
            printf("%d\\n",a+b);
            return 0;
        }
        '''
    my = hdu.HDU(name, password)
    my.submit(1000, src)
    # for i in range(min_question_id, max_question_id):
    #     solve(my, i)
    #     time.sleep(sleep_time)
    # return None


def answer_test():
    # while True:
    ans = answer.get_answer('HDU1000')
    for a in ans:
        print(a)
    # if ans is None:
    #     break


def solve_test():
    name = input("Your username: ")
    password = input("Your password: ")
    my = hdu.HDU(name, password)
    if my.login() is False:
        return
    for i in range(1000, 1005):
        print('id :', i)
        hdu.solve(my, i)
        time.sleep(30)
    return None


if __name__ == '__main__':
    # header_test()
    # code_test()
    # ans_test()
    # submit_test()
    # answer_test()
    # solve_test()
    pass
