{ "cells": [ { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Restaurants example\n", "===================\n", "\n", "This example takes you through some of the basics of PyOS and introduces you to some of the commands, syntax and \n", "concepts. So let's dive in, and enjoy! \n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "pycharm": { "is_executing": false } }, "outputs": [ { "name": "stdout", "text": [ "Welcome to\n", "\n", " ____ ____ \n", " / __ \\/ __ /\n", " ____ __ __/ / / / /_ \n", " / __ \\/ / / / / / /\\__ \\ \n", " / /_/ / /_/ / /_/ /___/ / \n", " / .___/\\__, /\\____//____/ \n", "/_/ /____/ v0.5.0 \n", "\n" ], "output_type": "stream" } ], "source": [ "from pyos.pyos import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/plain": "Path('/martin/')" }, "metadata": {}, "output_type": "execute_result", "execution_count": 2 } ], "source": [ "pwd()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/plain": "" }, "metadata": {}, "output_type": "execute_result", "execution_count": 3 } ], "source": [ "ls()" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Ok, so we're in the `martin` folder but there's nothing in it. Let's download some data and store it in dictionaries." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [], "source": [ "import mincepy\n", "import urllib.request\n", "import json\n", "\n", "ids = []\n", "with urllib.request.urlopen('https://raw.githubusercontent.com/ozlerhakan/mongodb-json-files/master/datasets/restaurant.json') as url: \n", " for line, _ in zip(url, range(399)): \n", " data = json.loads(line.decode()) \n", " data.pop('_id') \n", " ids.append(mincepy.Dict(data).save())" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "pycharm": { "is_executing": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/plain": "5e8e20ed1dbc98e7a84d9386 5e8e20ed1dbc98e7a84d9490 5e8e20ed1dbc98e7a84d959a\n5e8e20ed1dbc98e7a84d9388 5e8e20ed1dbc98e7a84d9492 5e8e20ed1dbc98e7a84d959c\n5e8e20ed1dbc98e7a84d938a 5e8e20ed1dbc98e7a84d9494 5e8e20ed1dbc98e7a84d959e\n5e8e20ed1dbc98e7a84d938c 5e8e20ed1dbc98e7a84d9496 5e8e20ed1dbc98e7a84d95a0\n5e8e20ed1dbc98e7a84d938e 5e8e20ed1dbc98e7a84d9498 5e8e20ed1dbc98e7a84d95a2\n5e8e20ed1dbc98e7a84d9390 5e8e20ed1dbc98e7a84d949a 5e8e20ed1dbc98e7a84d95a4\n5e8e20ed1dbc98e7a84d9392 5e8e20ed1dbc98e7a84d949c 5e8e20ed1dbc98e7a84d95a6\n5e8e20ed1dbc98e7a84d9394 5e8e20ed1dbc98e7a84d949e 5e8e20ed1dbc98e7a84d95a8\n5e8e20ed1dbc98e7a84d9396 5e8e20ed1dbc98e7a84d94a0 5e8e20ed1dbc98e7a84d95aa\n5e8e20ed1dbc98e7a84d9398 5e8e20ed1dbc98e7a84d94a2 5e8e20ed1dbc98e7a84d95ac\n5e8e20ed1dbc98e7a84d939a 5e8e20ed1dbc98e7a84d94a4 5e8e20ed1dbc98e7a84d95ae\n5e8e20ed1dbc98e7a84d939c 5e8e20ed1dbc98e7a84d94a6 5e8e20ed1dbc98e7a84d95b0\n5e8e20ed1dbc98e7a84d939e 5e8e20ed1dbc98e7a84d94a8 5e8e20ed1dbc98e7a84d95b2\n5e8e20ed1dbc98e7a84d93a0 5e8e20ed1dbc98e7a84d94aa 5e8e20ed1dbc98e7a84d95b4\n5e8e20ed1dbc98e7a84d93a2 5e8e20ed1dbc98e7a84d94ac 5e8e20ed1dbc98e7a84d95b6\n5e8e20ed1dbc98e7a84d93a4 5e8e20ed1dbc98e7a84d94ae 5e8e20ed1dbc98e7a84d95b8\n5e8e20ed1dbc98e7a84d93a6 5e8e20ed1dbc98e7a84d94b0 5e8e20ed1dbc98e7a84d95ba\n5e8e20ed1dbc98e7a84d93a8 5e8e20ed1dbc98e7a84d94b2 5e8e20ed1dbc98e7a84d95bc\n5e8e20ed1dbc98e7a84d93aa 5e8e20ed1dbc98e7a84d94b4 5e8e20ed1dbc98e7a84d95be\n5e8e20ed1dbc98e7a84d93ac 5e8e20ed1dbc98e7a84d94b6 5e8e20ed1dbc98e7a84d95c0\n5e8e20ed1dbc98e7a84d93ae 5e8e20ed1dbc98e7a84d94b8 5e8e20ed1dbc98e7a84d95c2\n5e8e20ed1dbc98e7a84d93b0 5e8e20ed1dbc98e7a84d94ba 5e8e20ed1dbc98e7a84d95c4\n5e8e20ed1dbc98e7a84d93b2 5e8e20ed1dbc98e7a84d94bc 5e8e20ed1dbc98e7a84d95c6\n5e8e20ed1dbc98e7a84d93b4 5e8e20ed1dbc98e7a84d94be 5e8e20ed1dbc98e7a84d95c8\n5e8e20ed1dbc98e7a84d93b6 5e8e20ed1dbc98e7a84d94c0 5e8e20ed1dbc98e7a84d95ca\n5e8e20ed1dbc98e7a84d93b8 5e8e20ed1dbc98e7a84d94c2 5e8e20ed1dbc98e7a84d95cc\n5e8e20ed1dbc98e7a84d93ba 5e8e20ed1dbc98e7a84d94c4 5e8e20ed1dbc98e7a84d95ce\n5e8e20ed1dbc98e7a84d93bc 5e8e20ed1dbc98e7a84d94c6 5e8e20ed1dbc98e7a84d95d0\n5e8e20ed1dbc98e7a84d93be 5e8e20ed1dbc98e7a84d94c8 5e8e20ed1dbc98e7a84d95d2\n5e8e20ed1dbc98e7a84d93c0 5e8e20ed1dbc98e7a84d94ca 5e8e20ed1dbc98e7a84d95d4\n5e8e20ed1dbc98e7a84d93c2 5e8e20ed1dbc98e7a84d94cc 5e8e20ed1dbc98e7a84d95d6\n5e8e20ed1dbc98e7a84d93c4 5e8e20ed1dbc98e7a84d94ce 5e8e20ed1dbc98e7a84d95d8\n5e8e20ed1dbc98e7a84d93c6 5e8e20ed1dbc98e7a84d94d0 5e8e20ed1dbc98e7a84d95da\n5e8e20ed1dbc98e7a84d93c8 5e8e20ed1dbc98e7a84d94d2 5e8e20ed1dbc98e7a84d95dc\n5e8e20ed1dbc98e7a84d93ca 5e8e20ed1dbc98e7a84d94d4 5e8e20ed1dbc98e7a84d95de\n5e8e20ed1dbc98e7a84d93cc 5e8e20ed1dbc98e7a84d94d6 5e8e20ed1dbc98e7a84d95e0\n5e8e20ed1dbc98e7a84d93ce 5e8e20ed1dbc98e7a84d94d8 5e8e20ed1dbc98e7a84d95e2\n5e8e20ed1dbc98e7a84d93d0 5e8e20ed1dbc98e7a84d94da 5e8e20ed1dbc98e7a84d95e4\n5e8e20ed1dbc98e7a84d93d2 5e8e20ed1dbc98e7a84d94dc 5e8e20ed1dbc98e7a84d95e6\n5e8e20ed1dbc98e7a84d93d4 5e8e20ed1dbc98e7a84d94de 5e8e20ed1dbc98e7a84d95e8\n5e8e20ed1dbc98e7a84d93d6 5e8e20ed1dbc98e7a84d94e0 5e8e20ed1dbc98e7a84d95ea\n5e8e20ed1dbc98e7a84d93d8 5e8e20ed1dbc98e7a84d94e2 5e8e20ed1dbc98e7a84d95ec\n5e8e20ed1dbc98e7a84d93da 5e8e20ed1dbc98e7a84d94e4 5e8e20ed1dbc98e7a84d95ee\n5e8e20ed1dbc98e7a84d93dc 5e8e20ed1dbc98e7a84d94e6 5e8e20ed1dbc98e7a84d95f0\n5e8e20ed1dbc98e7a84d93de 5e8e20ed1dbc98e7a84d94e8 5e8e20ed1dbc98e7a84d95f2\n5e8e20ed1dbc98e7a84d93e0 5e8e20ed1dbc98e7a84d94ea 5e8e20ed1dbc98e7a84d95f4\n5e8e20ed1dbc98e7a84d93e2 5e8e20ed1dbc98e7a84d94ec 5e8e20ed1dbc98e7a84d95f6\n5e8e20ed1dbc98e7a84d93e4 5e8e20ed1dbc98e7a84d94ee 5e8e20ed1dbc98e7a84d95f8\n5e8e20ed1dbc98e7a84d93e6 5e8e20ed1dbc98e7a84d94f0 5e8e20ed1dbc98e7a84d95fa\n5e8e20ed1dbc98e7a84d93e8 5e8e20ed1dbc98e7a84d94f2 5e8e20ed1dbc98e7a84d95fc\n5e8e20ed1dbc98e7a84d93ea 5e8e20ed1dbc98e7a84d94f4 5e8e20ed1dbc98e7a84d95fe\n5e8e20ed1dbc98e7a84d93ec 5e8e20ed1dbc98e7a84d94f6 5e8e20ed1dbc98e7a84d9600\n5e8e20ed1dbc98e7a84d93ee 5e8e20ed1dbc98e7a84d94f8 5e8e20ed1dbc98e7a84d9602\n5e8e20ed1dbc98e7a84d93f0 5e8e20ed1dbc98e7a84d94fa 5e8e20ed1dbc98e7a84d9604\n5e8e20ed1dbc98e7a84d93f2 5e8e20ed1dbc98e7a84d94fc 5e8e20ed1dbc98e7a84d9606\n5e8e20ed1dbc98e7a84d93f4 5e8e20ed1dbc98e7a84d94fe 5e8e20ed1dbc98e7a84d9608\n5e8e20ed1dbc98e7a84d93f6 5e8e20ed1dbc98e7a84d9500 5e8e20ed1dbc98e7a84d960a\n5e8e20ed1dbc98e7a84d93f8 5e8e20ed1dbc98e7a84d9502 5e8e20ed1dbc98e7a84d960c\n5e8e20ed1dbc98e7a84d93fa 5e8e20ed1dbc98e7a84d9504 5e8e20ed1dbc98e7a84d960e\n5e8e20ed1dbc98e7a84d93fc 5e8e20ed1dbc98e7a84d9506 5e8e20ed1dbc98e7a84d9610\n5e8e20ed1dbc98e7a84d93fe 5e8e20ed1dbc98e7a84d9508 5e8e20ed1dbc98e7a84d9612\n5e8e20ed1dbc98e7a84d9400 5e8e20ed1dbc98e7a84d950a 5e8e20ed1dbc98e7a84d9614\n5e8e20ed1dbc98e7a84d9402 5e8e20ed1dbc98e7a84d950c 5e8e20ed1dbc98e7a84d9616\n5e8e20ed1dbc98e7a84d9404 5e8e20ed1dbc98e7a84d950e 5e8e20ed1dbc98e7a84d9618\n5e8e20ed1dbc98e7a84d9406 5e8e20ed1dbc98e7a84d9510 5e8e20ed1dbc98e7a84d961a\n5e8e20ed1dbc98e7a84d9408 5e8e20ed1dbc98e7a84d9512 5e8e20ed1dbc98e7a84d961c\n5e8e20ed1dbc98e7a84d940a 5e8e20ed1dbc98e7a84d9514 5e8e20ed1dbc98e7a84d961e\n5e8e20ed1dbc98e7a84d940c 5e8e20ed1dbc98e7a84d9516 5e8e20ed1dbc98e7a84d9620\n5e8e20ed1dbc98e7a84d940e 5e8e20ed1dbc98e7a84d9518 5e8e20ed1dbc98e7a84d9622\n5e8e20ed1dbc98e7a84d9410 5e8e20ed1dbc98e7a84d951a 5e8e20ed1dbc98e7a84d9624\n5e8e20ed1dbc98e7a84d9412 5e8e20ed1dbc98e7a84d951c 5e8e20ed1dbc98e7a84d9626\n5e8e20ed1dbc98e7a84d9414 5e8e20ed1dbc98e7a84d951e 5e8e20ed1dbc98e7a84d9628\n5e8e20ed1dbc98e7a84d9416 5e8e20ed1dbc98e7a84d9520 5e8e20ed1dbc98e7a84d962a\n5e8e20ed1dbc98e7a84d9418 5e8e20ed1dbc98e7a84d9522 5e8e20ed1dbc98e7a84d962c\n5e8e20ed1dbc98e7a84d941a 5e8e20ed1dbc98e7a84d9524 5e8e20ed1dbc98e7a84d962e\n5e8e20ed1dbc98e7a84d941c 5e8e20ed1dbc98e7a84d9526 5e8e20ed1dbc98e7a84d9630\n5e8e20ed1dbc98e7a84d941e 5e8e20ed1dbc98e7a84d9528 5e8e20ed1dbc98e7a84d9632\n5e8e20ed1dbc98e7a84d9420 5e8e20ed1dbc98e7a84d952a 5e8e20ed1dbc98e7a84d9634\n5e8e20ed1dbc98e7a84d9422 5e8e20ed1dbc98e7a84d952c 5e8e20ed1dbc98e7a84d9636\n5e8e20ed1dbc98e7a84d9424 5e8e20ed1dbc98e7a84d952e 5e8e20ed1dbc98e7a84d9638\n5e8e20ed1dbc98e7a84d9426 5e8e20ed1dbc98e7a84d9530 5e8e20ed1dbc98e7a84d963a\n5e8e20ed1dbc98e7a84d9428 5e8e20ed1dbc98e7a84d9532 5e8e20ed1dbc98e7a84d963c\n5e8e20ed1dbc98e7a84d942a 5e8e20ed1dbc98e7a84d9534 5e8e20ed1dbc98e7a84d963e\n5e8e20ed1dbc98e7a84d942c 5e8e20ed1dbc98e7a84d9536 5e8e20ed1dbc98e7a84d9640\n5e8e20ed1dbc98e7a84d942e 5e8e20ed1dbc98e7a84d9538 5e8e20ed1dbc98e7a84d9642\n5e8e20ed1dbc98e7a84d9430 5e8e20ed1dbc98e7a84d953a 5e8e20ed1dbc98e7a84d9644\n5e8e20ed1dbc98e7a84d9432 5e8e20ed1dbc98e7a84d953c 5e8e20ed1dbc98e7a84d9646\n5e8e20ed1dbc98e7a84d9434 5e8e20ed1dbc98e7a84d953e 5e8e20ed1dbc98e7a84d9648\n5e8e20ed1dbc98e7a84d9436 5e8e20ed1dbc98e7a84d9540 5e8e20ed1dbc98e7a84d964a\n5e8e20ed1dbc98e7a84d9438 5e8e20ed1dbc98e7a84d9542 5e8e20ed1dbc98e7a84d964c\n5e8e20ed1dbc98e7a84d943a 5e8e20ed1dbc98e7a84d9544 5e8e20ed1dbc98e7a84d964e\n5e8e20ed1dbc98e7a84d943c 5e8e20ed1dbc98e7a84d9546 5e8e20ed1dbc98e7a84d9650\n5e8e20ed1dbc98e7a84d943e 5e8e20ed1dbc98e7a84d9548 5e8e20ed1dbc98e7a84d9652\n5e8e20ed1dbc98e7a84d9440 5e8e20ed1dbc98e7a84d954a 5e8e20ed1dbc98e7a84d9654\n5e8e20ed1dbc98e7a84d9442 5e8e20ed1dbc98e7a84d954c 5e8e20ed1dbc98e7a84d9656\n5e8e20ed1dbc98e7a84d9444 5e8e20ed1dbc98e7a84d954e 5e8e20ed1dbc98e7a84d9658\n5e8e20ed1dbc98e7a84d9446 5e8e20ed1dbc98e7a84d9550 5e8e20ed1dbc98e7a84d965a\n5e8e20ed1dbc98e7a84d9448 5e8e20ed1dbc98e7a84d9552 5e8e20ed1dbc98e7a84d965c\n5e8e20ed1dbc98e7a84d944a 5e8e20ed1dbc98e7a84d9554 5e8e20ed1dbc98e7a84d965e\n5e8e20ed1dbc98e7a84d944c 5e8e20ed1dbc98e7a84d9556 5e8e20ed1dbc98e7a84d9660\n5e8e20ed1dbc98e7a84d944e 5e8e20ed1dbc98e7a84d9558 5e8e20ed1dbc98e7a84d9662\n5e8e20ed1dbc98e7a84d9450 5e8e20ed1dbc98e7a84d955a 5e8e20ed1dbc98e7a84d9664\n5e8e20ed1dbc98e7a84d9452 5e8e20ed1dbc98e7a84d955c 5e8e20ed1dbc98e7a84d9666\n5e8e20ed1dbc98e7a84d9454 5e8e20ed1dbc98e7a84d955e 5e8e20ed1dbc98e7a84d9668\n5e8e20ed1dbc98e7a84d9456 5e8e20ed1dbc98e7a84d9560 5e8e20ed1dbc98e7a84d966a\n5e8e20ed1dbc98e7a84d9458 5e8e20ed1dbc98e7a84d9562 5e8e20ed1dbc98e7a84d966c\n5e8e20ed1dbc98e7a84d945a 5e8e20ed1dbc98e7a84d9564 5e8e20ed1dbc98e7a84d966e\n5e8e20ed1dbc98e7a84d945c 5e8e20ed1dbc98e7a84d9566 5e8e20ed1dbc98e7a84d9670\n5e8e20ed1dbc98e7a84d945e 5e8e20ed1dbc98e7a84d9568 5e8e20ed1dbc98e7a84d9672\n5e8e20ed1dbc98e7a84d9460 5e8e20ed1dbc98e7a84d956a 5e8e20ed1dbc98e7a84d9674\n5e8e20ed1dbc98e7a84d9462 5e8e20ed1dbc98e7a84d956c 5e8e20ed1dbc98e7a84d9676\n5e8e20ed1dbc98e7a84d9464 5e8e20ed1dbc98e7a84d956e 5e8e20ed1dbc98e7a84d9678\n5e8e20ed1dbc98e7a84d9466 5e8e20ed1dbc98e7a84d9570 5e8e20ed1dbc98e7a84d967a\n5e8e20ed1dbc98e7a84d9468 5e8e20ed1dbc98e7a84d9572 5e8e20ed1dbc98e7a84d967c\n5e8e20ed1dbc98e7a84d946a 5e8e20ed1dbc98e7a84d9574 5e8e20ed1dbc98e7a84d967e\n5e8e20ed1dbc98e7a84d946c 5e8e20ed1dbc98e7a84d9576 5e8e20ed1dbc98e7a84d9680\n5e8e20ed1dbc98e7a84d946e 5e8e20ed1dbc98e7a84d9578 5e8e20ed1dbc98e7a84d9682\n5e8e20ed1dbc98e7a84d9470 5e8e20ed1dbc98e7a84d957a 5e8e20ed1dbc98e7a84d9684\n5e8e20ed1dbc98e7a84d9472 5e8e20ed1dbc98e7a84d957c 5e8e20ed1dbc98e7a84d9686\n5e8e20ed1dbc98e7a84d9474 5e8e20ed1dbc98e7a84d957e 5e8e20ed1dbc98e7a84d9688\n5e8e20ed1dbc98e7a84d9476 5e8e20ed1dbc98e7a84d9580 5e8e20ed1dbc98e7a84d968a\n5e8e20ed1dbc98e7a84d9478 5e8e20ed1dbc98e7a84d9582 5e8e20ed1dbc98e7a84d968c\n5e8e20ed1dbc98e7a84d947a 5e8e20ed1dbc98e7a84d9584 5e8e20ed1dbc98e7a84d968e\n5e8e20ed1dbc98e7a84d947c 5e8e20ed1dbc98e7a84d9586 5e8e20ed1dbc98e7a84d9690\n5e8e20ed1dbc98e7a84d947e 5e8e20ed1dbc98e7a84d9588 5e8e20ed1dbc98e7a84d9692\n5e8e20ed1dbc98e7a84d9480 5e8e20ed1dbc98e7a84d958a 5e8e20ed1dbc98e7a84d9694\n5e8e20ed1dbc98e7a84d9482 5e8e20ed1dbc98e7a84d958c 5e8e20ed1dbc98e7a84d9696\n5e8e20ed1dbc98e7a84d9484 5e8e20ed1dbc98e7a84d958e 5e8e20ed1dbc98e7a84d9698\n5e8e20ed1dbc98e7a84d9486 5e8e20ed1dbc98e7a84d9590 5e8e20ed1dbc98e7a84d969a\n5e8e20ed1dbc98e7a84d9488 5e8e20ed1dbc98e7a84d9592 5e8e20ed1dbc98e7a84d969c\n5e8e20ed1dbc98e7a84d948a 5e8e20ed1dbc98e7a84d9594 5e8e20ed1dbc98e7a84d969e\n5e8e20ed1dbc98e7a84d948c 5e8e20ed1dbc98e7a84d9596 5e8e20ed1dbc98e7a84d96a0\n5e8e20ed1dbc98e7a84d948e 5e8e20ed1dbc98e7a84d9598 5e8e20ed1dbc98e7a84d96a2" }, "metadata": {}, "output_type": "execute_result", "execution_count": 5 } ], "source": [ "ls()" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "So what have we got? Let's ``cat`` a couple of our dictionaries to see:" ] }, { "cell_type": "code", "execution_count": 6, "outputs": [ { "data": { "text/plain": "┌──────────────┬─────────────────────────────────────────────────────────────┐\n│URL │http://www.just-eat.co.uk/restaurants-cn-chinese-cardiff/menu│\n│address │228 City Road │\n│address line 2│Cardiff │\n│name │.CN Chinese │\n│outcode │CF24 │\n│postcode │3JH │\n│rating │5 │\n│type_of_food │Chinese │\n└──────────────┴─────────────────────────────────────────────────────────────┘\n┌──────────────┬─────────────────────────────────────────────────────┐\n│URL │http://www.just-eat.co.uk/restaurants-atthai-ss9/menu│\n│address │376 Rayleigh Road │\n│address line 2│Essex │\n│name │@ Thai │\n│outcode │SS9 │\n│postcode │5PT │\n│rating │5.5 │\n│type_of_food │Thai │\n└──────────────┴─────────────────────────────────────────────────────┘" }, "metadata": {}, "output_type": "execute_result", "execution_count": 6 } ], "source": [ "cat(ids[0], ids[1])" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "Wait a minute. What's with all the boxes?\n", "\n", "Pretty, isn't it? That's just the default way PyOS prints your objects, you can see that they're really just dicts by\n", "using:" ] }, { "cell_type": "code", "source": [ "cat(ids[0], ids[1], representer=str)" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } }, "execution_count": 7, "outputs": [ { "data": { "text/plain": "{'URL': 'http://www.just-eat.co.uk/restaurants-cn-chinese-cardiff/menu', 'address': '228 City Road', 'address line 2': 'Cardiff', 'name': '.CN Chinese', 'outcode': 'CF24', 'postcode': '3JH', 'rating': 5, 'type_of_food': 'Chinese'}\n{'URL': 'http://www.just-eat.co.uk/restaurants-atthai-ss9/menu', 'address': '376 Rayleigh Road', 'address line 2': 'Essex', 'name': '@ Thai', 'outcode': 'SS9', 'postcode': '5PT', 'rating': 5.5, 'type_of_food': 'Thai'}" }, "metadata": {}, "output_type": "execute_result", "execution_count": 7 } ] }, { "cell_type": "markdown", "source": [ "Now let's give them meaningful names, converting spaces and forward slashes" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 8, "outputs": [ { "data": { "text/plain": ".CN_Chinese Aberdare_Charcoal_Grill \n@_Thai Aberdeen_Shanghai_Takeaway \n@_Thai_Restaurant Aberkenfig_Kebab_&_Pizza_House \n@Indian.com Abe's_Pizza \n007_Takeaway Abi_Restaurant \n042_Restaurant_&_Bar Abi_Ruchi \n1_2_3_Chinese Abida \n100_Degrees_Chinese_Restaurant Abidap_Connection \n100_Menu Abid's_Tandoori_Takeaway \n104_Turkish_BBQ Abington_Tandoori \n109_Ristorante Abi's_Kebab \n113_Fish_Bar Abo_Ali_-_Lebanese_Cuisine \n133_Takeaway Abra_Pizzas \n1498_The_Spice_Affair Abra-Kebab-Ra \n168_Chinese_&_Cantonese_Takeaway ABS_Fast_Food \n1A_Wok Abs_Fried_Chicken_&_Pizza \n1pizza1 Abshar_Indian_Cuisine \n1st_Choice_Pizza Abshar_Persian_Cuisine \n1st_Class_Pizza Absolute_Caribbean \n1st_Class_Pizza_&_Kebab_House Aby's_Indian_Experience \n2_4_1_Pizza Abyssinia_Ethiopian_Restaurant \n2_for_1_Pizza_Place Abz_BBQ_Kitchen \n2_Spice Ace_Of_Spice \n2_Treat_U Ace_Peri_Peri \n23rd_Street_Pizza Ace_Pizza \n241_Pizza ACE_Pizza_&_Kebab \n2-4-1_Pizza Ace_Plaice_Traditional_Fish_&_Chips \n280_Degrees_African_&_Nigerian_Restaurant Acha_Halal_Chinese_Cuisine \n3_Chef_Fish_Bar Ackee_Tree \n3_Chefs Ackie's \n3_In_1_Dunoon Acomb_Kebab_House \n3_in_1_Indian_&_Chipshop_Barrhead Acropolis \n3_In_1_Xtra Active_Cafe_Lounge \n321_Pizzas,_Kebabs_&_Burgers Acton_Charcoal_Grill \n328_Chinese_Online Ada_Restaurant \n333_Chinese_Takeaway Adaab_Balti \n333_Chinese_Takeaway1 Adams \n350_Wok Adams_&_Lily's \n4_in_1_Express Adams_Alsabti_Pizzeria_&_Grill_House \n4_in_Love Adams_Balti \n4500_Miles_From_Delhi Adam's_Balti_&_Pizza \n4_Seasons_Pizza_&_Grill Adam's_Cafe_-_Collection_Only \n4550_Miles_From_Delhi_-_Collection_Only Adam's_Grill \n5_In_1_Takeaway Adams_Chippy_&_Curry_House \n5_'N'_1 Adams_Diner \n5_Star_Chinese Adam's_Diner \n5_Star_Falafel_@_GH_Butchers Adam's_Fast_Food \n5_Star_Fish_Bar Adam's_Fish_&_Chips \n5_Star_Pizza Adams_Fish_&_Pizza_Bar \n555_Hot_Curry Adams_Fish_N_Pizza_Bar \n555_Pizza Adam's_Hot_&_Spicy \n555_Pizza_&_Kebab Adams_Ice_Cream_Parlour \n57_Orient_Takeaway Adams_Pizza \n62_Worksop_Fish_Bar Adam's_Pizza_&_Kebab \n64_Pizzeria Adams_Pizza_&_Kebabs \n7_&_One Adams_Pizza_Corner \n7_Oaks_Grill Adam's_Pizzeria \n7_Spices Adams_Pizzeria \n7_Spices_Takeaway Adams_Place \n7_STAR_Pizza Adam's_Spice \n7_Star_Spices Adams_Steak_&_Curry_House \n700_Degrees Adana_Pizza \n88_Chinese Adar_Restaurant \n88_Noodle_Bar Add_Spice \n888_Chinese_Takeaway Addlestone_Charcoal_Grill \n888_Triple_Eight Adeel_Tandoori \n9_Inch_CFC Adeels_Fast_Food \n9th_Avenue_Pizzeria Adeel_Balti_&_Pizza_Bar \n9th_Kitchen Adeels_Spice \nA_&_G_Kitchen Adelaide_Fish_Bar_-_Collection_Only \nA_&_T_Mundi_House Adel's_Pizza \nA_Cake_A_Shake Adil_Takeaway \nA_Fish_Called_Rhondda Adil's_Takeaway \nA_La_Pizza Adiva \nA_La_Turka Adlington_Mama_Mia \nA_M_Mians Adlington_Spice \nA_Matter_Of_Taste Admiral_Pizza \nA_One_Tandoori Admirals_Fish_&_Chips_&_Kebabs \nA_Passage_To_India Adnan_Southern_Fried_Chicken_Shop \nA_Sealand_Fish_Bar_-_Collection_Only Adnans_Indian_Restaurant_&_Takeaway \nA_Star_Chippy Adolfo's \nA_Taskinha Adonis_Pizza_&_Grill \nA_Taste_Of_Persia_-_Collection_Only Ado's \nA_To_Buy_Fish_&_Chips Adras_Restaurant \nA_Touch_of_Spice Adriatic_Italian \nA_World_Of_Fl@vours AF88 \nA_Yummy_Pizza Afandina_Restaurant \nA&A_Peri_Peri AFC \nA&S_Fast_Food AFC_American_Fried_Chicken \nA.J's_Pizza AFC_Fried_Chicken_&_Pizza \nèkó_Food_Market AFC_Pizza \n£1_Fish_Shop AFC-American_Fried_Chicken \nA1_Balti_House Afendi_Club_&_Restaurant \nA1_Pizzas Afendi_Restaurant_&_Cafe \nA1_Rice_'N'_Spice Afghan_Kebab_Takeaway \nA1_Wok Afghan_Pamir \nA12_Spice Afghan_Restaurant \nA4_Pizza_&_Kebab Afghan_Spice \nAA_Charcoal_Grill Africa_9JA_Restaurant \nAachi_Chettinad Africa_Best_Place \nAadams_Authentic_Grill African_Flavour \nAakash_Balti Afritopia_-_African_Restaurant_with_Style\nAakash_Restaurant Afsana \nAamaya After_Taste \nAamino's_Pizza Afters_Original \nAanias_Takeaway Agoon_Pani_Restaurant_&_Takeaway \nAAQA_Fast_Food Agra \nAaris_Indian_Restaurant Agra_Indian_Restaurant_&_Takeaway \nAarthi Agra_Spice_World \nA6_Grill Agra_Tandoori \nAashiana Agra_Tandoori_&_Balti \nAashir's Agra_Tandoori_Express \nAayan's Agrabad \nAB_Pizza_and_Grill Ahads_Bengal_Balti \nAbabil Ahjee_Bhajee \nAbaseen Ahmed_Indian_Takeaway \nAbbey_Fish_Bar Ahmed_Tandoori \nAbbey_Fryers_Fish_Bar_&_Balti_House Ahmed's \nAbbey_Meads_Indian_Restaurant_&_Takeaway Ahmeds_Curry_Cafe \nAbbey_Spice Ahmeds_Masala_Cafe \nAbbey_Tandoori Ahmed's_Perfect_Fried_Chicken \nAbbeyfry_Fish_and_Chips Ahmeds_Tandoori \nAbbeyfry_Pizzeria_&_Kebab_House Ai_Sushi \nAbbey's_Balti_Village Ai_Wok \nAbbey's_Fish_&_Chips_&_Pizza_Place Aimees \nAbbeys_Junction_Pizzeria Airlink_Restaurant_-_Collection_Only \nAbbey's_Pizza Aishah_Tandoori \nAbbeywood_Tandoori Aisha's \nAbbies_Pizza AJ_Pizza_Town_Limited \nAbby's_Diner AJ_Takeaway \nAbdul_Hadi Ajanta_Indian_Cuisine \nAbdul_Spice Ajantha_Takeaway \nAbduls Aji_-_Collection_Only \nAbdul's AJ's_Chicken \nAbdul's_Balti_House Aisuru_Sushi \nAbdul's_Curry_House AJs_Multi_Cuisine \nAbdul's_Indian AJ's_Pizza \nAbdul's_Indian_Cuisine AJ's_Traditional_Fish_&_Chips \nAbduls_Kebab_House Ajuba_Indian_Cuisine \nAbduls_Rusholme Ajwa_Restaurant \nAberavon_Packed_Meals AK_Chicken_Food \nAberbargoed_Indian_Takeaway AK_Grill " }, "metadata": {}, "output_type": "execute_result", "execution_count": 8 } ], "source": [ "for resto in ls | load: \n", " mv(resto, resto['name'].replace(' ', '_').replace('/', '_')) \n", " \n", "ls()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "The search functionality\n", "------------------------\n", "\n", "In the mood for curry in Edinburgh?" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "pycharm": { "name": "#%%\n", "is_executing": false } }, "outputs": [ { "data": { "text/plain": "┌──────────────┬──────────────────────────────────────────────────────┐\n│URL │http://www.just-eat.co.uk/restaurants-abduls-eh10/menu│\n│address │22 Comiston Road │\n│address line 2│Edinburgh │\n│name │Abduls │\n│outcode │EH10 │\n│postcode │5QE │\n│rating │5 │\n│type_of_food │Curry │\n└──────────────┴──────────────────────────────────────────────────────┘\n┌──────────────┬───────────────────────────────────────────────────────────┐\n│URL │http://www.just-eat.co.uk/restaurants-abida-restaurant/menu│\n│address │295A St John's Road │\n│address line 2│Edinburgh │\n│name │Abida │\n│outcode │EH12 │\n│postcode │7XF │\n│rating │4.5 │\n│type_of_food │Curry │\n└──────────────┴───────────────────────────────────────────────────────────┘\n┌──────────────┬─────────────────────────────────────────────────────────────┐\n│URL │http://www.just-eat.co.uk/restaurants-ahmedstandoori-eh6/menu│\n│address │100 Newhaven Road │\n│address line 2│Edinburgh │\n│name │Ahmeds Tandoori │\n│outcode │EH6 │\n│postcode │4BS │\n│rating │5 │\n│type_of_food │Curry │\n└──────────────┴─────────────────────────────────────────────────────────────┘\n┌──────────────┬────────────────────────────────────────────────────────┐\n│URL │http://www.just-eat.co.uk/restaurants-agoonpani-eh6/menu│\n│address │91 Henderson Street │\n│address line 2│Edinburgh │\n│name │Agoon Pani Restaurant & Takeaway │\n│outcode │EH6 │\n│postcode │6ED │\n│rating │5 │\n│type_of_food │Curry │\n└──────────────┴────────────────────────────────────────────────────────┘" }, "metadata": {}, "output_type": "execute_result", "execution_count": 9 } ], "source": [ "cat(find(state={'type_of_food': 'Curry', 'address line 2': 'Edinburgh'}))" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "Let's organise our resto's a little more into folders" ] }, { "cell_type": "code", "source": [ "for resto in ls | load:\n", " mv(resto, resto['type_of_food'] + '/') # All directories in PyOS end with a '/'\n", " \n", "ls()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% \n", "is_executing": false } }, "execution_count": 10, "outputs": [ { "data": { "text/plain": "Chinese/ African/ Fish & Chips/ Arabic/ Persian/ Caribbean/ Russian/ Burgers/\nThai/ Turkish/ English/ Desserts/ Peri Peri/ Ethiopian/ Afghan/ Sushi/ \nCurry/ Breakfast/ Lebanese/ Kebab/ South Curry/ Greek/ Cakes/ Grill/ \nPizza/ American/ Chicken/ Portuguese/ Punjabi/ Moroccan/ Japanese/" }, "metadata": {}, "output_type": "execute_result", "execution_count": 10 } ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "Beautiful, let's just check:" ] }, { "cell_type": "code", "execution_count": 11, "outputs": [ { "data": { "text/plain": "007_Takeaway 9th_Avenue_Pizzeria Adams_Alsabti_Pizzeria_&_Grill_House\n109_Ristorante A_La_Pizza Adam's_Cafe_-_Collection_Only \n1pizza1 A_La_Turka Adam's_Diner \n1st_Choice_Pizza A_Matter_Of_Taste Adam's_Fast_Food \n1st_Class_Pizza A_Yummy_Pizza Adam's_Hot_&_Spicy \n1st_Class_Pizza_&_Kebab_House A.J's_Pizza Adams_Pizza \n2_4_1_Pizza A1_Pizzas Adam's_Pizza_&_Kebab \n2_for_1_Pizza_Place A4_Pizza_&_Kebab Adams_Pizza_&_Kebabs \n2_Treat_U Aamino's_Pizza Adams_Pizza_Corner \n241_Pizza AAQA_Fast_Food Adam's_Pizzeria \n2-4-1_Pizza Abbeyfry_Pizzeria_&_Kebab_House Adams_Pizzeria \n321_Pizzas,_Kebabs_&_Burgers Abbeys_Junction_Pizzeria Adana_Pizza \n4_in_1_Express Abduls_Kebab_House Adeels_Spice \n4_Seasons_Pizza_&_Grill Aberdare_Charcoal_Grill Adel's_Pizza \n5_Star_Pizza Abe's_Pizza Admiral_Pizza \n555_Pizza Abra_Pizzas Adnan_Southern_Fried_Chicken_Shop \n555_Pizza_&_Kebab ABS_Fast_Food Adriatic_Italian \n64_Pizzeria Ace_Pizza AFC_Pizza \n7_STAR_Pizza ACE_Pizza_&_Kebab Afendi_Club_&_Restaurant \n7_Star_Spices Adams AJ's_Pizza \n9_Inch_CFC Adams_&_Lily's AJ's_Traditional_Fish_&_Chips " }, "metadata": {}, "output_type": "execute_result", "execution_count": 11 } ], "source": [ "ls('Pizza/')" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "You know what, I'm vegetarian anyway - let's delete the chicken joints" ] }, { "cell_type": "code", "execution_count": 12, "outputs": [ { "name": "stdout", "text": [ "rm: cannot remove 'Chicken/': Is a directory\n" ], "output_type": "stream" } ], "source": [ "rm('Chicken/')" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "source": [ "Whoops, I forgot the -r" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "source": [ "rm -r ('Chicken/')\n", "ls()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } }, "execution_count": 13, "outputs": [ { "data": { "text/plain": "Chinese/ African/ Fish & Chips/ Desserts/ Peri Peri/ Ethiopian/ Afghan/ Sushi/\nThai/ Turkish/ English/ Kebab/ South Curry/ Greek/ Cakes/ Grill/\nCurry/ Breakfast/ Lebanese/ Portuguese/ Punjabi/ Moroccan/ Japanese/\nPizza/ American/ Arabic/ Persian/ Caribbean/ Russian/ Burgers/ " }, "metadata": {}, "output_type": "execute_result", "execution_count": 13 } ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "Using metadata\n", "--------------\n", "\n", "Let's add my personal ratings as metadata" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "pycharm": { "name": "#%%\n", "is_executing": false } }, "outputs": [ { "data": { "text/plain": "┌──────────────┬────────────────────────┐\n│_directory │/martin/Curry/ │\n│obj_id │5e8e20ed1dbc98e7a84d9660│\n│name │Ahmeds_Tandoori │\n│martins_rating│5.5 │\n└──────────────┴────────────────────────┘" }, "metadata": {}, "output_type": "execute_result", "execution_count": 14 } ], "source": [ "meta -u ('Curry/Ahmeds_Tandoori', martins_rating=5.5) # -u for 'update'\n", "meta -u ('Curry/Abida', martins_rating=6)\n", "meta -u ('Curry/Abduls', martins_rating=4) \n", "\n", "# Let's have a look\n", "meta('Curry/Ahmeds_Tandoori')" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "And now let's find the good ones" ] }, { "cell_type": "code", "execution_count": 15, "outputs": [ { "data": { "text/plain": "Ahmeds_Tandoori\nAbida" }, "metadata": {}, "output_type": "execute_result", "execution_count": 15 } ], "source": [ "find(meta=dict(martins_rating=queries.gt(5)))\n" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "metadata": { "pycharm": { "is_executing": false, "name": "#%% md\n" } }, "source": [ "You can also 'pipe' results to another callable:" ] }, { "cell_type": "code", "execution_count": 16, "outputs": [ { "data": { "text/plain": "2" }, "metadata": {}, "output_type": "execute_result", "execution_count": 16 } ], "source": [ "find(meta=dict(martins_rating=queries.gt(5))) | len\n" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } } ], "metadata": { "kernelspec": { "display_name": "PyCharm (pyos)", "language": "python", "name": "pycharm-3c4673b5" }, "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.7.5" }, "pycharm": { "stem_cell": { "cell_type": "raw", "source": [], "metadata": { "collapsed": false } } } }, "nbformat": 4, "nbformat_minor": 1 }