|
|
@@ -1,4 +1,4 @@
|
|
|
-#!/usr/bin/env python
|
|
|
+#!/usr/bin/env python3
|
|
|
from __future__ import print_function
|
|
|
|
|
|
import re
|
|
|
@@ -17,7 +17,7 @@ from googleapiclient.errors import HttpError
|
|
|
import math
|
|
|
|
|
|
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
|
|
|
-SPREADSHEET_ID = ''
|
|
|
+SPREADSHEET_ID = '18v8v6hoZTjahWhvyxRldmbdVlqAyKLa2HDINJJfTgKA'
|
|
|
|
|
|
class Client:
|
|
|
def __init__(self, hostname, address, macAddress, k8s):
|
|
|
@@ -36,6 +36,11 @@ def getClientsSheets(args):
|
|
|
return c
|
|
|
|
|
|
def getClientsUnifi(args):
|
|
|
+ UNIFI_USER='robot'
|
|
|
+ UNIFI_PASS='fguohsfogj910A'
|
|
|
+ udm = unificontrol.UnifiClient(host='192.168.1.1', username=UNIFI_USER, password=UNIFI_PASS, site='Default')
|
|
|
+ for mac in udm.list_guests():
|
|
|
+ print(mac)
|
|
|
c = Client(hostname="gondor", address="192.168.1.9", macAddress="00:00:00:AA:BB:CC", k8s=False)
|
|
|
return c
|
|
|
|
|
|
@@ -43,6 +48,22 @@ def getClientsPihole(args):
|
|
|
c = Client(hostname="morgul", address="192.168.1.1", macAddress="00:00:00:AA:BB:CC", k8s=False)
|
|
|
return c
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+def buildGoogleCredentials(args):
|
|
|
+ creds = None
|
|
|
+ if os.path.exists('token.json'):
|
|
|
+ creds = Credentials.from_authorized_user_file('token.json', SCOPES)
|
|
|
+ if not creds or not creds.valid:
|
|
|
+ if creds and creds.expired and creds.refresh_token:
|
|
|
+ creds.refresh(Request())
|
|
|
+ else:
|
|
|
+ flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
|
|
|
+ creds = flow.run_local_server(port=0)
|
|
|
+ with open('token.json', 'w') as token:
|
|
|
+ token.write(creds.to_json())
|
|
|
+ return creds
|
|
|
+
|
|
|
def main():
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
@@ -59,7 +80,7 @@ def main():
|
|
|
parser.add_argument("--sheetid", required=False, help="Google Sheet ID to read from", type=str)
|
|
|
|
|
|
parser.add_argument("--readfrom", required=True, help="Which datasource to read from (unifi, pihole, sheets)", type=str, action='append')
|
|
|
- parser.add_argument("--writeto", required=True, help="Which datasource to write to (unifi, pihole, sheets)", type=str, action='append')
|
|
|
+ parser.add_argument("--writeto", required=True, help="Which datasource to write to (unifi, pihole, sheets, stdout)", type=str, action='append')
|
|
|
|
|
|
|
|
|
clients = []
|