-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-transfer-template.py
More file actions
77 lines (66 loc) · 2.17 KB
/
create-transfer-template.py
File metadata and controls
77 lines (66 loc) · 2.17 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.8"
# dependencies = [
# "t3api_utils"
# ]
# ///
# Usage: uv run discontinue_items.py
#
# Follow the instructions to bulk discontinue items
#
# This script discontinues selected items for a T3 license.
# Make sure to have a CSV file with item names in the same directory
# before running the script.
from t3api_utils.api.operations import send_api_request
from t3api_utils.api.parallel import load_all_data_sync
from t3api_utils.main.utils import (get_authenticated_client_or_error,
match_collection_from_csv, pick_license)
def main():
# Get an authenticated client. User can choose between:
# - Credentials (username/password)
# - JWT token (accessible from T3 Chrome extension)
# - API key
api_client = get_authenticated_client_or_error()
# Pick a license interactively
license = pick_license(api_client=api_client)
# Load all the items for the selected license
all_items = load_all_data_sync(
client=api_client,
path="/v2/items",
license_number=license["licenseNumber"],
)
# To only select the items we want to discontinue,
# we're going to pass a CSV.
#
# Each column header must be an item property (e.g. "name")
#
# The simplest strategy is to pass a single-column
# CSV that specifices the item name exactly:
#
# name
# OG Kush 1g Prerolls
# Pineapple Express 1g Prerolls
#
# t3api_utils will look for .csv files in the same
# folder as the running script, or you can pass
# the path to the script manually
filtered_items = match_collection_from_csv(
data=all_items, on_no_match="error"
)
# This will discontinue the items one by one
for item in filtered_items:
send_api_request(
client=api_client,
path="/v2/items/discontinue",
method="POST",
params={
"licenseNumber": license["licenseNumber"],
"submit": True
},
json_body={
"id": item["id"]
}
)
if __name__ == "__main__":
main()