Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- def send_graphql_query(query, variables=None):
- headers = {
- 'accept': '*/*',
- 'accept-language': 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',
- 'content-type': 'application/json',
- 'origin': 'https://sydneytools.com.au',
- 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',
- }
- json_data = {
- 'query': query,
- 'variables': variables or {},
- }
- response = requests.post('https://sydneytools.com.au/graphql', headers=headers, json=json_data)
- return response.json()
- # Updated query for product catalogue
- query = '''
- query routes_Catalogue_Query(
- $categoryUrlSlug: String!
- $subcategoryUrlSlug: String
- $subcategoryUrlSlug2: String
- $brandUrlSlug: String
- $count: Int!
- $cursor: String
- $filters: String
- $orderBy: OrderBy
- $page: Int
- $priorityPage: Boolean = false
- ) {
- viewer {
- ...Catalogue_viewer_3JTFNo
- id
- }
- }
- fragment Catalogue_viewer_3JTFNo on Customer {
- ...List_viewer
- ...CmsBanner_viewer
- ...PriorityPage_viewer @include(if: $priorityPage)
- configs
- categories(first: 1, urlSlug: $categoryUrlSlug) {
- edges {
- node {
- faqs(first: 99) {
- edges {
- node {
- id
- question
- answer
- }
- }
- }
- id
- name
- urlSlug
- description
- description2
- metaTitle
- metaDescription
- previewDescription
- jsonLd
- featuredBrands(first: 999) {
- edges {
- node {
- id
- name
- imageUrl
- urlSlug
- }
- }
- }
- catalogues(first: $count, orderBy: $orderBy, after: $cursor, filters: $filters, brandUrlSlug: $brandUrlSlug, subcategoryUrlSlug: $subcategoryUrlSlug, subcategoryUrlSlug2: $subcategoryUrlSlug2, page: $page) {
- totalCount
- subcategory {
- urlSlug
- name
- canonicalUrl
- metaTitle
- metaDescription
- description
- description2
- faqs(first: 99) {
- edges {
- node {
- id
- question
- answer
- }
- }
- }
- id
- }
- brand {
- urlSlug
- metaTitle
- description
- description2
- name
- id
- }
- facets {
- __typename
- __isFacetType: __typename
- ... on Facet {
- key
- name
- position
- buckets {
- key
- docCount
- imageUrl
- }
- }
- ... on FacetStats {
- key
- name
- position
- buckets {
- key
- docCount
- to
- from
- }
- max
- min
- }
- }
- edges {
- node {
- __typename
- ... on Subcategory {
- id
- imageUrl
- imageMode
- link
- displayMode
- name
- position
- urlSlug
- docCount
- metaTitle
- metaDescription
- }
- ... on Product {
- id
- name
- adjacentBanners(first: 99) {
- edges {
- node {
- id
- name
- placement
- imageUrl
- link
- }
- }
- }
- ...ProductCard_product
- }
- ... on Node {
- __isNode: __typename
- id
- }
- }
- cursor
- }
- pageInfo {
- endCursor
- hasNextPage
- }
- }
- }
- }
- }
- }
- fragment CmsBanner_viewer on Customer {
- cmsBanners(first: 999) {
- edges {
- node {
- id
- title
- link
- urlPaths
- categoryBig
- categorySmall
- }
- }
- }
- }
- fragment List_viewer on Customer {
- id
- ...ProductCard_viewer
- }
- fragment PriorityPage_viewer on Customer {
- id
- email
- faqs(first: 99, filterBy: [{field: "name", filter: "[PRIORITY-SHIPPING]", filterType: "text", type: "contains"}]) {
- edges {
- node {
- id
- question
- answer
- }
- }
- }
- }
- fragment ProductCard_product on Product {
- id
- alerts
- name
- type
- configurables(first: 99) {
- edges {
- node {
- id
- type
- discountCode
- name
- model
- secondModel
- sku
- regularPrice
- price
- priceMatch
- sellable
- nonStock
- }
- }
- }
- model
- secondModel
- regularPrice
- price
- priceDrop
- sku
- urlSlug
- freeShipping
- priorityShipping {
- getByDate
- }
- globalFreeShipping
- preorderDate
- backInStockDate
- nonStock
- onlineOnly
- callForPrice
- inStoreOnly
- sellable
- clearance
- discountCode
- brand {
- id
- name
- }
- loyaltyPoints {
- accruing
- dollars
- }
- labels(first: 999) {
- edges {
- node {
- id
- imageUrl
- placement
- type
- }
- }
- }
- mainImage {
- id
- thumbnail
- }
- }
- fragment ProductCard_viewer on Customer {
- id
- freeShippingAmount
- }
- '''
- # Example usage with variables
- variables = {
- "categoryUrlSlug": "power-tools",
- "count": 20,
- "page": 1,
- "priorityPage": False
- }
- result = send_graphql_query(query, variables)
- # Function to print subcategory information
- def print_subcategory_info(subcategory):
- print(f"Subcategory: {subcategory['name']}")
- print(f"Image URL: {subcategory['imageUrl']}")
- print(f"Product Count: {subcategory['docCount']}")
- print("-" * 40)
- # Parse and print the results
- if 'data' in result and 'viewer' in result['data']:
- viewer = result['data']['viewer']
- if 'categories' in viewer and 'edges' in viewer['categories']:
- for category_edge in viewer['categories']['edges']:
- category = category_edge['node']
- if 'catalogues' in category and 'edges' in category['catalogues']:
- for subcategory_edge in category['catalogues']['edges']:
- subcategory = subcategory_edge['node']
- if subcategory['__typename'] == 'Subcategory':
- print_subcategory_info(subcategory)
- else:
- print("No category or subcategory information found.")
- else:
- print("Unexpected response structure.")
Advertisement
Add Comment
Please, Sign In to add comment