Skip to content

Instantly share code, notes, and snippets.

@moarshy
Created June 28, 2022 08:24
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "7ef2fd0a",
"metadata": {},
"outputs": [],
"source": [
"from ipfsspec.core import *"
]
},
{
"cell_type": "markdown",
"id": "0c525a9d",
"metadata": {},
"source": [
"# Local node"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "9c67848b",
"metadata": {},
"outputs": [],
"source": [
"fs = IPFSFileSystem(gateway_type='local')"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "87b58540",
"metadata": {},
"outputs": [],
"source": [
"r = fs._gw_apipost('ls', arg='QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9')"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "63f6824e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'Objects': [{'Hash': 'QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9',\n",
" 'Links': []}]}]"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"parse_response(r)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "86560059",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"About this archive\\nThis is an archive of the Project Apollo Archive, a re-presentation of the public domain NASA-provided Apollo mission imagery as it was originally provided in its raw, high-resolution and unprocessed form by the Johnson Space Center on DVD-R and including from the center's Gateway to Astronaut Photography of Earth web site.\\n\\nDirectory names are base64 encoded names of each of the albums in the archive. This was done in order to handle characters in the album names that aren't valid in directory names.\\n\\nUpdating this archive\\nUse the included apolloarchive.py script. Before running, you will need to `pip install flickrapi`. The script also needs to have an API key and secret specified.\\n\\nIf you don't already have one, you can apply for a non-commercial flickr API at https://www.flickr.com/services/apps/create/apply.\\n\\nUpdating the frontend\\nThe frontend lives in the frontend directory and can be updated using the build_frontend_index.py script. This script will update/create the frontend.html page as well as pages for each of the albums. It will also generate thumbnails in the frontend/thumbnails directory.\\n\""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#given a file path to cat_file\n",
"fs.cat_file('QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "136f1022",
"metadata": {},
"outputs": [
{
"ename": "HTTPError",
"evalue": "Response Status Code: 500; Error Message: this dag node is a directory",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mHTTPError\u001b[0m Traceback (most recent call last)",
"Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m#given a dir path to cat_file -> dag node can only be opened with `cat` function\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[43mfs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcat_file\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mQmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[1;32md:\\github\\ipfsspec\\ipfsspec\\core.py:236\u001b[0m, in \u001b[0;36mIPFSFileSystem.cat_file\u001b[1;34m(self, path)\u001b[0m\n\u001b[0;32m 234\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m parse_response(res)\n\u001b[0;32m 235\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m--> 236\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError (parse_error_message(res)) \n\u001b[0;32m 237\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m parse_response(data)\n",
"\u001b[1;31mHTTPError\u001b[0m: Response Status Code: 500; Error Message: this dag node is a directory"
]
}
],
"source": [
"#given a dir path to cat_file -> dag node can only be opened with `cat` function\n",
"fs.cat_file('QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b1e4b30b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# given a file path to ls\n",
"fs.ls('QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9') # Should we raise an exception??"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "d44ba0ae",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'name': 'QmPWSgAamKS9YLuWbEWeqgZEoWsJBQ2kpKQyijTVBvwJLp/.ipynb_checkpoints',\n",
" 'size': 0,\n",
" 'type': 'directory'},\n",
" {'name': 'QmPWSgAamKS9YLuWbEWeqgZEoWsJBQ2kpKQyijTVBvwJLp/adult_data.csv',\n",
" 'size': 3974475,\n",
" 'type': 'file'},\n",
" {'name': 'QmPWSgAamKS9YLuWbEWeqgZEoWsJBQ2kpKQyijTVBvwJLp/fol1',\n",
" 'size': 0,\n",
" 'type': 'directory'},\n",
" {'name': 'QmPWSgAamKS9YLuWbEWeqgZEoWsJBQ2kpKQyijTVBvwJLp/test.txt',\n",
" 'size': 24,\n",
" 'type': 'file'},\n",
" {'name': 'QmPWSgAamKS9YLuWbEWeqgZEoWsJBQ2kpKQyijTVBvwJLp/test2.txt',\n",
" 'size': 23,\n",
" 'type': 'file'},\n",
" {'name': 'QmPWSgAamKS9YLuWbEWeqgZEoWsJBQ2kpKQyijTVBvwJLp/test3.txt',\n",
" 'size': 32,\n",
" 'type': 'file'},\n",
" {'name': 'QmPWSgAamKS9YLuWbEWeqgZEoWsJBQ2kpKQyijTVBvwJLp/test4.txt',\n",
" 'size': 20,\n",
" 'type': 'file'}]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#given a dir to ls\n",
"fs.ls('QmPWSgAamKS9YLuWbEWeqgZEoWsJBQ2kpKQyijTVBvwJLp')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "aaaef595",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"About this archive\\nThis is an archive of the Project Apollo Archive, a re-presentation of the public domain NASA-provided Apollo mission imagery as it was originally provided in its raw, high-resolution and unprocessed form by the Johnson Space Center on DVD-R and including from the center's Gateway to Astronaut Photography of Earth web site.\\n\\nDirectory names are base64 encoded names of each of the albums in the archive. This was done in order to handle characters in the album names that aren't valid in directory names.\\n\\nUpdating this archive\\nUse the included apolloarchive.py script. Before running, you will need to `pip install flickrapi`. The script also needs to have an API key and secret specified.\\n\\nIf you don't already have one, you can apply for a non-commercial flickr API at https://www.flickr.com/services/apps/create/apply.\\n\\nUpdating the frontend\\nThe frontend lives in the frontend directory and can be updated using the build_frontend_index.py script. This script will update/create the frontend.html page as well as pages for each of the albums. It will also generate thumbnails in the frontend/thumbnails directory.\\n\""
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#given a file to cat\n",
"fs.cat('QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "2cc2da66",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment