Pi Hole stats tweeter

Pi Hole stats tweeter

I wanted to send a a daily tweet with the results of what my Pi-Hole blocked.

How to use

Install following python dependencies with

sudo pip install tweepy datetime json urllib

Download python file and replace it with your own account data and link to your own path/to/admin/api.php. In my case it would be /var/www/html/admin.api.php or darthkeizer.ddns.net/admin.api.php

path/to/admin/api.php

/var/www/html/admin.api.php or

https://darthkeizer.ddns.net/admin.api.php

Script

#Send tweet when script is called

import tweepy
import datetime
import json
import urllib
from urllib.request import urlopen

# Retrieve data and load it into a dictionary
data = urlopen(‘path/to/admin/api.php’).read() #bytes
body = data.decode(‘utf-8’)
data = json.loads(body)

# Create tweet, adjust %.2f for amount of decimals you want or %i for a whole number
template_tweet = “\nAds Blocked: %s\nAds Percentage Today: %.2f\nDNS Queries Today: %s\nDomains Being Blocked: %s”
data = template_tweet % (data[‘ads_blocked_today’],
float (data[‘ads_percentage_today’]),
data[‘dns_queries_today’],
data[‘domains_being_blocked’]
)

def get_api(cfg):
auth = tweepy.OAuthHandler(cfg[‘consumer_key’], cfg[‘consumer_secret’])
auth.set_access_token(cfg[‘access_token’], cfg[‘access_token_secret’])
return tweepy.API(auth)

def main():
# Fill in the values noted in previous step here https://dev.twitter.com/oauth/overview/application-owner-access-tokens
cfg = {
“consumer_key” : “VALUE”,
“consumer_secret” : “VALUE”,
“access_token” : “VALUE”,
“access_token_secret” : “VALUE”
}

api = get_api(cfg)
tweet = datetime.datetime.today().strftime(“%Y-%m-%d”) + ” Daily Pi-Hole report\n ” + data
status = api.update_status(status=tweet)
# Yes, tweet is called ‘status’ rather confusing

if __name__ == “__main__”:
main()

Cronjob

This will tweet your stats at 23:59 everyday

59 23 * * * sudo python3 /path/to/twittertweeter.py >/dev/null 2>&1

Twitter acces keys and tokens

On their own website it is quite clearly explained: https://dev.twitter.com/oauth/overview/application-owner-access-tokens

Replace VALUE by the corrects keys, tokens and secrets.

Autostart your Raspberry Pi Fan with Python

Chilledpi

Basic python script activating a fan with standard GPIO when rebooting your raspberry pi. Adjust the script to you own liking.

How To

Sudo crontab -e and add the following code below:

@reboot sudo python /path/to/ChilledPi.py

Information

This python script uses RPi.GPIO, this script uses default temperatures and default GPIO pins. You can adjust all to you own liking.

Script

#!/usr/bin/env python
# coding: latin-1

# Import libary functions we need
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
import time

# Set which GPIO pins the drive outputs are connected to
DRIVE_1 = 4
DRIVE_2 = 18
DRIVE_3 = 8
DRIVE_4 = 7

# Set all of the drive pins as output pins
GPIO.setup(DRIVE_1, GPIO.OUT)
GPIO.setup(DRIVE_2, GPIO.OUT)
GPIO.setup(DRIVE_3, GPIO.OUT)
GPIO.setup(DRIVE_4, GPIO.OUT)

# Map the on/off state to nicer names for display
dName = {}
dName[True] = ‘ON ‘
dName[False] = ‘OFF’

# Function to set all drives off
def MotorOff():
GPIO.output(DRIVE_1, GPIO.LOW)
GPIO.output(DRIVE_2, GPIO.LOW)
GPIO.output(DRIVE_3, GPIO.LOW)
GPIO.output(DRIVE_4, GPIO.LOW)

# Setup for processor monitor, adjust your temperature here. The fan will stay on between tempHigh and tempLow.
# Default at 50 degrees celsius and 33 degrees celsius.
lProcessorFans = [DRIVE_1] # List of fans to turn on when processor is too hot
pathSensor = ‘/sys/class/thermal/thermal_zone0/temp’ # File path used to read the temperature
readingPrintMultiplier = 0.001 # Value to multiply the reading by for user display
tempHigh = 50000 # Reading at which the fan(s) will be started (same units as file)
tempLow = 33000 # Reading at which the fan(s) will be stopped (same units as file)
interval = 1 # Time between readings in seconds

try:
# Start by turning all drives off
MotorOff()
#raw_input(‘You can now turn on the power, press ENTER to continue’)
fansOn = False
while True:
# Read the temperature in from the file system
fSensor = open(pathSensor, ‘r’)
reading = float(fSensor.read())
fSensor.close()
# Adjust fan(s) depending on current status
if fansOn:
if reading <= tempLow:
# We have cooled down enough, turn the fans off
for fan in lProcessorFans:
GPIO.output(fan, GPIO.LOW)
fansOn = False
else:
if reading >= tempHigh:
# We have warmed up enough, turn the fans on
for fan in lProcessorFans:
GPIO.output(fan, GPIO.HIGH)
fansOn = True
# Print the latest reading and the current state of all 4 drives
print ‘%02.3f %s %s %s %s’ % (reading * readingPrintMultiplier, dName[GPIO.input(DRIVE_1)], dName[GPIO.input(DRIVE_2)], dName[GPIO.input(DRIVE_3)], dName[GPIO.input(DRIVE_4)])
# Wait a while
time.sleep(interval)
except KeyboardInterrupt:
# CTRL+C exit, turn off the drives and release the GPIO pins
print ‘Terminated’
MotorOff()
raw_input(‘Turn the power off now, press ENTER to continue’)
GPIO.cleanup()

Link to raw github file

 

Neurologie Boeken

Harrisons.Neurology.in.Clinical.Medicine.4th.Edition.k5t8u.iji8f.pdf
Neurologie formularium.pdf
Oxford Handbook of Neurology, Second Edition – Manji, Hadi .pdf

Neurologie Aantekeningen

Neurologie aantekening 2017

ICK week Neurologie.docx
MAK-toets-voorbereiding-neurologie-Rick.docx
MAK Neuro kennis en vragen obv boek hijdra.docx
MAK toets voorbereiding neurologie – Rick.docx
Neurologie boek.docx
Neurologisch onderzoek template.docx
Samenvatting_Hijdra_ Neurologie.pdf
Samenvatting DD%27s Neurologie.pdf
Samenvatting Hijdra.pdf
tv mak neuro.docx

Neurologie Powerpoint 2017

Beschrijvingen Casuistiek ICK NEUROLOGIE.pdf
C1 EEN 59 JARIGE VROUW MET SCHEEF GELAAT docentversie.ppt
C2 EEN 57 JARIGE MAN MET NEUROLOGISCHE UITVAL DOCENT versie.ppt
C3 EEN 39 JARIGE BEWUSTELOZE MAN docentversie.ppt
C4 Een 70 jarige man met NEUROLOGISCHE UITVAL DOCENT versie.ppt
C5 MAN VALT VAN STEIGER docentversie.ppt
C6 VROUW MET LOOPSTOORNISSEN DOCENT versie.ppt
C7 Een 33 jarige man die struikelt DOCENT versie.ppt
C8 Een 26 jarige vrouw ziet wazig DOCENT versie.ppt
C9 Een 65 jarige vrouw ziet plots niet goed DOCENT versie.ppt
C10 EEN 55 JARIGE VROUW RAAKT BEWUSTELOOS DOCENT versie .ppt
C11 EEN 18 JARIGE STUDENT MET EPILEPTISCHE AANVAL DOCENT versie .ppt
C12 EEN 68 JARIGE MAN MET PIJN IN DE BENEN DOCENT versie .ppt
C13 EEN 42 JARIGE MAN MET RUGPIJN DOCENT versie .ppt
Casus4Fragment1.mpg
Casus4Fragment2.mpg
Functional neuroanatomy.ppt

The Sith

An ancient order of Force-wielders devoted to the dark side, the Sith practice hate, deception, and greed. Notable for their red-bladed lightsabers, black dress, and use of their aggressive feelings, the Sith look to amass power at all costs. The evil Darth Sidious, along with his apprentice Darth Vader, achieved the Sith goal of galactic conquest after a millennia of plotting.

[soundy button]