-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_helper.py
46 lines (38 loc) · 1.1 KB
/
list_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from pathlib import Path, PurePath
import json
# Path to the directory containing the brand files
BRAND_DATA_DIR = "brand_data"
class Brand:
"""
Brand class. Holds name, description, and product names
"""
def __init__(self, name, description, products):
self.name = name
self.description = description
self.products = products
def __str__(self):
return f"{self.name}: {self.description}\nProducts: {[p['name'] for p in self.products]}"
def get_brands():
"""
Pulls a list of brands from the brands.json file.
"""
with Path(PurePath('DB', BRAND_DATA_DIR, 'brands.json')).open(mode='r') as f:
brands = json.load(f)
brand_list = []
for brand in brands:
products = []
for product in brand["products"]:
products.append(product)
brand_list.append(Brand(brand["name"], brand["description"], products))
return brand_list
def get_sublist(brand):
"""
Get a list of subreddits for a given brand. TODO: implement
"""
sublist = ['buzzmasters']
return sublist
def get_timecode(dt):
"""
Generate a timecode from a datetime object.
"""
return dt.hour