Esempio n. 1
0
def rename_file(file_id, name):
    """
    Renames the file in the local sqlite database to reflect the remote change.
    Infers fileExtension from the filename.

    Returns:
        id of renamed file
    """
    conn = connect()
    cursor = conn.cursor()

    tokens = name.split(".")
    fileExtension = tokens[len(tokens) - 1]

    cursor.execute("""
        UPDATE tbl_files
        SET title = ?,  fileExtension = ?
        WHERE id = ?;
        """, (
            name,
            fileExtension,
            file_id
        ))

    conn.commit()
    cursor.close()

    return file_id
def main():
    # check is user is conncted to internet
    if not connect():
        print('No Internet Connection!\nExiting....')
        exit() #exit if not
    else:
        while True:
        	# url='https://www.youtube.com/watch?v=Edpy1szoG80&list=PL153hDY-y1E00uQtCVCVC8xJ25TYX8yPU'
        	url=input('Enter the Playlist link to Download: ')
        	if urlChecker(url):
        		break
        	else:print('Invalid Url!')
        while True:
            temp=pathExistsElseCreate(input('\nEnter Destination Path("." for this dir):'))
            if temp is not None:
                SAVE_PATH=temp
                break
            else:print('Invalid Path!')

        
        print("\nGetting Details of Playlist")
        pl = Playlist(url)
        os.system('cls')
        print("\nDetails for Playlist","\n")
        print("Title:   ",pl.title()) #may not work for some playlist
        print("\nDownloading...")
        pl.download_all(SAVE_PATH)
        print("\nDownload completed!!")
Esempio n. 3
0
def match_to_umail():
    ldap_conn = helper.connect()
    for user in sorted(
        User.query_by().filter(
            not_(User.username.contains('@umail.ucsb.edu'))).all()):
        if user.admin_for or user.is_admin or '(' in user.name:
            continue
        match = helper.find_user(ldap_conn, user.name)
        if match:
            print match, user.username
Esempio n. 4
0
def update_umail_users():
    ldap_conn = helper.connect()
    for user in User.query_by().order_by(User.name).all():
        email = user.username
        if email.endswith('umail.ucsb.edu'):
            name = helper.fetch_name(ldap_conn, email)
            if name and name != user.name:
                user.name = name
            elif not name:
                print email, user.name
    transaction.commit()
Esempio n. 5
0
def select_all_files():
    """
    Generates a basic listing of files in tbl_files
    """
    conn = connect()
    cursor = conn.cursor()
    cursor.execute("SELECT title, id FROM tbl_files")
    files = cursor.fetchall()
    cursor.close()
    conn.commit()

    return files
Esempio n. 6
0
def main():
    if len(sys.argv) < 2:
        usage(sys.argv)
    config_uri = sys.argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)

    mailer = Mailer.from_settings(settings)
    ldap_conn = helper.connect()
    for line in sys.stdin:
        merge_to_umail(ldap_conn, mailer, *line.strip().split())
    transaction.commit()
Esempio n. 7
0
def main():
    if len(sys.argv) < 2:
        usage(sys.argv)
    config_uri = sys.argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)

    mailer = Mailer.from_settings(settings)
    ldap_conn = helper.connect()
    for line in sys.stdin:
        merge_to_umail(ldap_conn, mailer, *line.strip().split())
    transaction.commit()
Esempio n. 8
0
def get_file_id_by_name(file_name):
    """
    Returns the id associated with 'file_name' 
    """
    file_name = file_name.strip()

    conn = connect()
    cursor = conn.cursor()
    cursor.execute("SELECT id FROM tbl_files WHERE title = ?; ",
        (file_name,))

    file_id = cursor.fetchone()

    cursor.close()
    conn.commit()

    return file_id[0]
Esempio n. 9
0
def create_schema():
    conn = connect()
    cursor = conn.cursor()

    """
    tbl_files
        -> tbl_labels
        -> tbl_parentsCollection
        -> tbl_userPermission
    """
    cursor.execute("""
        CREATE TABLE tbl_files (
            createdDate TEXT,
            description TEXT,
            downloadUrl TEXT,
            etag TEXT,
            fileExtension TEXT,
            fileSize TEXT,
            id TEXT PRIMARY KEY,
            kind TEXT,
            lastViewedDate TEXT,
            md5Checksum TEXT,
            mimeType TEXT,
            modifiedByMeDate TEXT,
            modifiedDate TEXT,
            title TEXT
        );
        """)

    """
        tbl_labels
            <- tbl_files
    """
    cursor.execute("""
        CREATE TABLE tbl_labels (
            files_id TEXT,
            hidden INTEGER,
            starred INTEGER,
            trashed INTEGER,
            FOREIGN KEY (files_id) REFERENCES tbl_files(id)
            );
        """)

    """
        tbl_parentsCollection
            <- tbl_files
    """
    cursor.execute("""
        CREATE TABLE tbl_parentsCollection (
            files_id TEXT,
            parent_id TEXT,
            parentLink TEXT,
            FOREIGN KEY (files_id) REFERENCES tbl_files(id)
            );
        """)


    """
        tbl_userPermission
            <- tbl_files
    """
    cursor.execute("""
        CREATE TABLE tbl_userPermission (
            files_id TEXT,
            etag TEXT,
            kind TEXT,
            role TEXT,
            type TEXT,
            FOREIGN KEY (files_id) REFERENCES tbl_files(id)
            );
        """)

    conn.commit()
    cursor.close()
Esempio n. 10
0
def insert_file(metadata):
    """
    Inserts file metadata returned by gdrive.insert_file into the
    tbl_files table and tables related to it.

    Returns:
        id of the inserted data
    """

    conn = connect()
    cursor = conn.cursor()

    cursor.execute("""
        INSERT INTO tbl_files (
            createdDate,
            description,
            downloadUrl,
            etag,
            fileExtension,
            fileSize,
            id,
            kind,
            lastViewedDate,
            md5Checksum,
            mimeType,
            modifiedByMeDate,
            modifiedDate,
            title
        ) VALUES (
           ?,?,?,?,?,?,?,?,?,?,?,?,?,?
        );
        """, (
            metadata["createdDate"],
            metadata["description"],
            metadata["downloadUrl"],
            metadata["etag"],
            metadata["fileExtension"],
            metadata["fileSize"],
            metadata["id"],
            metadata["kind"],
            metadata["lastViewedDate"],
            metadata["md5Checksum"],
            metadata["mimeType"],
            metadata["modifiedByMeDate"],
            metadata["modifiedDate"],
            metadata["title"],
            )
        );

    cursor.execute("""
        INSERT INTO tbl_labels (
            files_id,
            hidden,
            starred,
            trashed
        ) VALUES (
            ?,?,?,?
        );
        """, (
            metadata["id"],
            metadata["labels"]["hidden"],
            metadata["labels"]["starred"],
            metadata["labels"]["trashed"],
        )
    );

    for parent in metadata["parentsCollection"]:
        cursor.execute("""
            INSERT INTO tbl_parentsCollection (
                files_id,
                parent_id,
                parentLink
            ) VALUES (
                ?,?,?
            );
            """, (
                metadata["id"],
                parent["id"],
                parent["parentLink"],
            )
        );

    cursor.execute("""
        INSERT INTO tbl_userPermission (
            files_id,
            etag,
            kind,
            role,
            type
        ) VALUES (
            ?,?,?,?,?
        )
        """, (
            metadata["id"],
            metadata["userPermission"]["etag"],
            metadata["userPermission"]["kind"],
            metadata["userPermission"]["role"],
            metadata["userPermission"]["type"],
        )
    );


    conn.commit()
    cursor.close()

    return metadata["id"]
Esempio n. 11
0
def update_file(metadata):
    """
    Updates file metadata returned by gdrive.update_file into the
    tbl_files table and tables related to it.

    Returns:
        id of the inserted data
    """

    conn = connect()
    cursor = conn.cursor()

    cursor.execute("""
        UPDATE tbl_files
        SET createdDate = ?,
            description = ?, 
            downloadUrl = ?, 
            etag = ?, 
            fileExtension = ?, 
            fileSize = ?, 
            kind = ?, 
            lastViewedDate = ?, 
            md5Checksum = ?, 
            mimeType = ?, 
            modifiedBymeDate = ?, 
            modifiedDate = ?, 
            title = ?
        WHERE id = ?;
        """, (
            metadata["createdDate"],
            metadata["description"],
            metadata["downloadUrl"],
            metadata["etag"],
            metadata["fileExtension"],
            metadata["fileSize"],
            metadata["kind"],
            metadata["lastViewedDate"],
            metadata["md5Checksum"],
            metadata["mimeType"],
            metadata["modifiedByMeDate"],
            metadata["modifiedDate"],
            metadata["title"],
            metadata["id"],
        )
    );

    cursor.execute("""
        UPDATE tbl_labels
        SET hidden = ?,
            starred = ?,
            trashed = ?
        WHERE files_id = ?;
        """, (
            metadata["labels"]["hidden"],
            metadata["labels"]["starred"],
            metadata["labels"]["trashed"],
            metadata["id"],
        )
    );

    for parent in metadata["parentsCollection"]:
        cursor.execute("""
            UPDATE tbl_parentsCollection
            SET parent_id = ?,
                parentLink = ?
            WHERE files_id = ?
            """, (
                parent["id"],
                parent["parentLink"],
                metadata["id"],
            )
        );

    cursor.execute("""
        UPDATE tbl_userPermission 
        SET etag = ?,
            kind = ?,
            role = ?,
            type = ?
        WHERE files_id = ?;
        """, (
            metadata["userPermission"]["etag"],
            metadata["userPermission"]["kind"],
            metadata["userPermission"]["role"],
            metadata["userPermission"]["type"],
            metadata["id"],
        )
    );

    conn.commit()
    cursor.close()

    return metadata["id"]
Esempio n. 12
0
            print('Refilled ' + str(refillCount) + ' times')
            h.wait(1)
            h.touchRefillIntellect()
            h.wait(1)
            h.touchRefillIntellectConfirm()
            h.wait(3)
        else:
            h.touchStartMissionB()
            h.waitFightStart()
            h.waitFightEnd()
            h.touchFightEnd()
        h.waitUntilSelectMission()


if __name__ == '__main__':
    from log import logger as l

    l.info("Starting...")
    import helper as h
    h.connect()

    l.info("Started")

    main()

    l.info("Stop")
    l.info("-------------------")
    l.info("-------------------")
    l.info("-------------------")
    input()
Esempio n. 13
0
def main():
    # check is user is conncted to internet
    if not connect():
        print('No Internet Connection!\nExiting....')
        exit() #exit if not
    else:
        # links=['https://youtu.be/qbW6FRbaSl0']
        while True:
            # check is user want to download multiple files
            multiple=input('\nDo you want to dowanlod multiple videos?(y/n): ').lower()
            if(multiple==('y')):
                while True:
                    # get txt file from user
                    via_txt=input('\nDo you want to send links via a txt file?(y/n)').lower()
                    if(via_txt=='y'):
                        while True:
                            path=input('\nEnter the path of txt file with video links on each line: ')
                            if(fileExists):
                                # urlChecker checks if the url is valid youtube link
                                links=[url for url in open('Example_links.txt', "r").read().splitlines() if urlChecker(url)]
                                break
                            else:
                                print('File Not Found!, Please Check the file path')
                    elif(via_txt=='n'):
                        # get one by one link from user
                        while True:
                            try:
                                n = int(input("Enter the number of youtube videos to download:   "))
                                print("\nEnter all the links one per line:")
                                links=[]
                                for i in range(0,n):
                                    while True:
                                        url=input()
                                        if(urlChecker(url)):
                                            links.append(url)
                                            break
                                        else:
                                            print('Invalid Input!')
                            except ValueError:
                                print('Invalid Input!')
                    else:
                        print('Invalid Input!')
            elif(multiple=='n'):
                # get single link from user
                while True:
                    print("\nEnter the link of Video:")
                    url=input()
                    links=[]
                    if(urlChecker(url)):
                        links.append(url)
                        break
                    else:print('Invalid Input!')
                break
            else:
                print('Invalid Input!')
        while True:
            temp=pathExistsElseCreate(input('\nEnter Destination Path("." for this dir):'))
            if temp is not None:
                SAVE_PATH=temp
                break
            else:print('Invalid Path!')
        def progress_function(stream, chunk, bytes_remaining):
            size = ys.filesize
            print(round((1-bytes_remaining/size)*100, 3), '% done...',end='\r')
        for i in range(0,len(links)):
            link = links[i]
            print("\nGetting Details of Video")
            # get video object
            yt = YouTube(link,on_progress_callback=progress_function)
            os.system('cls')
            print("\nDetails for Video","\n")
            print("Title:   ",yt.title)
            print("Length of video:  ",yt.length,"seconds")
            # get progressive streams i.e audio+video
            stream_ = yt.streams.filter(progressive=True)
            stream=str(stream_)
            stream = stream[1:]
            stream = stream[:-1]
            streamlist = stream.split(", ")
            # display available options
            print("\nAll available options for downloads:\n")
            for i in range(0,len(streamlist)):
                st = streamlist[i].split(" ")
                print(i+1,") ",st[1]," ",st[3],' size=',humanbytes(stream_[i].filesize),sep='')
            tag = int(input("\nEnter the itag of your preferred stream to download:   "))
            ys = yt.streams.get_by_itag(tag)
            print("\nDownloading...")
            ys.download(SAVE_PATH)
            print("\nDownload completed!!")