Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Sakat's CoC Script - Download your clan data and CWL stats

  1. #11
    I would recommend not to use cocapi but instead to try our own and simpliest possible API implementation, for example I've made it after many tries by this code (indentation is not good in the quote of this forum, function has to be indented, of course) :
    # encoding: utf-8

    import requests
    import urllib
    import os
    import json
    from pandas.io.json import json_normalize
    import pandas as pd

    base_key = 'v1'
    base_url = 'https://api.clashofclans.com/{base_key}/'.format(base_key=base_key)
    from urllib.parse import quote

    def cocget(token, url, params=None):
    global headers
    headers = {'authorization': 'Bearer %s' % token, 'Accept': 'application/json'}
    result = requests.get(base_url + url, headers=headers, params=params)
    if result.status_code != 200:
    return [result.status_code, result.json()]
    return json.loads(result.text)

    token = ...
    sTagClan = ...

    data = cocget(token,'clans/{sTagClan}'.format(sTagClan=quote(sTagClan)))
    #Pandas finally thanx to json_normalize()
    df=json_normalize(data)
    Last edited by omanoe; April 13th, 2019 at 12:59 PM.

  2. #12
    Quote Originally Posted by omanoe View Post
    I would recommend not to use cocapi but instead to try our own and simpliest possible API implementation, for example I've made it after many tries by this code (indentation is not good in the quote of this forum, function has to be indented, of course) :
    Hi
    I'm the idiot who wrote cocapi. I have used json.dumps in the api as I intended to use this as a part of my other webapps so strings made more sense for me. Also yes if you want to fix the quotes to a python object just simply pass the response from the call with a dump. That should convert that to a dict.
    Also just to clear it out my work is not an api but a wrapper on top of the official APIs. Sort of like a python sample and plus you don't have to write the entire request for multiple end points but just simply call them. There's more work to be done and I'd love PRs .
    Last edited by tonybenoy; 3 Weeks Ago at 08:14 AM. Reason: Indented ->Intended

  3. #13
    Quote Originally Posted by tonybenoy View Post
    Hi
    I'm the idiot who wrote cocapi. I have used json.dumps in the api as I indented to use this as a part of my other webapps so strings made more sense for me. Also yes if you want to fix the quotes to a python object just simply pass the response from the call with a dump. That should convert that to a dict.
    Also just to clear it out my work is not an api but a wrapper on top of the official APIs. Sort of like a python sample and plus you don't have to write the entire request for multiple end points but just simply call them. There's more work to be done and I'd love PRs .
    Thanks for your idiot work It really helped me a lot to do my script. I'm not sure I would have been able to do it without it!
    Tired of Clan Games Leechers? Follow your clan member activity with CGLeech !
    ===>More info on the official thread <===



  4. #14
    I'm glad it's of use to you 😉

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •