anelendata / PyPardotSF

PyPardotSF is yet another fork of PyPardot/PyPardot4. The main driver for the fork is to address Pardot's authentication change in Sprint 2021 to use Salesforce OAuth.
MIT License
4 stars 6 forks source link

visitoractivity bulk stuff #6

Open martingaleh opened 2 years ago

martingaleh commented 2 years ago

Hello.

I'm not great at github so I don't know if I'm reading this stuff right but somehow the visitoractivites handles bulk export. I coudn't get it to work, so intead I used the PardotAPI's get function to get the visitor activities after setting up the job. The issue with the get function for me is that it only handles json and the bulk export comes in csv, so I had to modify _check_response. Thus I made this, which seems to work. I'm sure there's a more professional version of this.

from pypardot.client import PardotAPI from pypardot.errors import PardotAPIError

""" Hello. I had to make this bs because the original pypardot doesn't have the ability to handle csv so I made my own item here. """ class KobePardotAPI(PardotAPI):

@staticmethod def _check_response(response): """ Checks the HTTP response to see if it contains JSON. If it does, checks the JSON for error codes and messages. Raises PardotAPIError if an error was found. If no error was found, returns the JSON. If JSON was not found, returns the response status code. """ if response.headers.get('content-type') == 'application/json': json = response.json() error = json.get('err') if error: raise PardotAPIError(json_response=json) return json elif response.headers.get('content-type') == 'text/csv; charset=utf-8': return response.text else: return response