Credentials

class feupy.Credentials(username=None, password: str = None)

This class represents your login credentials. It also features a non-persistent cache that stores htmls of urls previously accessed.

Parameters:
  • username (int or str, optional) – Your username. You will be prompted for your username if you don’t pass a username as an argument
  • password (str, optional) – Your password. You will be prompted for your password if you don’t pass a password as an argument
username

Your username (e.g. 201806185)

Type:int or str
session

A requests.Session object that holds the login cookies

Type:requests.Session
cache

A dictionary that maps a url string to an html string

Type:dict

Example:

from feupy import Credentials

username = 201806185
password = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

creds = Credentials(username, password)

# You may instead enter your username and password at runtime
creds = Credentials()
# Username?
# :> up201806185
# Password for 201806185?
# :>
download(url: str, folder_path: str) → str

Downloads the file from the given url and saves it to the given folder path. If the path doesn’t exist, it will be created automatically.

Parameters:
  • url (str) – The url of the file to be downloaded
  • folder_path (str) – The path of the folder you want to download the file to
Returns:

The path of the file as an str

get_html(url: str, params: dict = {}) → str

Functionally equivalent to requests.get(url, params).text, with scripts and styles removed. If the result is already in cache, the method will just return the value from the cache instead of making a web request.

Parameters:
  • url (str) – The url of the html to be fetched
  • params (dict, optional) – the query portion of the url, should you want to include a query
Returns:

A string which is the html from the requested page url

get_html_async(urls, n_workers: int = 10)

Credentials.get_html(), but async, give or take.

Takes a list (or any iterable) of urls and returns a corresponding generator of htmls. The htmls have their scripts and styles removed and are stored in cache.

Parameters:
  • urls (iterable(str)) – The urls to be accessed
  • n_workers (int, optional) – The number of workers.
Returns:

An str generator