|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "DATA = {\n", |
| 10 | + " 'client_id':'',\n", |
| 11 | + " 'client_secret':''\n", |
| 12 | + "}" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": null, |
| 18 | + "metadata": {}, |
| 19 | + "outputs": [], |
| 20 | + "source": [ |
| 21 | + "# Login\n", |
| 22 | + "import requests \n", |
| 23 | + "\n", |
| 24 | + "response = requests.post('http://localhost:19999/login',data=DATA)\n", |
| 25 | + "\n", |
| 26 | + "access_token = response.json()['access_token']\n", |
| 27 | + "headers= {\n", |
| 28 | + " 'Authorization': 'token ' + access_token,\n", |
| 29 | + " 'x-looker-appid': 'marketplace_extension_hackathon::hackathon'\n", |
| 30 | + "}\n", |
| 31 | + "response = requests.get(\n", |
| 32 | + " 'http://localhost:19999/api/4.0/artifact/namespaces',\n", |
| 33 | + " headers=headers)\n", |
| 34 | + "\n", |
| 35 | + "print(response.status_code)" |
| 36 | + ] |
| 37 | + }, |
| 38 | + { |
| 39 | + "cell_type": "code", |
| 40 | + "execution_count": null, |
| 41 | + "metadata": {}, |
| 42 | + "outputs": [], |
| 43 | + "source": [ |
| 44 | + "import json\n", |
| 45 | + "TABLE_NAME = 'User'\n", |
| 46 | + "\n", |
| 47 | + "response = requests.get(\n", |
| 48 | + " 'http://localhost:19999/api/4.0/artifact/hackathon/search',\n", |
| 49 | + " data={'key': TABLE_NAME + '%'},\n", |
| 50 | + " headers=headers)\n", |
| 51 | + "\n", |
| 52 | + "print(response.json())" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "code", |
| 57 | + "execution_count": null, |
| 58 | + "metadata": {}, |
| 59 | + "outputs": [], |
| 60 | + "source": [ |
| 61 | + "# Migrate all data \n", |
| 62 | + "# Download each google sheet as csv\n", |
| 63 | + "# Expects directory/naming to be: csv/hackathons.csv\n", |
| 64 | + "import json\n", |
| 65 | + "import csv\n", |
| 66 | + "\n", |
| 67 | + "def toValues(path):\n", |
| 68 | + " with open(path, newline='') as csvfile:\n", |
| 69 | + " reader = csv.reader(x.replace('\\0', '') for x in csvfile)\n", |
| 70 | + " header = next(reader)\n", |
| 71 | + " values = []\n", |
| 72 | + " for row in reader:\n", |
| 73 | + " value = {}\n", |
| 74 | + " for index, v in enumerate(row):\n", |
| 75 | + " value[header[index]] = v\n", |
| 76 | + " values.append(value)\n", |
| 77 | + " return values\n", |
| 78 | + " \n", |
| 79 | + "def toArtifact(key, value):\n", |
| 80 | + " artifact = {}\n", |
| 81 | + " artifact['key'] = key\n", |
| 82 | + " artifact['content_type'] = 'application/json'\n", |
| 83 | + " artifact['value'] = json.dumps(value)\n", |
| 84 | + " return artifact\n", |
| 85 | + " \n", |
| 86 | + "artifacts = []\n", |
| 87 | + "\n", |
| 88 | + "for v in toValues('csv/hackathons.csv'):\n", |
| 89 | + " key = 'Hackathon:' + v['_id']\n", |
| 90 | + " del v['_id'] \n", |
| 91 | + " artifacts.append(toArtifact(key, v))\n", |
| 92 | + "\n", |
| 93 | + "for v in toValues('csv/judgings.csv'):\n", |
| 94 | + " key = 'Judging:' + v['_id']\n", |
| 95 | + " del v['_id'] \n", |
| 96 | + " v['user_id'] = 'User:' + v['user_id']\n", |
| 97 | + " v['project_id'] = 'Project:' + v['project_id']\n", |
| 98 | + " artifacts.append(toArtifact(key, v))\n", |
| 99 | + "\n", |
| 100 | + "for v in toValues('csv/projects.csv'):\n", |
| 101 | + " key = 'Project:' + v['_id']\n", |
| 102 | + " del v['_id']\n", |
| 103 | + " v['_user_id'] = 'User:' + v['_user_id']\n", |
| 104 | + " v['_hackathon_id'] = 'Hackathon:' + v['_hackathon_id']\n", |
| 105 | + " v['technologies'] = ['Technology:' + x for x in v['technologies'].split(',')]\n", |
| 106 | + " artifacts.append(toArtifact(key, v))\n", |
| 107 | + "\n", |
| 108 | + "for v in toValues('csv/registrations.csv'):\n", |
| 109 | + " key = 'Registration:' + v['_id']\n", |
| 110 | + " del v['_id'] \n", |
| 111 | + " v['_user_id'] = 'User:' + v['_user_id']\n", |
| 112 | + " v['hackathon_id'] = 'Hackathon:' + v['hackathon_id']\n", |
| 113 | + " artifacts.append(toArtifact(key, v))\n", |
| 114 | + "\n", |
| 115 | + "for v in toValues('csv/team_members.csv'):\n", |
| 116 | + " key = 'TeamMember:' + v['_id']\n", |
| 117 | + " del v['_id'] \n", |
| 118 | + " v['user_id'] = 'User:' + v['user_id']\n", |
| 119 | + " v['project_id'] = 'Project:' + v['project_id']\n", |
| 120 | + " artifacts.append(toArtifact(key, v))\n", |
| 121 | + "\n", |
| 122 | + "for v in toValues('csv/technologies.csv'):\n", |
| 123 | + " key = 'Technology:' + v['_id']\n", |
| 124 | + " del v['_id'] \n", |
| 125 | + " artifacts.append(toArtifact(key, v))\n", |
| 126 | + "\n", |
| 127 | + "for v in toValues('csv/users.csv'):\n", |
| 128 | + " key = 'User:' + v['_id']\n", |
| 129 | + " v['looker_id'] = '' + v['_id']\n", |
| 130 | + " del v['_id'] \n", |
| 131 | + " artifacts.append(toArtifact(key, v))\n", |
| 132 | + "\n", |
| 133 | + "response = requests.put('http://localhost:19999/api/4.0/artifacts/hackathon', headers=headers, json=artifacts) \n", |
| 134 | + "\n", |
| 135 | + "print(response.status_code)\n" |
| 136 | + ] |
| 137 | + }, |
| 138 | + { |
| 139 | + "cell_type": "code", |
| 140 | + "execution_count": null, |
| 141 | + "metadata": {}, |
| 142 | + "outputs": [], |
| 143 | + "source": [ |
| 144 | + "# TO PURGE ALL TABLES. BE CAREFUL\n", |
| 145 | + "response = requests.delete('http://localhost:19999/api/4.0/artifact/Hackathon/purge',headers=headers)\n", |
| 146 | + "print(response.status_code)\n", |
| 147 | + "\n", |
| 148 | + "response = requests.delete('http://localhost:19999/api/4.0/artifact/Judging/purge',headers=headers)\n", |
| 149 | + "print(response.status_code)\n", |
| 150 | + "\n", |
| 151 | + "response = requests.delete('http://localhost:19999/api/4.0/artifact/Project/purge',headers=headers)\n", |
| 152 | + "print(response.status_code)\n", |
| 153 | + "\n", |
| 154 | + "response = requests.delete('http://localhost:19999/api/4.0/artifact/Registration/purge',headers=headers)\n", |
| 155 | + "print(response.status_code)\n", |
| 156 | + "\n", |
| 157 | + "response = requests.delete('http://localhost:19999/api/4.0/artifact/TeamMember/purge',headers=headers)\n", |
| 158 | + "print(response.status_code)\n", |
| 159 | + "\n", |
| 160 | + "response = requests.delete('http://localhost:19999/api/4.0/artifact/Technology/purge',headers=headers)\n", |
| 161 | + "print(response.status_code)\n", |
| 162 | + "\n", |
| 163 | + "response = requests.delete('http://localhost:19999/api/4.0/artifact/User/purge',headers=headers)\n", |
| 164 | + "print(response.status_code)\n" |
| 165 | + ] |
| 166 | + }, |
| 167 | + { |
| 168 | + "cell_type": "code", |
| 169 | + "execution_count": null, |
| 170 | + "metadata": {}, |
| 171 | + "outputs": [], |
| 172 | + "source": [] |
| 173 | + } |
| 174 | + ], |
| 175 | + "metadata": { |
| 176 | + "kernelspec": { |
| 177 | + "display_name": "Python 3.10.7 64-bit", |
| 178 | + "language": "python", |
| 179 | + "name": "python3" |
| 180 | + }, |
| 181 | + "language_info": { |
| 182 | + "codemirror_mode": { |
| 183 | + "name": "ipython", |
| 184 | + "version": 3 |
| 185 | + }, |
| 186 | + "file_extension": ".py", |
| 187 | + "mimetype": "text/x-python", |
| 188 | + "name": "python", |
| 189 | + "nbconvert_exporter": "python", |
| 190 | + "pygments_lexer": "ipython3", |
| 191 | + "version": "3.10.8" |
| 192 | + }, |
| 193 | + "orig_nbformat": 4, |
| 194 | + "vscode": { |
| 195 | + "interpreter": { |
| 196 | + "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" |
| 197 | + } |
| 198 | + } |
| 199 | + }, |
| 200 | + "nbformat": 4, |
| 201 | + "nbformat_minor": 2 |
| 202 | +} |
0 commit comments