From 8cdc67ba522e4cdfb563dce7662b70735c8065eb Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 22:40:04 -0500 Subject: [PATCH 01/30] Update pihole_tweeter.py --- pihole_tweeter.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 6d235cf..31fadb7 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -28,12 +28,7 @@ if not (api_path, consumer_key, consumer_key, consumer_secret, access_token, acc print('2 Please check your config.ini.') sys.exit(1) - -def comma_value(num): - """Helper function for thousand separators""" - return "{:,}".format(int(num)).replace(',', '.') - - + def get_api(): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) @@ -65,12 +60,12 @@ def get_pihole_data(): def construct_tweet(data): - today = datetime.today().strftime("%d.%m.%Y") - tweet = 'Pi-Hole-Statistik für den {date}:\n'.format(date=today) - tweet += 'Blockierte Werbung: ' + str(comma_value(data['ads_blocked_today'])) - tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' - tweet += 'DNS-Abfragen: ' + str(comma_value(data['dns_queries_today'])) + '\n' - tweet += 'Domains auf der Blacklist: ' + str(comma_value(data['domains_being_blocked'])) + today = datetime.today().strftime("%m.%d.%Y") + tweet = 'Pi-hole statistics for {date}:\n'.format(date=today) + tweet += 'Total Ads Blocked: ' + (data['ads_blocked_today']) + tweet += ' (' + (data['ads_percentage_today'] + ' %)\n' + tweet += 'Total DNS Queries: ' + (data['dns_queries_today']) + '\n' + tweet += 'Domains on Blacklist: ' + (data['domains_being_blocked']) return tweet -- 2.25.1 From d627522c611dc5f1fdf7a3e482fb37010fa5682f Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 22:41:39 -0500 Subject: [PATCH 02/30] Translated output to english --- pihole_tweeter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 31fadb7..37f3c45 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -61,9 +61,9 @@ def get_pihole_data(): def construct_tweet(data): today = datetime.today().strftime("%m.%d.%Y") - tweet = 'Pi-hole statistics for {date}:\n'.format(date=today) + tweet = 'Pi-hole Stats for {date}:\n'.format(date=today) tweet += 'Total Ads Blocked: ' + (data['ads_blocked_today']) - tweet += ' (' + (data['ads_percentage_today'] + ' %)\n' + tweet += ' (' + (data['ads_percentage_today']) + ' %)\n' tweet += 'Total DNS Queries: ' + (data['dns_queries_today']) + '\n' tweet += 'Domains on Blacklist: ' + (data['domains_being_blocked']) return tweet -- 2.25.1 From 3c27fc1afa76f97d969b08f6360e71296f6a3132 Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 22:48:47 -0500 Subject: [PATCH 03/30] maybe it works now --- pihole_tweeter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 37f3c45..84950ac 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -62,10 +62,10 @@ def get_pihole_data(): def construct_tweet(data): today = datetime.today().strftime("%m.%d.%Y") tweet = 'Pi-hole Stats for {date}:\n'.format(date=today) - tweet += 'Total Ads Blocked: ' + (data['ads_blocked_today']) - tweet += ' (' + (data['ads_percentage_today']) + ' %)\n' - tweet += 'Total DNS Queries: ' + (data['dns_queries_today']) + '\n' - tweet += 'Domains on Blacklist: ' + (data['domains_being_blocked']) + tweet += 'Total Ads Blocked: ' + ['ads_blocked_today'] + tweet += ' (' + ['ads_percentage_today'] + ' %)\n' + tweet += 'Total DNS Queries: ' + ['dns_queries_today'] + '\n' + tweet += 'Domains on Blacklist: ' + ['domains_being_blocked'] return tweet -- 2.25.1 From d6f59f0d8d045ef63d133d07e0d8eab4def9063a Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 22:50:13 -0500 Subject: [PATCH 04/30] Update pihole_tweeter.py --- pihole_tweeter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 84950ac..a5221a7 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -62,10 +62,10 @@ def get_pihole_data(): def construct_tweet(data): today = datetime.today().strftime("%m.%d.%Y") tweet = 'Pi-hole Stats for {date}:\n'.format(date=today) - tweet += 'Total Ads Blocked: ' + ['ads_blocked_today'] - tweet += ' (' + ['ads_percentage_today'] + ' %)\n' - tweet += 'Total DNS Queries: ' + ['dns_queries_today'] + '\n' - tweet += 'Domains on Blacklist: ' + ['domains_being_blocked'] + tweet += 'Total Ads Blocked: ' + str(['ads_blocked_today']) + tweet += ' (' + str(['ads_percentage_today']) + ' %)\n' + tweet += 'Total DNS Queries: ' + str(['dns_queries_today']) + '\n' + tweet += 'Domains on Blacklist: ' + str(['domains_being_blocked']) return tweet -- 2.25.1 From 8b309cd3bd3a2c228f640c49adb8a8a92fc2b72f Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 22:51:43 -0500 Subject: [PATCH 05/30] Update pihole_tweeter.py --- pihole_tweeter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index a5221a7..3baa473 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -62,10 +62,10 @@ def get_pihole_data(): def construct_tweet(data): today = datetime.today().strftime("%m.%d.%Y") tweet = 'Pi-hole Stats for {date}:\n'.format(date=today) - tweet += 'Total Ads Blocked: ' + str(['ads_blocked_today']) - tweet += ' (' + str(['ads_percentage_today']) + ' %)\n' - tweet += 'Total DNS Queries: ' + str(['dns_queries_today']) + '\n' - tweet += 'Domains on Blacklist: ' + str(['domains_being_blocked']) + tweet += 'Total Ads Blocked: ' + str(data(['ads_blocked_today'])) + tweet += ' (' + str(data(['ads_percentage_today'])) + ' %)\n' + tweet += 'Total DNS Queries: ' + str(data(['dns_queries_today'])) + '\n' + tweet += 'Domains on Blacklist: ' + str(data(['domains_being_blocked'])) return tweet -- 2.25.1 From 3c8b1744918c2836651bccda5ddba12a323fc7bb Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 22:52:55 -0500 Subject: [PATCH 06/30] Update pihole_tweeter.py --- pihole_tweeter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 3baa473..95e4e73 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -62,10 +62,10 @@ def get_pihole_data(): def construct_tweet(data): today = datetime.today().strftime("%m.%d.%Y") tweet = 'Pi-hole Stats for {date}:\n'.format(date=today) - tweet += 'Total Ads Blocked: ' + str(data(['ads_blocked_today'])) - tweet += ' (' + str(data(['ads_percentage_today'])) + ' %)\n' - tweet += 'Total DNS Queries: ' + str(data(['dns_queries_today'])) + '\n' - tweet += 'Domains on Blacklist: ' + str(data(['domains_being_blocked'])) + tweet += 'Total Ads Blocked: ' + str('ads_blocked_today') + tweet += ' (' + str('ads_percentage_today') + ' %)\n' + tweet += 'Total DNS Queries: ' + str('dns_queries_today') + '\n' + tweet += 'Domains on Blacklist: ' + str('domains_being_blocked') return tweet -- 2.25.1 From 6bed8dd8b2a550a45df49b676b8d78d6fc06e91e Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 22:54:06 -0500 Subject: [PATCH 07/30] Update pihole_tweeter.py --- pihole_tweeter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 95e4e73..a5221a7 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -62,10 +62,10 @@ def get_pihole_data(): def construct_tweet(data): today = datetime.today().strftime("%m.%d.%Y") tweet = 'Pi-hole Stats for {date}:\n'.format(date=today) - tweet += 'Total Ads Blocked: ' + str('ads_blocked_today') - tweet += ' (' + str('ads_percentage_today') + ' %)\n' - tweet += 'Total DNS Queries: ' + str('dns_queries_today') + '\n' - tweet += 'Domains on Blacklist: ' + str('domains_being_blocked') + tweet += 'Total Ads Blocked: ' + str(['ads_blocked_today']) + tweet += ' (' + str(['ads_percentage_today']) + ' %)\n' + tweet += 'Total DNS Queries: ' + str(['dns_queries_today']) + '\n' + tweet += 'Domains on Blacklist: ' + str(['domains_being_blocked']) return tweet -- 2.25.1 From 88590c126e9e38670fdcf5fdfc74708008ae2d3f Mon Sep 17 00:00:00 2001 From: mwoolweaver Date: Mon, 15 Apr 2019 23:06:27 -0500 Subject: [PATCH 08/30] reset --- pihole_tweeter.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index a5221a7..6d235cf 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -28,7 +28,12 @@ if not (api_path, consumer_key, consumer_key, consumer_secret, access_token, acc print('2 Please check your config.ini.') sys.exit(1) - + +def comma_value(num): + """Helper function for thousand separators""" + return "{:,}".format(int(num)).replace(',', '.') + + def get_api(): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) @@ -60,12 +65,12 @@ def get_pihole_data(): def construct_tweet(data): - today = datetime.today().strftime("%m.%d.%Y") - tweet = 'Pi-hole Stats for {date}:\n'.format(date=today) - tweet += 'Total Ads Blocked: ' + str(['ads_blocked_today']) - tweet += ' (' + str(['ads_percentage_today']) + ' %)\n' - tweet += 'Total DNS Queries: ' + str(['dns_queries_today']) + '\n' - tweet += 'Domains on Blacklist: ' + str(['domains_being_blocked']) + today = datetime.today().strftime("%d.%m.%Y") + tweet = 'Pi-Hole-Statistik für den {date}:\n'.format(date=today) + tweet += 'Blockierte Werbung: ' + str(comma_value(data['ads_blocked_today'])) + tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' + tweet += 'DNS-Abfragen: ' + str(comma_value(data['dns_queries_today'])) + '\n' + tweet += 'Domains auf der Blacklist: ' + str(comma_value(data['domains_being_blocked'])) return tweet -- 2.25.1 From f5f0a0644f77f62a64c96d522c5eb40b527a602b Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 23:10:28 -0500 Subject: [PATCH 09/30] translate to english again and maybe commas are ok --- pihole_tweeter.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 6d235cf..c775658 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -31,7 +31,7 @@ if not (api_path, consumer_key, consumer_key, consumer_secret, access_token, acc def comma_value(num): """Helper function for thousand separators""" - return "{:,}".format(int(num)).replace(',', '.') + return "{:,}".format(int(num)).replace(',', ',') def get_api(): @@ -66,11 +66,11 @@ def get_pihole_data(): def construct_tweet(data): today = datetime.today().strftime("%d.%m.%Y") - tweet = 'Pi-Hole-Statistik für den {date}:\n'.format(date=today) - tweet += 'Blockierte Werbung: ' + str(comma_value(data['ads_blocked_today'])) + tweet = 'Pi-hole statistics for {date}:\n'.format(date=today) + tweet += 'Ads Blocked: ' + str(comma_value(data['ads_blocked_today'])) tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' - tweet += 'DNS-Abfragen: ' + str(comma_value(data['dns_queries_today'])) + '\n' - tweet += 'Domains auf der Blacklist: ' + str(comma_value(data['domains_being_blocked'])) + tweet += 'Total DNS Queries: ' + str(comma_value(data['dns_queries_today'])) + '\n' + tweet += 'Domains on Blocklist: ' + str(comma_value(data['domains_being_blocked'])) return tweet -- 2.25.1 From afc90ffaa67930fb8d13b432801ccb273a616e1e Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 23:11:21 -0500 Subject: [PATCH 10/30] Update pihole_tweeter.py --- pihole_tweeter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index c775658..c0fdf36 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -65,7 +65,7 @@ def get_pihole_data(): def construct_tweet(data): - today = datetime.today().strftime("%d.%m.%Y") + today = datetime.today().strftime("%m.%d.%Y") tweet = 'Pi-hole statistics for {date}:\n'.format(date=today) tweet += 'Ads Blocked: ' + str(comma_value(data['ads_blocked_today'])) tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' -- 2.25.1 From 9933141e70c5b3d4442a3e38d2bd374471e237cc Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 23:18:19 -0500 Subject: [PATCH 11/30] Update pihole_tweeter.py --- pihole_tweeter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index c0fdf36..ff2b40f 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -65,12 +65,13 @@ def get_pihole_data(): def construct_tweet(data): - today = datetime.today().strftime("%m.%d.%Y") - tweet = 'Pi-hole statistics for {date}:\n'.format(date=today) + today = datetime.today().strftime("%m/%d/%Y") + tweet += 'Pi-hole statistics for {date}:\n'.format(date=today) tweet += 'Ads Blocked: ' + str(comma_value(data['ads_blocked_today'])) tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' tweet += 'Total DNS Queries: ' + str(comma_value(data['dns_queries_today'])) + '\n' tweet += 'Domains on Blocklist: ' + str(comma_value(data['domains_being_blocked'])) + tweet += '#Sky-hole: The @The_Pi_Hole on @GoogleCompute.' return tweet -- 2.25.1 From 877527711181b9e6183a589021fb90a57a0b4f05 Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 23:19:34 -0500 Subject: [PATCH 12/30] Update pihole_tweeter.py --- pihole_tweeter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index ff2b40f..5ba1c49 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -66,7 +66,7 @@ def get_pihole_data(): def construct_tweet(data): today = datetime.today().strftime("%m/%d/%Y") - tweet += 'Pi-hole statistics for {date}:\n'.format(date=today) + tweet = 'Pi-hole statistics for {date}:\n'.format(date=today) tweet += 'Ads Blocked: ' + str(comma_value(data['ads_blocked_today'])) tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' tweet += 'Total DNS Queries: ' + str(comma_value(data['dns_queries_today'])) + '\n' -- 2.25.1 From 02308269de8a712613b56689d2ab93462dffe731 Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 23:20:26 -0500 Subject: [PATCH 13/30] Update pihole_tweeter.py --- pihole_tweeter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 5ba1c49..2151bff 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -70,7 +70,7 @@ def construct_tweet(data): tweet += 'Ads Blocked: ' + str(comma_value(data['ads_blocked_today'])) tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' tweet += 'Total DNS Queries: ' + str(comma_value(data['dns_queries_today'])) + '\n' - tweet += 'Domains on Blocklist: ' + str(comma_value(data['domains_being_blocked'])) + tweet += 'Domains on Blocklist: ' + str(comma_value(data['domains_being_blocked'])) + '\n' tweet += '#Sky-hole: The @The_Pi_Hole on @GoogleCompute.' return tweet -- 2.25.1 From dac089daebde97cf038892e4bb9a61d1c8343cc8 Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Mon, 15 Apr 2019 23:21:14 -0500 Subject: [PATCH 14/30] Update pihole_tweeter.py --- pihole_tweeter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 2151bff..43546eb 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -71,7 +71,7 @@ def construct_tweet(data): tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' tweet += 'Total DNS Queries: ' + str(comma_value(data['dns_queries_today'])) + '\n' tweet += 'Domains on Blocklist: ' + str(comma_value(data['domains_being_blocked'])) + '\n' - tweet += '#Sky-hole: The @The_Pi_Hole on @GoogleCompute.' + tweet += '#SkyHole: The @The_Pi_Hole on @GoogleCompute.' return tweet -- 2.25.1 From a64b7ad9c4391ac9774fc1cccdad311dc34d9f14 Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 00:29:22 -0500 Subject: [PATCH 15/30] Update pihole_tweeter.py --- pihole_tweeter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 43546eb..b5f895d 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -68,7 +68,7 @@ def construct_tweet(data): today = datetime.today().strftime("%m/%d/%Y") tweet = 'Pi-hole statistics for {date}:\n'.format(date=today) tweet += 'Ads Blocked: ' + str(comma_value(data['ads_blocked_today'])) - tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', ',') + ' %)\n' + tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', '.') + ' %)\n' tweet += 'Total DNS Queries: ' + str(comma_value(data['dns_queries_today'])) + '\n' tweet += 'Domains on Blocklist: ' + str(comma_value(data['domains_being_blocked'])) + '\n' tweet += '#SkyHole: The @The_Pi_Hole on @GoogleCompute.' -- 2.25.1 From 155f49083ad6f0c49e0802c2188c3f1724873a07 Mon Sep 17 00:00:00 2001 From: mwoolweaver Date: Tue, 16 Apr 2019 01:09:05 -0500 Subject: [PATCH 16/30] maybe automate install --- install.sh | 31 +++++++++++++++++++++++++++++++ pi-hole-tweeter-cron | 1 + 2 files changed, 32 insertions(+) create mode 100644 install.sh create mode 100644 pi-hole-tweeter-cron diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..04a59df --- /dev/null +++ b/install.sh @@ -0,0 +1,31 @@ +#!/bin/sh +## pihole tweeter +NAMEOFAPP="piholetweeter" +WHATITDOES="This is a script from DarthKeizer to tweet the Pi-Hole stats daily." + +{ if +(whiptail --title "$NAMEOFAPP" --yes-button "Skip" --no-button "Proceed" --yesno "Do you want to setup $NAMEOFAPP? $WHATITDOES" 8 78) +then +echo "Declined $NAMEOFAPP" +else +sudo apt-get install -y python3-pip +sudo python3 -m pip install -U setuptools +sudo python3 -m pip install tweepy +sudo python3 -m pip install request +sudo python3 -m pip install urllib +sudo python3 -m pip install json +sudo python3 -m pip install simplejson +sudo python3 -m pip install datetime +sudo wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pihole_tweeter.py -P ~/pihole_tweeter/pihole_tweeter.py +sudo wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/config.ini.example -P ~/pihole_tweeter/config.ini +sudo wget http://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/ +CONSUMER_KEY=$(whiptail --inputbox "Consumer Key" 20 60 "" 3>&1 1>&2 2>&3) +CONSUMER_SECRET=$(whiptail --inputbox "Consumer Secret" 20 60 "" 3>&1 1>&2 2>&3) +ACCESS_TOKEN=$(whiptail --inputbox "Access Token" 20 60 "" 3>&1 1>&2 2>&3) +ACCESS_TOKEN_SECRET=$(whiptail --inputbox "Access Token Secret" 20 60 "" 3>&1 1>&2 2>&3) +sudo sed -i "s/VALUE1/$CONSUMER_KEY/" ~/pihole_tweeter/config.ini +sudo sed -i "s/VALUE2/$CONSUMER_SECRET/" ~/pihole_tweeter/config.ini +sudo sed -i "s/VALUE3/$ACCESS_TOKEN/" ~/pihole_tweeter/config.ini +sudo sed -i "s/VALUE4/$ACCESS_TOKEN_SECRET/" ~/pihole_tweeter/config.ini +fi } + diff --git a/pi-hole-tweeter-cron b/pi-hole-tweeter-cron new file mode 100644 index 0000000..fba3e69 --- /dev/null +++ b/pi-hole-tweeter-cron @@ -0,0 +1 @@ +55 23 * * * root cd ~/pihole_tweeter/ && python3 pihole_tweeter.py >> ~/pihole_tweeter/twitter_bot.txt -- 2.25.1 From 7ef16d09d8cf0aebc2705e438eae35fa7de2156a Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 01:13:13 -0500 Subject: [PATCH 17/30] Rename config.ini.example to config.ini --- config.ini.example => config.ini | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename config.ini.example => config.ini (100%) diff --git a/config.ini.example b/config.ini similarity index 100% rename from config.ini.example rename to config.ini -- 2.25.1 From 9d0b741d2b5532e75a45fde611a703fc45e236fb Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 01:15:07 -0500 Subject: [PATCH 18/30] Update config.ini --- config.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.ini b/config.ini index 26d8c40..eb2d4cb 100644 --- a/config.ini +++ b/config.ini @@ -1,6 +1,6 @@ [DEFAULT] api_path = http://localhost/admin/api.php -consumer_key = CONSUMERKEY -consumer_secret = CONSUMERSECRET -access_token = ACCESS-TOKEN -access_token_secret = ACCESSTOKENSECRET +consumer_key = VALUE1 +consumer_secret = VALUE2 +access_token = VALUE3 +access_token_secret = VALUE4 -- 2.25.1 From e039dd8caf539a89bd53f1f252c67d9b204c58cf Mon Sep 17 00:00:00 2001 From: mwoolweaver Date: Tue, 16 Apr 2019 02:00:21 -0500 Subject: [PATCH 19/30] automation --- install.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) mode change 100644 => 100755 install.sh diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index 04a59df..4826ef7 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/bin/sh ## pihole tweeter -NAMEOFAPP="piholetweeter" -WHATITDOES="This is a script from DarthKeizer to tweet the Pi-Hole stats daily." +NAMEOFAPP="Pi-hole Stats Tweeter" +WHATITDOES="This script will install Pi-Hole-stats-tweeter and setup a cronjob that runs every day at 23:55" { if (whiptail --title "$NAMEOFAPP" --yes-button "Skip" --no-button "Proceed" --yesno "Do you want to setup $NAMEOFAPP? $WHATITDOES" 8 78) @@ -9,23 +9,23 @@ then echo "Declined $NAMEOFAPP" else sudo apt-get install -y python3-pip -sudo python3 -m pip install -U setuptools -sudo python3 -m pip install tweepy -sudo python3 -m pip install request -sudo python3 -m pip install urllib -sudo python3 -m pip install json -sudo python3 -m pip install simplejson -sudo python3 -m pip install datetime -sudo wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pihole_tweeter.py -P ~/pihole_tweeter/pihole_tweeter.py -sudo wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/config.ini.example -P ~/pihole_tweeter/config.ini -sudo wget http://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/ +pip3 install -U -r https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/requirements.txt +sudo wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pihole_tweeter.py -P ~/pihole_tweeter/ +sudo wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/config.ini -P ~/pihole_tweeter/ CONSUMER_KEY=$(whiptail --inputbox "Consumer Key" 20 60 "" 3>&1 1>&2 2>&3) CONSUMER_SECRET=$(whiptail --inputbox "Consumer Secret" 20 60 "" 3>&1 1>&2 2>&3) ACCESS_TOKEN=$(whiptail --inputbox "Access Token" 20 60 "" 3>&1 1>&2 2>&3) ACCESS_TOKEN_SECRET=$(whiptail --inputbox "Access Token Secret" 20 60 "" 3>&1 1>&2 2>&3) -sudo sed -i "s/VALUE1/$CONSUMER_KEY/" ~/pihole_tweeter/config.ini -sudo sed -i "s/VALUE2/$CONSUMER_SECRET/" ~/pihole_tweeter/config.ini -sudo sed -i "s/VALUE3/$ACCESS_TOKEN/" ~/pihole_tweeter/config.ini -sudo sed -i "s/VALUE4/$ACCESS_TOKEN_SECRET/" ~/pihole_tweeter/config.ini +sudo sed -ie "s/VALUE1/$CONSUMER_KEY/" ~/pihole_tweeter/config.ini +sudo sed -ie "s/VALUE2/$CONSUMER_SECRET/" ~/pihole_tweeter/config.ini +sudo sed -ie "s/VALUE3/$ACCESS_TOKEN/" ~/pihole_tweeter/config.ini +sudo sed -ie "s/VALUE4/$ACCESS_TOKEN_SECRET/" ~/pihole_tweeter/config.ini +fi } +{ if +(whiptail --title "$NAMEOFAPP" --yes-button "Skip" --no-button "Proceed" --yesno "Do you want to setup $NAMEOFAPP as a cronjob?" 8 78) +then +echo "did not install cronjob" +else +sudo wget http://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pi-hole-tweeter-cron -P /etc/cron.d/ +sudo rm ~/pihole_tweeter/config.inie fi } - -- 2.25.1 From 45c65a19b4fcb51145e60dcc38bdb62d0c4b8c5b Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 02:04:59 -0500 Subject: [PATCH 20/30] Update README.md --- README.md | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9e74058..d177ed2 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,8 @@ Send a daily tweet with your Pi-Hole statistics! # How to use -1. Install Python 3 -2. `pip3 install -U -r requirements.txt` -3. Copy config.ini.example to config.ini and adjust it - * `api_path` = Path to your /admin/api.php of Pi-Hole - * Tokens: Create an application [here](https://apps.twitter.com/) -4. Run it! +1. Create an application [here](https://apps.twitter.com/). You will need the tokens for this to work -# Cronjob -This will tweet your stats at 23:59 everyday and redirects output to /dev/null: +2. curl -sSL https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/install.sh | bash -``` -59 23 * * * python3 /path/to/pihole_tweeter.py >/dev/null 2>&1 -``` +the install script will ask if you want to install as a cronjob -- 2.25.1 From e635c925d86418af700c40da1ee77e33e1565a7c Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 02:06:00 -0500 Subject: [PATCH 21/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d177ed2..3e10a81 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,6 @@ Send a daily tweet with your Pi-Hole statistics! # How to use 1. Create an application [here](https://apps.twitter.com/). You will need the tokens for this to work -2. curl -sSL https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/install.sh | bash +2. ```curl -sSL https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/install.sh | bash``` the install script will ask if you want to install as a cronjob -- 2.25.1 From 76b305f7d2897cdb214c379fc826cec5f4309f68 Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 02:06:44 -0500 Subject: [PATCH 22/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e10a81..a26d914 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Send a daily tweet with your Pi-Hole statistics! # How to use -1. Create an application [here](https://apps.twitter.com/). You will need the tokens for this to work +1. Create an application via Twitter [here](https://apps.twitter.com/). You will need the tokens for this to work. 2. ```curl -sSL https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/install.sh | bash``` -- 2.25.1 From 06821a9fd4074bceb1f4d0b36d87fbdaa4788c9b Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 02:09:08 -0500 Subject: [PATCH 23/30] Update install.sh --- install.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 4826ef7..95a1a03 100755 --- a/install.sh +++ b/install.sh @@ -8,18 +8,18 @@ WHATITDOES="This script will install Pi-Hole-stats-tweeter and setup a cronjob t then echo "Declined $NAMEOFAPP" else -sudo apt-get install -y python3-pip +apt-get install -y python3-pip pip3 install -U -r https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/requirements.txt -sudo wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pihole_tweeter.py -P ~/pihole_tweeter/ -sudo wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/config.ini -P ~/pihole_tweeter/ +wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pihole_tweeter.py -P ~/pihole_tweeter/ +wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/config.ini -P ~/pihole_tweeter/ CONSUMER_KEY=$(whiptail --inputbox "Consumer Key" 20 60 "" 3>&1 1>&2 2>&3) CONSUMER_SECRET=$(whiptail --inputbox "Consumer Secret" 20 60 "" 3>&1 1>&2 2>&3) ACCESS_TOKEN=$(whiptail --inputbox "Access Token" 20 60 "" 3>&1 1>&2 2>&3) ACCESS_TOKEN_SECRET=$(whiptail --inputbox "Access Token Secret" 20 60 "" 3>&1 1>&2 2>&3) -sudo sed -ie "s/VALUE1/$CONSUMER_KEY/" ~/pihole_tweeter/config.ini -sudo sed -ie "s/VALUE2/$CONSUMER_SECRET/" ~/pihole_tweeter/config.ini -sudo sed -ie "s/VALUE3/$ACCESS_TOKEN/" ~/pihole_tweeter/config.ini -sudo sed -ie "s/VALUE4/$ACCESS_TOKEN_SECRET/" ~/pihole_tweeter/config.ini +sed -ie "s/VALUE1/$CONSUMER_KEY/" ~/pihole_tweeter/config.ini +sed -ie "s/VALUE2/$CONSUMER_SECRET/" ~/pihole_tweeter/config.ini +sed -ie "s/VALUE3/$ACCESS_TOKEN/" ~/pihole_tweeter/config.ini +sed -ie "s/VALUE4/$ACCESS_TOKEN_SECRET/" ~/pihole_tweeter/config.ini fi } { if (whiptail --title "$NAMEOFAPP" --yes-button "Skip" --no-button "Proceed" --yesno "Do you want to setup $NAMEOFAPP as a cronjob?" 8 78) @@ -27,5 +27,5 @@ then echo "did not install cronjob" else sudo wget http://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pi-hole-tweeter-cron -P /etc/cron.d/ -sudo rm ~/pihole_tweeter/config.inie +rm ~/pihole_tweeter/config.inie fi } -- 2.25.1 From 7a1f18e0e352876cfbc0d64a71e4bae29e1d388a Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 02:10:30 -0500 Subject: [PATCH 24/30] Update install.sh --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 95a1a03..7a952c3 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ WHATITDOES="This script will install Pi-Hole-stats-tweeter and setup a cronjob t then echo "Declined $NAMEOFAPP" else -apt-get install -y python3-pip +sudo apt-get install -y python3-pip pip3 install -U -r https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/requirements.txt wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pihole_tweeter.py -P ~/pihole_tweeter/ wget https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/config.ini -P ~/pihole_tweeter/ -- 2.25.1 From 1e86d31692d5319e0256d3f8628e87e1af9d734f Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 02:20:00 -0500 Subject: [PATCH 25/30] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index a26d914..13cefd4 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,10 @@ Send a daily tweet with your Pi-Hole statistics! 2. ```curl -sSL https://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/install.sh | bash``` the install script will ask if you want to install as a cronjob + + + +#Credits + +original install script was found [here](https://github.com/deathbybandaid/Pi-Hole-stats-tweeter/blob/master/install.sh) + -- 2.25.1 From 7f0d950af217a5c3036e3577726b43bc3a9bfc22 Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 02:34:42 -0500 Subject: [PATCH 26/30] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 13cefd4..27e5c45 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Send a daily tweet with your Pi-Hole statistics! the install script will ask if you want to install as a cronjob +upon successful cron completion you will find ~/pihole_tweeter/twitter_bot.txt #Credits -- 2.25.1 From 108573cbd022f040ecbe802f483eec996a846aac Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 16 Apr 2019 02:49:48 -0500 Subject: [PATCH 27/30] Update pihole_tweeter.py --- pihole_tweeter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index b5f895d..dd2e680 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -96,7 +96,7 @@ def main(): except tweepy.error.TweepError: print('Status could not be posted.') return - print('Status posted! https://twitter.com/' + status.author.screen_name + '/status/' + status.id_str) + print(status.id_str) if __name__ == '__main__': -- 2.25.1 From 7c16fbf11986a3a7b900864c6e90bc82e76145be Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 23 Apr 2019 05:20:08 -0500 Subject: [PATCH 28/30] Update pihole_tweeter.py --- pihole_tweeter.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index dd2e680..3c5dec6 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -3,8 +3,12 @@ import sys from configparser import ConfigParser from datetime import datetime - +import psutil +import os +from hurry.filesize import size +from uptime import uptime import tweepy +import platform from requests import get config = ConfigParser() @@ -28,6 +32,19 @@ if not (api_path, consumer_key, consumer_key, consumer_secret, access_token, acc print('2 Please check your config.ini.') sys.exit(1) +def pretty_time_delta(seconds): + seconds = int(seconds) + days, seconds = divmod(seconds, 86400) + hours, seconds = divmod(seconds, 3600) + minutes, seconds = divmod(seconds, 60) + if days > 0: + return '%dd %dh %dm %ds' % (days, hours, minutes, seconds) + elif hours > 0: + return '%dh %dm %ds' % (hours, minutes, seconds) + elif minutes > 0: + return '%dm %ds' % (minutes, seconds) + else: + return '%ds' % (seconds,) def comma_value(num): """Helper function for thousand separators""" @@ -63,15 +80,16 @@ def get_pihole_data(): return data +print(platform.system()) def construct_tweet(data): - today = datetime.today().strftime("%m/%d/%Y") - tweet = 'Pi-hole statistics for {date}:\n'.format(date=today) + tweet = '#ComputeHole: The @The_Pi_Hole on @GoogleCompute\n' tweet += 'Ads Blocked: ' + str(comma_value(data['ads_blocked_today'])) - tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', '.') + ' %)\n' + tweet += ' (' + str(round(data['ads_percentage_today'], 2)).replace('.', '.') + '%)\n' tweet += 'Total DNS Queries: ' + str(comma_value(data['dns_queries_today'])) + '\n' tweet += 'Domains on Blocklist: ' + str(comma_value(data['domains_being_blocked'])) + '\n' - tweet += '#SkyHole: The @The_Pi_Hole on @GoogleCompute.' + tweet += 'Uptime: ' + pretty_time_delta(uptime()) + '\n' + 'Load Avg: ' + str(os.getloadavg()) + '\n' + 'Ram Usage: ' + str(psutil.virtual_memory()[2]) + '% ' + str(size(psutil.virtual_memory()[3])) + '/' + str(size(psutil.virtual_memory()[1])) + '\n' + tweet += 'Kernel/OS: ' + str(platform.platform()) return tweet -- 2.25.1 From 0b28999da36646b1dadcf96272bf51fb0e56dd1a Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 23 Apr 2019 05:21:11 -0500 Subject: [PATCH 29/30] Update pihole_tweeter.py --- pihole_tweeter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole_tweeter.py b/pihole_tweeter.py index 3c5dec6..7206455 100644 --- a/pihole_tweeter.py +++ b/pihole_tweeter.py @@ -80,7 +80,7 @@ def get_pihole_data(): return data -print(platform.system()) + def construct_tweet(data): tweet = '#ComputeHole: The @The_Pi_Hole on @GoogleCompute\n' -- 2.25.1 From 32c9a7ab563b0ed4cfe95b17b9376011440d8d57 Mon Sep 17 00:00:00 2001 From: Michael Woolweaver Date: Tue, 23 Apr 2019 05:23:06 -0500 Subject: [PATCH 30/30] Update install.sh --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index 7a952c3..f9db2e3 100755 --- a/install.sh +++ b/install.sh @@ -24,6 +24,7 @@ fi } { if (whiptail --title "$NAMEOFAPP" --yes-button "Skip" --no-button "Proceed" --yesno "Do you want to setup $NAMEOFAPP as a cronjob?" 8 78) then +rm ~/pihole_tweeter/config.inie echo "did not install cronjob" else sudo wget http://raw.githubusercontent.com/mwoolweaver/Pi-Hole-stats-tweeter/master/pi-hole-tweeter-cron -P /etc/cron.d/ -- 2.25.1