Files
The following functions interact with the Files folder and are available in the abstra.files
module.
get_persistent_dir
This fuctions returns the path of the Files folder.
Return type: pathlib.Path
Usage
from abstra.files import get_persistent_dir
persistent_dir = get_persistent_dir()
logs = persistent_dir / 'logs.txt'
logs.write_text('Hello World')
get_public_dir
This fuctions returns the path of the _public
directory inside the Files folder.
Files inside this folder are publicly available at /_public
.
Return type: pathlib.Path
Usage
import json
from abstra.files import get_public_dir
public = get_public_dir()
# will be available at /_public/manifest.json
manifest = public / 'manifest.json'
manifest.write_text(json.dumps(dict(version=2, status='Updated')))
# will be available at /_public/dumps/public.txt
dump = public / 'dumps' / 'public.txt'
dump.write_text("PUBLIC DUMP")
create_public_link
This fuctions creates a copy of the provided file inside the _public
directory in a nested folder and returns the url link to that file.
Argument type: str or pathlib.Path
Return type: str
Usage
import abstra.forms as forms
import abstra.files as files
import abstra.messages as messages
# Get inputs
user = forms.get_user()
date = forms.read_date("Report date")
isodate = date.isoformat()
# Generate report
report_path = files.get_persistent_dir() / f"{isodate}-report.txt"
report_path.write_text(f"{user.email}: {isodate}")
report_link = files.create_public_link(report_path)
# Send Report
title = f"Report from {date}"
message = f"""Hi {user.email}. This is the report link: {report_link}."""
am.send_email(to=user.email, message=message, title=title)
# Display report
forms.Page().display("Report also send via email").display_link(report_link, link_text='Report').run(end_program=True)