From e36ecc3eb7cf8774edc35cd0e7fbcc30b0c1dd94 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 1 Dec 2023 09:21:54 +0000 Subject: [PATCH] Commit changes made by code formatters --- src/geocode.py | 13 +++++++++---- src/juniper.py | 21 +++++++++++++-------- src/main.py | 10 ++++++---- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/geocode.py b/src/geocode.py index 4385f68..7a20589 100644 --- a/src/geocode.py +++ b/src/geocode.py @@ -1,24 +1,28 @@ from geopy import Nominatim from timezonefinder import TimezoneFinder + def geocode(address) -> str: geolocator = Nominatim(user_agent="geocode") location = geolocator.geocode(address) try: latitude, longitude = location.latitude, location.longitude except ValueError: - raise ValueError('geocode unable to find latitude & longitude for {address}'.format(address=address)) + raise ValueError( + 'geocode unable to find latitude & longitude for {address}'.format(address=address)) return latitude, longitude + def find_country_code(gps) -> tuple: latitude = gps[0] longitude = gps[1] geolocator = Nominatim(user_agent="geocode") location = geolocator.reverse([latitude, longitude]) - country_code=location.raw['address']['country_code'] + country_code = location.raw['address']['country_code'] return country_code.upper() + def find_timezone(gps) -> tuple: tf_init = TimezoneFinder() latitude = gps[0] @@ -26,8 +30,9 @@ def find_timezone(gps) -> tuple: try: timezone_name = tf_init.timezone_at(lat=latitude, lng=longitude) except ValueError: - raise ValueError('The coordinates were out of bounds {latitude}:{longitude}'.format(lat=latitude,lng=longitude)) + raise ValueError('The coordinates were out of bounds {latitude}:{longitude}'.format( + lat=latitude, lng=longitude)) if timezone_name is None: raise ValueError('GPS coordinates did not match a time_zone') - return timezone_name \ No newline at end of file + return timezone_name diff --git a/src/juniper.py b/src/juniper.py index 80f31ab..ad39931 100644 --- a/src/juniper.py +++ b/src/juniper.py @@ -1,6 +1,10 @@ -import sys, requests, json +import sys +import requests +import json # Mist CRUD operations + + class Admin(object): def __init__(self, token=''): self.session = requests.Session() @@ -21,7 +25,8 @@ def post(self, url, payload, timeout=60): print('Failed to POST') print('\tURL: {}'.format(url)) print('\tPayload: {}'.format(payload)) - print('\tResponse: {} ({})'.format(response.text, response.status_code)) + print('\tResponse: {} ({})'.format( + response.text, response.status_code)) return False @@ -39,7 +44,8 @@ def put(self, url, payload): print('Failed to PUT') print('\tURL: {}'.format(url)) print('\tPayload: {}'.format(payload)) - print('\tResponse: {} ({})'.format(response.text, response.status_code)) + print('\tResponse: {} ({})'.format( + response.text, response.status_code)) return False @@ -52,8 +58,8 @@ def juniper_script( mist_api_token='', org_id=''): - show_more_details = True # Configure True/False to enable/disable additional logging of the API response objects - + # Configure True/False to enable/disable additional logging of the API response objects + show_more_details = True # Check for required variables if mist_api_token == '': @@ -90,8 +96,6 @@ def juniper_script( } - - print('Calling the Mist Create Site API...') result = admin.post('/api/v1/orgs/' + org_id + '/sites', site) if result == False: @@ -116,7 +120,8 @@ def juniper_script( result = admin.put('/api/v1/sites/' + site_id + '/setting', site_setting) if result == False: - print('Failed to update site setting {} ({})'.format(site['name'], site_id)) + print('Failed to update site setting {} ({})'.format( + site['name'], site_id)) else: print('Updated site setting {} ({})'.format(site['name'], site_id)) diff --git a/src/main.py b/src/main.py index 61c9ccd..4b84078 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,6 @@ from juniper import juniper_script -import os, csv +import os +import csv from geocode import geocode, find_timezone, find_country_code @@ -11,20 +12,21 @@ def csv_to_json(file_path): title = reader.fieldnames for row in reader: - csv_rows.extend([ {title[i]: row[title[i]] for i in range(len(title))} ]) + csv_rows.extend([{title[i]: row[title[i]] + for i in range(len(title))}]) return csv_rows + if __name__ == '__main__': - csv_file_path=os.getcwd() + '/../test_data/sites_with_clients.csv' + csv_file_path = os.getcwd() + '/../test_data/sites_with_clients.csv' # Convert CSV to valid JSON data = csv_to_json(csv_file_path) if data == None or data == []: raise ValueError('Failed to convert CSV file to JSON. Exiting script.') - # Create each site from the CSV file for d in data: # Variables