Example #1
0
def main():
    #step 1: get all the id of original tutorials
    tutorials_id = get_id.get_id()
    
    for t_id in tutorials_id:
        #step 2: get all the name of original tutorials
        t_name = get_name.get_name(t_id)
        
        #step 3: insert id and name into org_tutorial table
        #database
        
        #step 4: From the result of step 3, call get_name to first level totorial info
        get_spinoff.get_first_spinoff(t_id)
        
        #step 5: Insert into first_level_spinoff table
        #database
        
        #step 6: From the result of step 5, call get_user_id to get user id
        user_id = get_user_id.get_user_id(t_id)

        #step 7: insert user info into user table
        #database

        #step 8: Call get_user_project to get all related project
        get_user_project.get_user_project(user_id)
def d_insert_first_level_spinoff():
    # step 1: get all the id of original tutorials
    tutorials_id = get_id.get_id()

    # set up database
    con = mdb.connect(host="mysql1", user="******", passwd="TBtsTL4Xn6e4Whwh", db="khandb", charset="utf8")
    cur = con.cursor()
    # get all original tutorials id
    # cur.execute("TRUNCATE TABLE first_level_spinoff")
    cur.execute('SELECT org_tut_id FROM org_tutorials WHERE is_checked = "0"')
    results_org_tut_id = cur.fetchall()

    cur.execute("SELECT project_id FROM first_level_spinoff")
    results_project_id = cur.fetchall()

    for org_tut_id in results_org_tut_id:
        # org_tut_id = str(org_tut_id)
        org_tut_id = str(org_tut_id)[1:][:-3]
        # org_tut_id = org_tut_id
        # print org_tut_id
        results = get_spinoff.get_first_spinoff(org_tut_id)
        for result in results:
            count = 0
            # database fields
            # 1:call get_user_id to get user id
            # 2:rfind('\') from url then cut it
            # 3:result[0]: project_title
            # 4:result[2]: url
            # 5:result[3]: parent's id

            project_title = result[0]
            url = result[2]
            parent_id = org_tut_id
            user_id = get_user_id.get_user_id(url)
            project_id = url[url.rfind("/") + 1 :]
            if not user_id:
                user_id = "['none']"
            user_id = str(user_id)[2:][:-2]
            for fls_project_id in results_project_id:
                fls_project_id = str(fls_project_id)[1:][:-3]
                if fls_project_id == project_id:
                    count = 1
            # print user_id
            # print project_id
            # print project_title
            # print url
            # print parent_id
            if count != 1:
                cur.execute(
                    "INSERT INTO first_level_spinoff (user_id, project_id, project_title, url, parent_id) VALUES (%s, %s, %s, %s, %s)",
                    (user_id, project_id, project_title, url, parent_id),
                )

        cur.execute(
            'UPDATE org_tutorials SET is_checked = "1", checked_date = current_date WHERE org_tut_id = %s', (org_tut_id)
        )

    con.close()
def d_insert_first_level_spinoff():
    # step 1: get all the id of original tutorials
    tutorials_id = get_id.get_id()

    # set up database
    con = mdb.connect(host="mysql1", user="******", passwd="TBtsTL4Xn6e4Whwh", db="khandb", charset="utf8")
    cur = con.cursor()
    # get all original tutorials id
    # cur.execute("TRUNCATE TABLE first_level_spinoff")
    cur.execute('SELECT org_tut_id FROM org_tutorials WHERE is_checked = "0"')
    results_org_tut_id = cur.fetchall()

    cur.execute("SELECT project_id FROM first_level_spinoff")
    results_project_id = cur.fetchall()

    for org_tut_id in results_org_tut_id:
        org_tut_id = str(org_tut_id[0])

        results = get_spinoff.get_first_spinoff(org_tut_id)
        for result in results:
            count = 0

            project_title = result[0]
            url = result[2]
            parent_project_id = org_tut_id
            user_id = str(get_user_id.get_user_id(url)[0])
            # user_id = str(user_id[0])
            project_id = url[url.rfind("/") + 1 :]
            # if not user_id:
            # user_id = ['NULL']

            for r_project_id in results_project_id:
                r_project_id = str(r_project_id[0])
                if r_project_id == project_id:
                    count = 1

            if count != 1:
                cur.execute(
                    "INSERT INTO first_level_spinoff (user_id, project_id, project_title, url, parent_project_id) VALUES (%s, %s, %s, %s, %s)",
                    (user_id, project_id, project_title, url, parent_project_id),
                )

        cur.execute(
            'UPDATE org_tutorials SET is_checked = "1", checked_date = current_date WHERE org_tut_id = %s', (org_tut_id)
        )

    con.close()
def d_insert_first_level_spinoff():
    #step 1: get all the id of original tutorials
    tutorials_id = get_id.get_id()

    #set up database
    con = mdb.connect(host="mysql1", user="******", passwd="TBtsTL4Xn6e4Whwh", db="khandb", charset='utf8');
    cur = con.cursor()
    #get all original tutorials id
    cur.execute("TRUNCATE TABLE first_level_spinoff") 
    cur.execute("SELECT org_tut_id FROM org_tutorials")
    results = cur.fetchall()
    
    for org_tut_id in results:
        #org_tut_id = str(org_tut_id)
        org_tut_id = str(org_tut_id)[1:][:-3]
        #org_tut_id = org_tut_id
        #print org_tut_id
        results = get_spinoff.get_first_spinoff(org_tut_id)
        for result in results:
            #database fields
            #1:call get_user_id to get user id
            #2:rfind('\') from url then cut it
            #3:result[0]: project_title
            #4:result[2]: url
            #5:result[3]: parent's id

            project_title = result[0]
            url = result[2]
            parent_id = org_tut_id
            user_id = get_user_id.get_user_id(url)
            project_id = url[url.rfind('/')+1:]
            if not user_id:
                user_id = "['none']"
            user_id = str(user_id)[2:][:-2]
            #print user_id
            #print project_id
            #print project_title
            #print url
            #print parent_id
            cur.execute("INSERT INTO first_level_spinoff (user_id, project_id, project_title, url, parent_id) VALUES (%s, %s, %s, %s, %s)",
                        (user_id, project_id, project_title, url, parent_id))
    
    con.close()