Skip to content

Commit

Permalink
Added mandatory API Token command line arguments for latest version o…
Browse files Browse the repository at this point in the history
  • Loading branch information
doublehelix committed Jan 2, 2023
1 parent 148174f commit c7526fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions README.md
Expand Up @@ -30,7 +30,15 @@ python ./inky-pihole/main.py
```

## Options
All command line optins are optional and the default values when left out are detailed below.

* `-t`, `--token`
Pihole API Token (_Required_)
e.g.: `--token "4e0a518a7e2cc8e8b0520b91c8f0156709167ce9265298add8fa45d1d933f99e"`
Navigate to the settings admin page to retrieve your API token:
http://pihole/admin/settings.php?tab=api
and click the `Show API Token` button to view your API key.

All other command line options are optional, and the default values when left out are detailed below.
* `-a` , `--apihosts`
A comma separated list of your Pi-Hole host names.
e.g.: `--apihosts "192.168.1.10, 192.168.1.11"`
Expand Down Expand Up @@ -80,11 +88,11 @@ crontab -e

Add the following line:
```
*/30 * * * * python /home/pi/inky-pihole/main.py
*/30 * * * * python /home/pi/inky-pihole/main.py --token "4e0a518a7e2cc8e8b0520b91c8f0156709167ce9265298add8fa45d1d933f99e"
```
Or, add some command line options:
```
*/30 * * * * python /home/pi/inky-pihole/main.py --rotate --lcars --simple --apihosts "10.0.0.10,10.0.0.11" --tz "Australia/Melbourne"
*/30 * * * * python /home/pi/inky-pihole/main.py --rotate --lcars --simple --apihosts "10.0.0.10,10.0.0.11" --tz "Australia/Melbourne" --token "4e0a518a7e2cc8e8b0520b91c8f0156709167ce9265298add8fa45d1d933f99e"
```

30 minutes should be a non-obtrusive refresh time for most people. The display can flash quite a lot during updates, so refreshing more regularly is only recommended if you need closer monitoring.
Expand Down
8 changes: 7 additions & 1 deletion main.py
Expand Up @@ -19,6 +19,7 @@
parser.add_argument('-s', '--simple', action='store_true', help='Simple Statistics Display')
parser.add_argument('--lcars', action='store_true', help='Use LCARS style display')
parser.add_argument('--tz', help='Timezone (default: UTC)')
parser.add_argument('-t', '--token', required=True, help='API authentication token. See: http://pihole/admin/settings.php?tab=api [Show API Token] button')
# Helpers
parser.add_argument('--timezones', action='store_true', help='Show all available TimeZone values')

Expand All @@ -30,6 +31,10 @@
print(tz)
exit()

if (args.token is None)
print('API token is mandatory!')
exit();

# Initialize Inky pHAT Display
display = auto()

Expand All @@ -53,7 +58,8 @@
# Get Pi-Hole API data
def get_data(host, combine=False):
try:
f = urlopen('http://' + host + '/admin/api.php') # open API connection
url = 'http://' + host + '/admin/api.php?summaryRaw&auth=' + args.token
f = urlopen(url) # open API connection
json_data_string = f.read() # Read data
f.close() # close connection

Expand Down

0 comments on commit c7526fb

Please sign in to comment.