You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
326 lines
10 KiB
326 lines
10 KiB
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "2bec1b04-f1ab-4165-a4ea-cc890cc9e5ec", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"!python -m pip install gql" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "7374f89e-23f8-407d-967b-c76e7d6d93a2", |
|
"metadata": { |
|
"scrolled": true, |
|
"tags": [] |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"import csv\n", |
|
"\n", |
|
"with open(\"/home/jovyan/code/directus/homebrew.txt\") as f:\n", |
|
" reader = csv.reader(f)\n", |
|
" for row in reader:\n", |
|
" item = row[0]\n", |
|
" print(item)" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "f0367eee-e052-4184-b016-8ecb0dd1aa32", |
|
"metadata": { |
|
"scrolled": true, |
|
"tags": [] |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"for x in scrubbed_records:\n", |
|
" # pprint.pprint(x)\n", |
|
" image = image.replace(\":latest\", \"\")\n", |
|
" name = name.replace(\"/\", \"\")\n", |
|
" data = x" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "f2b300a9-f7c0-4863-9696-29e92e6cedc8", |
|
"metadata": { |
|
"scrolled": true, |
|
"tags": [] |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"for x in scrubbed_records:\n", |
|
" item = x\n", |
|
" name = item[\"Name\"]\n", |
|
" image = item[\"Config\"][\"Image\"]\n", |
|
" image = image.replace(\":latest\", \"\")\n", |
|
" name = name.replace(\"/\", \"\")\n", |
|
" print(name)\n", |
|
" print(image)\n", |
|
" input_set = {\"id\": name, \"image\": image, \"name\": name, \"raw\": item}\n", |
|
"\n", |
|
" my_headers = {\n", |
|
" \"Authorization\": \"os.env(directus_token)\",\n", |
|
" \"Content-Type\": \"application/json\",\n", |
|
" }\n", |
|
" response = requests.post(\n", |
|
" \"https://cms.donavanaldrich.com/items/containers\",\n", |
|
" headers=my_headers,\n", |
|
" json=(input_set),\n", |
|
" )\n", |
|
" print(response.json())" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "a4dc5471-3df9-4d52-865e-ca9202d472a3", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"# https://formulae.brew.sh/api/cask.json" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 3, |
|
"id": "74566291-5fb8-455a-b674-03c0733c6700", |
|
"metadata": { |
|
"tags": [] |
|
}, |
|
"outputs": [ |
|
{ |
|
"name": "stdout", |
|
"output_type": "stream", |
|
"text": [ |
|
"{'appcast': None,\n", |
|
" 'artifacts': [['0 A.D..app'],\n", |
|
" {'signal': {},\n", |
|
" 'trash': '~/Library/Saved Application '\n", |
|
" 'State/com.wildfiregames.0ad.savedState'}],\n", |
|
" 'auto_updates': None,\n", |
|
" 'caveats': None,\n", |
|
" 'conflicts_with': None,\n", |
|
" 'container': None,\n", |
|
" 'depends_on': {'macos': {'>=': ['10.12']}},\n", |
|
" 'desc': 'Real-time strategy game',\n", |
|
" 'full_token': '0-ad',\n", |
|
" 'homepage': 'https://play0ad.com/',\n", |
|
" 'installed': None,\n", |
|
" 'name': ['0 A.D.'],\n", |
|
" 'outdated': False,\n", |
|
" 'sha256': 'd1a2073dee3435d8a78bf289206248c9ed6be5e17f4ba1ac8412caf6d0eae0b0',\n", |
|
" 'tap': 'homebrew/cask',\n", |
|
" 'token': '0-ad',\n", |
|
" 'url': 'https://releases.wildfiregames.com/0ad-0.0.25b-alpha-osx64.dmg',\n", |
|
" 'version': '0.0.25b-alpha',\n", |
|
" 'versions': {}}\n" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"import json\n", |
|
"import os\n", |
|
"import pprint\n", |
|
"\n", |
|
"import requests\n", |
|
"\n", |
|
"my_headers = {\"Content-Type\": \"application/json\"}\n", |
|
"raw_casks = requests.get(\"https://formulae.brew.sh/api/cask.json\")\n", |
|
"\n", |
|
"casks = raw_casks.json()\n", |
|
"\n", |
|
"# pprint.pprint(casks[0])" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "7b3f64e7-019a-4c21-9de2-5c84bd22640f", |
|
"metadata": { |
|
"scrolled": true, |
|
"tags": [] |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"for cask in casks:\n", |
|
" name = cask[\"name\"][0]\n", |
|
" desc = cask[\"desc\"]\n", |
|
" homepage = cask[\"homepage\"]\n", |
|
" url = cask[\"url\"]\n", |
|
" tap = cask[\"tap\"]\n", |
|
" full_name = cask[\"full_token\"]\n", |
|
" print(full_token)" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 4, |
|
"id": "1d6f86f0-91ab-4773-aba3-ace57852f9e4", |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"ename": "NameError", |
|
"evalue": "name 'raw' is not defined", |
|
"output_type": "error", |
|
"traceback": [ |
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
|
"\u001b[0;32m/tmp/ipykernel_9736/2986828884.py\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mcategory\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"cask\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0minput_set\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"id\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mfull_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"description\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdesc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"homepage\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mhomepage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"tap\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtap\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"raw\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mraw\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"category\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mcategory\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m response = requests.post(\n\u001b[1;32m 14\u001b[0m \u001b[0;34m\"https://cms.donavanaldrich.com/items/all_homebrews\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
|
"\u001b[0;31mNameError\u001b[0m: name 'raw' is not defined" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"my_headers = {\"Authorization\": \"os.env(directus_token)\", \"Content-Type\": \"application/json\"}\n", |
|
"\n", |
|
"for cask in casks:\n", |
|
" name = cask[\"name\"][0]\n", |
|
" desc = cask[\"desc\"]\n", |
|
" homepage = cask[\"homepage\"]\n", |
|
" url = cask[\"url\"]\n", |
|
" tap = cask[\"tap\"]\n", |
|
" full_name = cask[\"full_token\"]\n", |
|
" category = \"cask\"\n", |
|
" # raw\n", |
|
"\n", |
|
" input_set = {\n", |
|
" \"id\": full_name,\n", |
|
" \"description\": desc,\n", |
|
" \"homepage\": homepage,\n", |
|
" \"tap\": tap,\n", |
|
" \"raw\": cask,\n", |
|
" \"category\": category,\n", |
|
" }\n", |
|
" response = requests.post(\n", |
|
" \"https://cms.donavanaldrich.com/items/all_homebrews\",\n", |
|
" headers=my_headers,\n", |
|
" json=(input_set),\n", |
|
" )\n", |
|
" print(response.json())" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "ecab5d16-91a5-4a3d-9772-516410b8ce76", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"# https://formulae.brew.sh/api/formula.json" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "762b9c4d-dbfb-45dc-a24f-ca1a3a3bbbcf", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"my_headers = {\"Content-Type\": \"application/json\"}\n", |
|
"raw_brews = requests.get(\"https://formulae.brew.sh/api/formula.json\")\n", |
|
"\n", |
|
"brews = raw_brews.json()\n", |
|
"\n", |
|
"pprint.pprint(brews[0])" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "9bb9a11e-4343-421c-820d-ef927e02532f", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"for brew in brews:\n", |
|
" name = brew[\"name\"]\n", |
|
" desc = brew[\"desc\"]\n", |
|
" homepage = brew[\"homepage\"]\n", |
|
" url = brew[\"urls\"][\"stable\"][\"url\"]\n", |
|
" tap = brew[\"tap\"]\n", |
|
" full_name = brew[\"full_name\"]\n", |
|
" print(urls)" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "9630a738-10ef-40a0-b666-097b0ab02c06", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"my_headers = {\"Authorization\": \"os.env(directus_token)\", \"Content-Type\": \"application/json\"}\n", |
|
"\n", |
|
"for brew in brews:\n", |
|
" name = brew[\"name\"]\n", |
|
" desc = brew[\"desc\"]\n", |
|
" homepage = brew[\"homepage\"]\n", |
|
" url = brew[\"urls\"][\"stable\"][\"url\"]\n", |
|
" tap = brew[\"tap\"]\n", |
|
" full_name = brew[\"full_name\"]\n", |
|
" category = \"brew\"\n", |
|
"\n", |
|
" input_set = {\n", |
|
" \"id\": full_name,\n", |
|
" \"description\": desc,\n", |
|
" \"homepage\": homepage,\n", |
|
" \"tap\": tap,\n", |
|
" \"raw\": brew,\n", |
|
" \"category\": category,\n", |
|
" }\n", |
|
" response = requests.post(\n", |
|
" \"https://cms.donavanaldrich.com/items/all_homebrews\",\n", |
|
" headers=my_headers,\n", |
|
" json=(input_set),\n", |
|
" )\n", |
|
" print(response.json())" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "b835d52d-88bd-49f5-a1e3-d2b3c56e4fb2", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [] |
|
} |
|
], |
|
"metadata": { |
|
"kernelspec": { |
|
"display_name": "Python 3 (ipykernel)", |
|
"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.9.12" |
|
}, |
|
"toc-autonumbering": false, |
|
"toc-showcode": false, |
|
"toc-showtags": false, |
|
"widgets": { |
|
"application/vnd.jupyter.widget-state+json": { |
|
"state": {}, |
|
"version_major": 2, |
|
"version_minor": 0 |
|
} |
|
} |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 5 |
|
}
|
|
|