-
-
Save petehartnett/c65b9df479ddb2fd773c87f450394cc7 to your computer and use it in GitHub Desktop.
download a tulip table to CSV
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
from pprint import pprint | |
import tulip_api,csv | |
TABLE_ID = 'PDfAmYGTgCzXJWojk' | |
CREDENTIALS = 'YXBpa2V5LjJfdXh6W.....5maTZPX1I3dFhIaUhuVi1qV1B1QXpWdlI0YmVuNmlXag==' | |
CSV_FILE = 'mycsvfile.csv' | |
api = tulip_api.TulipAPI('petehartnett.tulip.co',auth=CREDENTIALS) | |
wi_table = tulip_api.TulipTable(api,TABLE_ID) | |
records = wi_table.get_records(limit=1) | |
cnt = 0 | |
with open(CSV_FILE, 'w') as f: # You will need 'wb' mode in Python 2.x | |
w = csv.DictWriter(f, records[0].keys()) | |
w.writeheader() | |
for row in wi_table.stream_records(): | |
cnt +=1 | |
if cnt%1000 == 0: | |
print("----Saved 1000 rows----") | |
elif cnt%100 == 0: | |
print("Saved 100 records") | |
w.writerow(row) |
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
community-tulip-api | |
pprint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment