Created
July 25, 2020 09:04
-
-
Save mathurs/0a4aa2bcbef36724866675fbcf441579 to your computer and use it in GitHub Desktop.
Example python script to export Data from Browsee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Browsee Data Export Script (https://browsee.io/) | |
# Copyright 2019-2029 Heroteck Solutions Pvt. Ltd. | |
# Licensed under Apache 2.0 License (https://www.apache.org/licenses/LICENSE-2.0) | |
# | |
# Example python script to export data from Browsee. | |
# | |
import requests | |
import json | |
url = "https://api.browsee.io/api/v1/export/sessions" | |
apiKey = '<Your Project API Key Here>' | |
secretKey = '<Your Project Secret Key Here>' | |
headers = { | |
'content-type': "application/json", | |
'cache-control': "no-cache", | |
} | |
def getPayload( fromIndex = 0 ): | |
"""Returns payload for a page of export""" | |
payload = { | |
"apiKey": apiKey, | |
"secretKey": secretKey, | |
"select": [ 'duration', 'tags', 'urls', 'userId' ], | |
"from": fromIndex | |
} | |
return payload; | |
def getData( fromIndex = 0 ): | |
"""This is a recursive function | |
to call Browsee's data export API""" | |
payload=json.dumps(getPayload(fromIndex)) | |
print(payload) | |
response = requests.request("POST", url, data=payload, headers=headers) | |
#print(response.text) | |
data = json.loads(response.text) | |
print(data) | |
print("Received ", len(data['exports']['data']), " sessions.") | |
total = data['exports']['total']; | |
to = data['exports']['to']; | |
if to == total: | |
# All results processed. | |
print("Processed: ", total, " sessions.") | |
else: | |
# Recursively get more data. | |
getData(fromIndex=to) | |
getData() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment