I couldn’t find anything that does this anywhere, nor the toml file referenced in some examples.
This code takes the most recent aw-category-export.json from a folder specified (i used downloads) and converts it to a string to insert into queries.
import re
import os
def convert_categorisation(path_with_space):
#inorder to make the raw string work ensure there is a space before the final " EG:
# r"C:\Users\NAME\Downloads\ "
downloads_path = path_with_space[:-1]
file_location = downloads_path + 'aw-category-export.json'
matches = 0
#searches download path for the most recent category export.
for root, dirs, files in os.walk(downloads_path):
for file in files:
if re.match('aw-category-export \(\d+\).json', file):
matches += 1
if matches != 0:
file_location = downloads_path + 'aw-category-export (%s).json'%matches
final_categories = []
#picks apart the category json and returns it in a format the queries want to work with.
with open(file_location, 'r') as file:
data = json.load(file)
for entry in data["categories"]:
category = ()
if entry['rule']['type'] != None:
category = category + (entry['name'],)
category = category + (entry['rule'],)
final_categories.append(category)
return(final_categories)
I hope this is helpfull to someone, if you have feedback i’d love to hear it.