How to extract "Weekly Pattern" using API through Python

There is a problem when I am trying to extract “Weekly Pattern” using Places API through Python. The error shows “exceptions must derive from BaseException”. I am wondering which step I missed. Below is my sample code:


import safegraphql.client as sgql

sgql_client = sgql.HTTP_Client(apikey = ‘xxxxxxxxxx’)
sgql_client.lookup(product = ‘weekly_patterns’, placekeys = ‘xxx’, date = ‘xxx’, columns = ‘*’)


Hey @zhr19002! Looping in @Victor_Chen into this conversation who can help!

can you try specifying the specific columns to see if that works. this may be due to * include all columns including columns that are not available to weekly_patterns (e.g. brands)

from safegraphql import client

sgql_client = client.HTTP_Client("Rnccqb52cd3ny1Ke0D3RQasD86JjctWg")

pk = 'zzw-222@8fy-fjg-b8v' # Disney World
core = sgql_client.lookup(product = 'weekly_patterns', placekeys = pk, date="2020-09-01", columns = ['placekey', 'location_name', 'raw_visit_counts'])

core

Hi @vchen , thank you for your response. I tried your code, and replaced with my own API key, the problem still exists.

hm, wondering if it is an issue with then library version. do you still get the issue if you pin the library:
pip install safegraphQL==0.4.3

if that still doesn’t work can you try just running the graphql query directly?

import os
import requests
import json

headers = {
    'Content-Type': 'application/json',
    'apikey': os.environ['SGAPI']
}

query = """
query($date: DateTime){
    search( filter: {
        address: {
            city: "San Francisco"
            region: "CA"
        }
    }) {
        placekey
        safegraph_weekly_patterns (date: $date){
          location_name
          raw_visit_counts
        }
    }
}
"""

req = requests.post(
    'https://api.safegraph.com/v1/graphql',
    json={
        'query': query,
        'variables': {'date': '2020-09-01'}
    },
    headers=headers
)

r_json = req.json()
print (json.dumps(r_json, indent=4, sort_keys=True))