Skip to content

Commit

Permalink
chore: episode 22 end
Browse files Browse the repository at this point in the history
  • Loading branch information
NagariaHussain committed Oct 21, 2023
1 parent 032ca0f commit 8337df0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions printrov_merch_store/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
# Scheduled Tasks
# ---------------

scheduler_events = {
"hourly": [
"printrov_merch_store.tasks.sync_products_from_printrove"
]
}

# scheduler_events = {
# "all": [
# "printrov_merch_store.tasks.all"
Expand Down
38 changes: 38 additions & 0 deletions printrov_merch_store/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import frappe

from frappe.integrations.utils import make_get_request, make_post_request


BASE_URL = "https://api.printrove.com/"


def sync_products_from_printrove():
access_token = get_printrove_access_token()
headers = {"Authorization": f"Bearer {access_token}"}
products_route = "api/external/products"
all_products = make_get_request(f"{BASE_URL}{products_route}", headers=headers)
all_products = all_products["products"]

for product in all_products:
doc = frappe.get_doc({
"doctype": "Store Product",
"name": product["name"],
"printrove_id": product["id"],
"front_mockup": product["mockup"]["front_mockup"],
"back_mockup": product["mockup"]["back_mockup"]
}).insert(ignore_permissions=True)




def get_printrove_access_token():
printrove_settings = frappe.get_single("Printrove Settings")
auth_route = "api/external/token"
response = make_post_request(
f"{BASE_URL}{auth_route}",
data={
"email": printrove_settings.email,
"password": printrove_settings.get_password("password"),
},
)
return response["access_token"]

0 comments on commit 8337df0

Please sign in to comment.