Skip to content

Commit

Permalink
Commit changes made by code formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 1, 2023
1 parent f4f6989 commit e36ecc3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
13 changes: 9 additions & 4 deletions src/geocode.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
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]
longitude = gps[1]
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
return timezone_name
21 changes: 13 additions & 8 deletions src/juniper.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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 == '':
Expand Down Expand Up @@ -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:
Expand All @@ -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))

Expand Down
10 changes: 6 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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
Expand Down

0 comments on commit e36ecc3

Please sign in to comment.