# Setup

Installation, settings, and secrets

# Installation

Supported installation methods. 

If installing through the AUR or the binary, the first time run will take longer since these rely on PyApp to run. 

**Note**: after installation, it is encouraged to run `config-init` for the first-time setup. 

### Arch

`yay -S wallypub`

### Binary 

1. Download

`curl -LO https://codeberg.org/fausty/wallypub/releases/download/1.0.1/wallypub_1.0.1`

2. Move to usr bin 

`sudo mv wallypub_1.0.1 /usr/local/bin/wallypub`

3. Make executable

`sudo chmod +x /usr/local/bin/wallypub`

4. Run 

`wallypub --help`

### Python

https://pypi.org/project/wallypub/

`pip install wallypub`

# Settings

## Initial Configuration

Running `config-init` will take you through your first-time setup. During the  initial configuration, Wallypub only asks for the bare minimum information to create a digest. This includes the
name of the digest, who you would like to attribute its authorship to, and your Wallabag API credentials. 

If you do not have the default system font installed, Wallypub will prompt you for your sudo password to copy the default
font, `FreeMono.ttf` into the system fonts location `/usr/share/fonts`. 

There are more settings, explained below, and these can be edited after the first time setup by running `config-edit`.

### Digest Settings

`digest_title`: This is the title of the epub that will appear in the file name and on the cover, if you use 
an image generated by Wallypub. The default title is `Wallypub Presents`.  

`digest_author`: This will show up on the title page and in the metadata. You can leave this blank without issue; it defaults to "".

`back_matter`: This generates the final page in your EPUB. The back matter page just credits Wallypub and provides a link to donate. This can be disabled by setting this value to False. 

# File locations for creating a digest
`digest_directory_filepath`: Location of files for creating the digest, defaults to `~/.local/share/Wallypub/static"`    
`digest_cover_image`: The image file that Wallypub looks for defaults to `~/.local/share/Wallypub/static/cover.jpg"`  
`digest_output_path`: Where Wallypub outputs a generated epub, defaults to `~/Documents`

### Wallabag settings
`wallabag_url`: The URL where your Wallabag is hosted, defaults to `app.wallabag.it`  
`wallabag_userame`: The username for your Wallabag instance.   
`wallabag_password`: Your Wallabag instance password.  Stored in your machine's keyring.  
`wallabag_client_id`: client_id for accessing API. Follow the [client setup](https://app.wallabag.it/developer) if you do not know what this is.   
`wallabag_client_secret`: client_secret for accessing API. Follow the [client setup](https://app.wallabag.it/developer) if you do not know what this is.  Stored in your machine's keyring.

#### Retrieval Settings

The Wallabag allows one to customize which files are retrieved by passing certain URL parameters.

##### Article Parameters 
The default configuration for article parameters assumes that the bulk of the material desired for reading is the more 
recently added items to Wallabag. 

Example:

```[ArticleParameters]
archive = "0" 
starred = "0"
sort = "created"
order = "desc"
page = "1"
perPage = "10"
tags = ""
since = ""
public = ""
detail = "full"
domain_name = ""
```

The canonical place to determine the behavior of the URL parameters is in the [Wallabag docs](https://app.wallabag.it/api/doc/)



##### Additional Article Parameters 
Wallypub automatically filters out 0 length articles. This means that the number of recent articles you intended to make 
a digest from is lower. To ensure that the proper number of articles are inlcuded in the epub, a check is made and then articles
are fetched using different parameters. The default is configured to pull this article from the back of the queue. This choice
can be amended in the settings, however; the default was decided as a method to add variety. It is likely that articles saved from
week to week might relate to a particular big news event or a rabbit hole. This default configuration attempts to provide some variety
to the digest. 

### Other Settings

`max_read_time` articles with a longer read time than this will be skipped. Defaults to 120 (minutes). 120 minutes is about
15000 words, depending on one's reading spead. 

`minimum_reading_time` Only article with a read time greater than this number are included in the digest. Defaults to 0. 
0 time articles are always filtered out because it normally indicates that Wallabag was not able to properly pull the text.

`log_level`

log_level is an `int` value that gets translated to something human-readable in the logging libraries. 
The values are as follows: .

```
CRITICAL = 50
ERROR = 40
WARNING = 30
INFO = 20
DEBUG = 10
NOTSET = 0
```

Note that FATAL is not present. That is because exposing that value through configuration was more difficult and unnecessary. If you have never set log levels before, DEBUG will be noisier than INFO, INFO will be noisier than WARNING, and so on.  If you want a quiet terminal, increase the log level; if you are troubleshooting, decrease it. 

## Fonts 

The fonts available are the ones on your system. If you want the cover image to be different, change the font in the settings. 
You can open-source fonts at [The League of Moveable Type](https://www.theleagueofmoveabletype.com/) and [Open Source Foundry](https://osp.kitchen/about). 

To see what fonts are available on your system, you can run the [show-sysetm-fonts](https://wiki.freecomputer.club/link/46#bkmrk-system-fonts-show) command from wallypub.

If you prefer to use system tools for font exploration, you can also use the [fc-list](https://manpage.me/?fc-list) command from your terminal. 

Fonts are stored under system fonts at `/usr/share/fonts` this location was chosen because it appears to be consistent across many distributions of Linux. 
 

## Example Settings File 

On your system your settings file can be found at `~/.config/Wallypub/settings.toml` or
you can use the Wallypub `config-show` to see the current configuration.

```toml
[AdditionalArticleParameters]
archive = "0"
starred = "0"
sort = "asc"
order = ""
page = ""
perPage = ""
tags = ""
since = ""
public = ""
detail = ""
domain_name = ""

[ArticleParameters]
archive = "0"
starred = "0"
sort = "created"
order = "desc"
page = "1"
perPage = "10"
tags = ""
since = ""
public = ""
detail = "full"
domain_name = ""

[Base]
application_directory = "/home/$USER/.local/share/Wallypub"
log_level = 20
max_read_time = 120
minimum_read_time = 0

[Digest]
title = "Wallypub Presents"
filepath = "/home/$USER/.local/share/Wallypub/static"
author = "$AUTHOR"
output_path = "/home/$USER/Documents/Wallypub"
cover_file = "cover.jpg"
title_font = "FreeMono.ttf"
date_font = "FreeMono.ttf"
back_matter = True

[Wallabag]
client_id = "$CLIENT_ID"
username = "$USER"
url = "app.wallabag.it"

```

# Secrets

In order to access your Wallabag instance, Wallypub relies on two secrets. 
Your `wallabag_password` and your `wallabag_client_secret`. 

## Viewing & Editing
You are prompted to add your secrets when running the initial `config-init`, but you
can view the currently configured secrets by running `config-secrets-show`. Updating the secrets
happens through `config-secrets-edit`,

## Storage 

Wallypub stores your keys in your devices' keyring. You will note there
are separate commands for showing the config and showing the secrets. This is 
partially to prevent printing your config for troubleshooting and accidentally exposing
your sensitive values, but also because the secrets are not store in a plaintext settings file.

# Troubleshooting

Wallypub generates a `debug.log` file which can be found in your ~/.local/share/Wallypub/ directory

  If you want to see debug output in your terminal, set the `log_level` to `10` in your base settings.