Created
May 30, 2018 16:18
-
-
Save michellemho/4019078379dd8acbd136ad569755d52f to your computer and use it in GitHub Desktop.
How to Transfer Tables
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 110, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"table_names = [\n", | |
" \"adjacent_m_c\",\n", | |
" \"allplutonew_r_3000\", \n", | |
" \"bldg_permits_15_16_cd\", \n", | |
" \"block_groups_2015_5year_pop\", \n", | |
" \"facilities\", \n", | |
" \"historic_districts\", \n", | |
" \"individual_landmarks\", \n", | |
" \"nycc\", \n", | |
" \"nycmih_20171121\", \n", | |
" \"nyctransitzones_201601\", \n", | |
" \"subway_entrances_may2016\", \n", | |
" \"table_83x8_shf7\", \n", | |
" \"table_83x8_shf7_3\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 112, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for i in table_names:\n", | |
" payload = {'url':\n", | |
" \"https://cartourbandemo.carto.com/api/v2/sql?&q=SELECT+*+FROM+{table_name}\"\\\n", | |
" \"&api_key=xxxx&format=GeoJSON\".format(table_name=i)}\n", | |
" resp = requests.post('https://nyc-real-estate.carto.com/api/v1/imports',\n", | |
" params={'api_key':'xxxxx'},\n", | |
" data=payload)\n", | |
" resp = requests.post('https://nyc-real-estate.carto.com/api/v2/sql?'\\\n", | |
" 'q=ALTER TABLE cartodb_query RENAME to {table_name}'.format(table_name=i),\n", | |
" params={'api_key':'xxxxx'})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment