Exemplo n.º 1
0
def open_db():
    create_path(DB_FILE)
    con = sqlite3.connect(DB_FILE)
    # con.set_trace_callback(print)

    with con:
        cur = con.cursor()
        cur.execute(CREATE_TABLE)

    return con
Exemplo n.º 2
0
def open_db():
    create_path(DB_FILE)
    con = sqlite3.connect(DB_FILE)
    # con.set_trace_callback(print)

    with con:
        cur = con.cursor()
        cur.execute(CREATE_TABLE)

    return con
Exemplo n.º 3
0
def download_file(url):
    def reporthook(blocknum, blocksize, totalsize):
        readsofar = blocknum * blocksize
        if totalsize > 0:
            percent = (readsofar * 1e2 / totalsize) / 2.
            pyotherside.send("on-progress", percent)
        else:
            sys.stderr.write("read %d\n" % (readsofar, ))

    create_path(FILENAME)

    return urlretrieve(url, FILENAME, reporthook)
Exemplo n.º 4
0
def download_file(url):

    def reporthook(blocknum, blocksize, totalsize):
        readsofar = blocknum * blocksize
        if totalsize > 0:
            percent = (readsofar * 1e2 / totalsize) / 2.
            pyotherside.send("on-progress", percent)
        else:
            sys.stderr.write("read %d\n" % (readsofar,))

    create_path(FILENAME)

    return urlretrieve(url, FILENAME, reporthook)
Exemplo n.º 5
0
    def login(self, url, username, password):
        self.client = MatrixClient(url)

        # New user
        # token = client.register_with_password(username="******", password="******")

        # Existing user
        create_path(FILENAME)
        token = self.client.login_with_password(username=username,
                                                password=password)
        print("Logged in with token: {token}".format(token=token))

        data = {'token': token, 'user_id': self.client.user_id, 'url': url}

        with open(FILENAME, 'w') as f:
            json.dump(data, f, ensure_ascii=False)

        return data