Beispiel #1
0
    def show_profile(self, user_id):

        connection = sqlite3.connect("../main/data_base.db")
        crsr = connection.cursor()
        crsr.execute("SELECT * FROM user")
        user = crsr.fetchall()
        connection.close()

        connection_friends = sqlite3.connect("connections.db")
        crsr_friends = connection_friends.cursor()
        sql_connections_table = """CREATE TABLE if not exists {}(connection_user_id char, sent_request_user_id char,received_request_user_id char)""".format(
            user_id)
        crsr_friends.execute(sql_connections_table)
        crsr_friends.execute("SELECT * FROM {}".format(user_id))
        user_detail = crsr_friends.fetchall()

        sql_num_connections = """ SELECT COUNT(connection_user_id ) FROM {};""".format(
            user_id)
        crsr_friends.execute(sql_num_connections)
        num_c = crsr_friends.fetchall()

        for i in user:

            if i[0] == user_id:

                fname = i[1]
                lname = i[2]
                gender = i[3]
                email = i[4]
                phone = i[5]

                print("user_id : ", user_id)
                print("Name : ", fname, lname)
                print("Gender : ", gender)
                print("Email Id: ", email)
                print("Phone Number: ", phone)
                print("Total Connections : ", num_c[0][0])

        print("")
        print(
            "Enter 1:> Post Stories  | Enter 2:> See Connections | Enter 3:> logout | Enter 4:> Find_connection"
        )
        user_will = int(input())
        if user_will == 1:
            pass
        elif user_will == 2:
            pass
        elif user_will == 3:
            login.login().logout()
        elif user_will == 4:
            pass
Beispiel #2
0
def get_all_classes():
    s = login(user_id=config.ly_user_id, user_password=config.ly_user_password)
    res = s.get(
        "http://jwc.swjtu.edu.cn/vatuu/AjaxXML?selectType=CollegeInfo&selectValue=allCollege"
    )
    page = ElementTree.fromstring(res.text)
    college_names = [i.text for i in page.iter("college_name")]
    college_codes = [i.text for i in page.iter("college_code")]
    url = "http://jwc.swjtu.edu.cn/vatuu/PublicInfoQueryAction"
    data = {"setAction": "queryClass", "collegeCode": "16", "btn1": "执行查询"}
    for college_name, college_code in list(zip(college_names,
                                               college_codes))[2:3]:
        print(college_name)
        data["collegeCode"] = college_code
        res = s.post(url, data=data)
        page = etree.HTML(res.text)
        trs = page.xpath("//table[@class='table_gray']/tr")
        trs = trs[2:]
        if len(trs) <= 1:
            continue
        class_codes = [i.xpath("td[2]/text()")[0].strip() for i in trs]
        class_names = [i.xpath("td[3]/text()")[0].strip() for i in trs]
        _college_names = [i.xpath("td[4]/text()")[0].strip() for i in trs]
        major_names = [i.xpath("td[5]/text()")[0].strip() for i in trs]
        grade = [i.xpath("td[6]/text()")[0].strip() for i in trs]
        class_num = [i.xpath("td[7]/text()")[0].strip() for i in trs]
        c.executemany(
            "INSERT INTO class values (%s,%s,%s,%s,%s,%s) ",
            zip(class_codes, class_names, _college_names, major_names, grade,
                class_num))
        conn.commit()
Beispiel #3
0
def get_all_names():
    s = login(user_id=config.ly_user_id, user_password=config.ly_user_password)

    def name_single(url, course, term):
        single_res = s.get(url)
        single_page = etree.HTML(single_res.text)
        lists = single_page.xpath("//table[@id='table2']/tr")
        if not lists:
            return
        lists.pop(0)
        rows = []
        for i in lists:
            student_id = i.xpath("td[2]/text()")[0].strip()
            student_name = i.xpath("td[3]/text()")[0].strip()
            student_gender = i.xpath("td[4]/text()")[0].strip()
            student_class = i.xpath("td[5]/text()")[0].strip()
            rows.append((course, student_id, student_name, student_class,
                         student_gender, term))
        c.executemany(
            "INSERT INTO student_course values (%s,%s,%s,%s,%s,%s) on conflict do nothing ",
            rows)
        print(f"课程{course} {len(rows)} and {c.statusmessage}")

    c.execute("SELECT name_list_url,number,term FROM course order by number ")
    results = c.fetchall()
    for num, line in enumerate(results):
        name_single(*line)
        print(num + 1, line[1])
        if num + 1 % 100 == 0:
            conn.commit()
    conn.commit()
    conn.close()
Beispiel #4
0
def main():
    s = login(config.user_id, config.user_password)
    cookies = s.cookies.get_dict()
    driver = webdriver.Chrome()
    driver.get("http://jwc.swjtu.edu.cn/vatuu/UserFramework")
    for i in cookies:
        driver.add_cookie({"name": i, "value": cookies[i]})
    driver.get("http://jwc.swjtu.edu.cn/vatuu/UserFramework")
Beispiel #5
0
 def menu(self, task):
     # Accept raw_input choice
     self.login = login()
     if self.login.getStatus() == "Authorized":
         print "going to character Select Menu"
         return task.done
     
     return task.again
Beispiel #6
0
    def __init__(self):
        
	    # Network Setup
        self.cManager = ConnectionManager()
        self.startConnection()
        print "Ran Main"
        #taskMgr.add(self.menu, "Menu")
        self.login = login()
        print "Finished"
Beispiel #7
0
#coding:utf-8
from main import login
from main import classs
import sys
import time
import json
from main.login import write_zd
login.init_zd()
zhangdan=[]
print '欢迎来到网上银行'
login.init_database()
flags=False
while flags is False:
    username=raw_input('Username:'******'Password:'******'请重新输入'
account=classs.account_info(username)
print '''
姓名      %s
余额     %s
''' %(username,account.balance())
func=['get_money','save_money','check_zhangdan','exit']
for i in enumerate(func,1):
    print str(i).strip('()')
while True:
    foo=input('请选择:')
    if foo == 1 or foo == 'get_money':
        money=input('请输入金额')
        account.get_money(money)
Beispiel #8
0
def main(grade="2016"):
    s = login(user_id=user_id, user_password=user_password)
    res = s.get(
        "http://jwc.swjtu.edu.cn/vatuu/AjaxXML?selectType=CollegeInfo&selectValue=teachingCollege"
    )
    page = ET.fromstring(res.text)
    college_names = [i.text for i in page.iter("college_name")]
    college_codes = [i.text for i in page.iter("college_code")]
    params1 = {
        "selectType": "SpecialityInfo",
        "selectValue": "collegeSpeciality",
        "key2": "1"
    }
    params2 = {
        "setAction": "specialityPlan",
        "SelectType": "query",
        "B1": "查询"
    }
    wb = Workbook()
    for college_name, college_code in zip(college_names, college_codes):
        params1["key"] = college_code
        res = s.get("http://jwc.swjtu.edu.cn/vatuu/AjaxXML", params=params1)
        if "speciality_code" not in res.text:
            continue
        page = ET.fromstring(res.text)
        speciality_codes = [i.text for i in page.iter("speciality_code")]
        speciality_names = [i.text for i in page.iter("speciality_name")]
        for speciality_name, speciality_code in zip(speciality_names,
                                                    speciality_codes):
            if speciality_name in ('建筑学', '城乡规划', '风景园林'):
                params2["grade"] = str(int(grade) - 1)
            else:
                params2["grade"] = grade
            results = []
            params2["college_name"] = college_name
            params2["speciality_name"] = speciality_name
            params2["college_code"] = college_code
            params2["speciality_code"] = speciality_code
            res = s.get("http://jwc.swjtu.edu.cn/vatuu/MasterAction",
                        params=params2)
            if not res.ok:
                continue
            page = etree.HTML(res.text)
            lines = page.xpath("//table[@id='table6']/tr")
            if len(lines) == 1:
                continue
            lines.pop()
            for line in lines:
                temp = [i for i in line.getchildren()]
                result = [i.text.strip() for i in temp[:-1]]
                if temp[-1].getchildren():
                    result.append("非免研课")
                else:
                    result.append(temp[-1].text.strip())
                results.append(result)
            sheet = wb.create_sheet(
                f"{college_name}-{speciality_name}".replace("[", "").replace(
                    "]", ""))
            for i, result in enumerate(results):
                for j, k in enumerate(result):
                    sheet.cell(row=i + 1, column=j + 1).value = k

    wb.save(f"2020年保研课{grade}级教务查询.xlsx")
Beispiel #9
0
def get_all_courses():
    term = "2019-2020学年上学期"
    html = "http://jwc.swjtu.edu.cn/vatuu/CourseAction"
    params = {
        "setAction": "queryCourseList",
        "viewType": "",
        "orderType": "teachId",
        "orderValue": "asc",
        "selectAction": "QueryAll",
        "key1": "",
        "key2": "",
        "key3": "",
        "key4": "",
        "selectTermId": "92",
        "selectTermName": "2019-2020第1学期",
        "courseType": "all",
        "selectTableType": "ThisTerm",
        "jumpPage": "1"
    }
    s = login(user_id=config.ly_user_id, user_password=config.ly_user_password)

    def course_page(page_number):

        params["jumpPage"] = page_number
        single_res = s.get(html, params=params)
        single_page = etree.HTML(single_res.text)
        lists = single_page.xpath("//table[@class='c-tb']/tbody/tr")
        rows = []
        for i in lists:
            number = i.xpath("td[2]/a/font/text()")[0].strip()
            code = i.xpath("td[3]/a/text()")[0].strip()
            name = i.xpath("td[4]/a/text()")[0].strip()
            credit = i.xpath("td[6]/a/text()")[0].strip()
            course_type = i.xpath("td[7]/a/text()")[0].strip()
            teacher_name_list = i.xpath("td[9]/a/text()")
            teacher_name_list = [j.strip() for j in teacher_name_list]
            teacher_name = "+".join(teacher_name_list)
            time_location_list = i.xpath("td[11]/text()")
            time_location_list = [j.strip() for j in time_location_list]
            time_location_list = [j for j in time_location_list if j]
            assert len(
                time_location_list
            ) % 2 == 0, f"the length of {time_location_list} is out of control"
            time_location = "+".join(time_location_list)
            classes_list = i.xpath("td[12]/a/text()")
            classes_list = [j.strip() for j in classes_list]
            classes = "+".join(classes_list)
            status = i.xpath("td[13]/text()")[0].strip()
            number_of_people, class_capacity = status.split("/")
            campus = i.xpath("td[14]/a/text()")[0].strip()
            if len(i.xpath("td[15]/p")) == 4:
                name_list_url = i.xpath("td[15]/p[2]/a/@href")[0]
            else:
                name_list_url = i.xpath("td[15]/p[1]/a/@href")[0]
            name_list_url = urljoin(html, name_list_url)
            rows.append((number, code, name, credit, course_type, teacher_name,
                         time_location, classes, number_of_people,
                         class_capacity, campus, name_list_url, term))
        c.executemany(
            "INSERT INTO course values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on conflict do nothing",
            rows)

        print(f"{page_number} 页 {len(rows)} and {c.statusmessage}")

    res = s.get(html, params=params)
    page = etree.HTML(res.text)
    page_total = len(page.xpath("//select[@class='btn btn-page']/option"))

    for page_num in range(page_total):
        course_page(page_num + 1)
    conn.commit()
    conn.close()