Back to use cases

    Use case / Marketers / Python 3 / Published

    Best Time to Post: Check Your Niche on TikTok, Instagram and Facebook

    Posting Time Check is a small Python script that answers "what is the best time to post in my niche" with data from your own peers. Give it your account plus 10 to 15 peer accounts and it scores their recent public posts on TikTok, Instagram and Facebook by weekday and time of day.

    The problem

    Generic "best time to post" charts mix every industry together. What works for a fashion brand may not work for a crypto news account. Comparing peers by hand is hard because big accounts drown out small ones.

    What the app does

    • Reads handles.json with your account and peers per platform.
    • Pulls recent public posts per account and platform.
    • Scores each post against its own account's median engagement, so big and small accounts count equally.
    • Groups scores by weekday and 4-hour block in the time zone you pick.
    • Writes a heatmap and tables of the best and worst slots.

    How it works

    1. Posts. GET /desearch/tiktok/profile/{username}/posts, GET /desearch/instagram/profile/{username}/posts and GET /desearch/facebook/profile/{profile_id}/posts.
    2. Engagement. TikTok likes + comments + shares, Instagram likes + comments, Facebook reactions + comments.
    3. Score = engagement / median engagement of that account. 1.0 is a normal post.
    4. Rank slots with 3 or more posts.

    The code

    import os, requests
    
    API = "https://api.desearch.ai"
    headers = {"Authorization": os.environ["DESEARCH_API_KEY"]}
    
    r = requests.get(f"{API}/desearch/instagram/profile/coindesk/posts",
                     headers=headers, params={"count": 30}, timeout=60)
    posts = r.json()
    print(len(posts), "posts, cost $", r.headers.get("X-Desearch-Cost-Usd"))
    

    The folder has posting_time_check.py, an example handles.json and the sample run in output/.

    Example output

    The sample uses a crypto news brand as the main account and 12 public crypto news, research and exchange brand accounts as peers. That run made 49 calls and scored 316 posts. Output is a weekday by 4-hour heatmap per platform plus a table of the strongest and weakest slots.

    Run it yourself

    git clone https://github.com/Desearch-ai/desearch-py-examples && cd desearch-py-examples/posting-time-check
    pip install -r requirements.txt
    export DESEARCH_API_KEY=...   # from console.desearch.ai
    python posting_time_check.py handles.json
    

    Useful flags: --pages (more posts per account), --tz (time zone for the slots), --platforms tiktok,instagram, --max-age-days (default 90), --from-raw FILE (offline, no cost).

    What it costs

    Each post returned cost $0.00207. Billing is per item returned, and empty results cost nothing. The sample run was 49 calls, 316 posts and $0.654, from the X-Desearch-Cost-Usd headers. See pricing.

    Ideas to extend it

    • Re-run each quarter as your audience changes.
    • Add your own analytics to compare with the peer view.
    • Schedule posts into the best slots.

    Build your own example.

    Give your agents access to web and social search. Get an API key to start building, or talk to us about your integration.

    Read docs