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.
187 lines
9.3 KiB
187 lines
9.3 KiB
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 25, |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"name": "stdout", |
|
"output_type": "stream", |
|
"text": [ |
|
"Node.js\n", |
|
"Node.js - Cross-Platform\n", |
|
"Frontend Development\n", |
|
"iOS\n", |
|
"Android\n", |
|
"IoT & Hybrid Apps\n", |
|
"Electron\n", |
|
"Cordova\n", |
|
"React Native\n", |
|
"Xamarin\n", |
|
"Linux\n", |
|
"Linux - Containers\n", |
|
"Linux - eBPF\n", |
|
"Linux - Arch-based Projects\n", |
|
"Linux - AppImage\n", |
|
"macOS - Screensavers\n", |
|
"macOS - Apps\n", |
|
"macOS - Open Source Apps\n", |
|
"watchOS\n", |
|
"JVM\n", |
|
"Salesforce\n", |
|
"Amazon Web Services\n", |
|
"Windows\n", |
|
"IPFS\n", |
|
"Fuse\n", |
|
"Heroku\n", |
|
"Raspberry Pi\n", |
|
"Qt\n", |
|
"WebExtensions\n", |
|
"Smart TV\n", |
|
"GNOME\n", |
|
"KDE\n" |
|
] |
|
}, |
|
{ |
|
"ename": "InvalidName", |
|
"evalue": "collection names must not start or end with '.': '.NET'", |
|
"output_type": "error", |
|
"traceback": [ |
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
"\u001b[0;31mInvalidName\u001b[0m Traceback (most recent call last)", |
|
"Input \u001b[0;32mIn [25]\u001b[0m, in \u001b[0;36m<cell line: 18>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 28\u001b[0m link \u001b[38;5;241m=\u001b[39m string\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m/\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m-\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 30\u001b[0m mydb \u001b[38;5;241m=\u001b[39m myclient[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mawesome-lists\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[0;32m---> 31\u001b[0m mycol \u001b[38;5;241m=\u001b[39m \u001b[43mmydb\u001b[49m\u001b[43m[\u001b[49m\u001b[43mtitle\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 33\u001b[0m one_list \u001b[38;5;241m=\u001b[39m requests\u001b[38;5;241m.\u001b[39mget(\n\u001b[1;32m 34\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://raw.githubusercontent.com/lockys/awesome.json/master/repo-json/\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 35\u001b[0m \u001b[38;5;241m+\u001b[39m link \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.json\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 36\u001b[0m headers\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAccept\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapplication/vnd.github.v3+json\u001b[39m\u001b[38;5;124m\"\u001b[39m},\n\u001b[1;32m 37\u001b[0m )\n\u001b[1;32m 38\u001b[0m \u001b[38;5;28mprint\u001b[39m(title)\n", |
|
"File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/pymongo/database.py:237\u001b[0m, in \u001b[0;36mDatabase.__getitem__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 229\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getitem__\u001b[39m(\u001b[38;5;28mself\u001b[39m, name: \u001b[38;5;28mstr\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCollection[_DocumentType]\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 230\u001b[0m \u001b[38;5;124;03m\"\"\"Get a collection of this database by name.\u001b[39;00m\n\u001b[1;32m 231\u001b[0m \n\u001b[1;32m 232\u001b[0m \u001b[38;5;124;03m Raises InvalidName if an invalid collection name is used.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 235\u001b[0m \u001b[38;5;124;03m - `name`: the name of the collection to get\u001b[39;00m\n\u001b[1;32m 236\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 237\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mCollection\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[43m)\u001b[49m\n", |
|
"File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/pymongo/collection.py:212\u001b[0m, in \u001b[0;36mCollection.__init__\u001b[0;34m(self, database, name, create, codec_options, read_preference, write_concern, read_concern, session, **kwargs)\u001b[0m\n\u001b[1;32m 210\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidName(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcollection names must not contain \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m$\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m: \u001b[39m\u001b[38;5;132;01m%r\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m name)\n\u001b[1;32m 211\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m name[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m name[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 212\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidName(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcollection names must not start or end with \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m: \u001b[39m\u001b[38;5;132;01m%r\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m name)\n\u001b[1;32m 213\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\x00\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m name:\n\u001b[1;32m 214\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidName(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcollection names must not contain the null character\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", |
|
"\u001b[0;31mInvalidName\u001b[0m: collection names must not start or end with '.': '.NET'" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"import json\n", |
|
"import pprint\n", |
|
"import requests\n", |
|
"import pymongo\n", |
|
"\n", |
|
"myclient = pymongo.MongoClient(\n", |
|
" \"mongodb://donaldrich:ibanez69@192.168.1.101:27017\")\n", |
|
"# DB\n", |
|
"\n", |
|
"data = requests.get(\n", |
|
" \"https://raw.githubusercontent.com/lockys/Awesome.json/master/awesome/awesome.json?ref=master\",\n", |
|
" headers={\"Accept\": \"application/vnd.github.v3+json\"},\n", |
|
")\n", |
|
"#\n", |
|
"\n", |
|
"repos = data.json()\n", |
|
"\n", |
|
"for x in repos.values():\n", |
|
" for z in x:\n", |
|
" try:\n", |
|
" string = z['repo']\n", |
|
"# if len(z['name']) > 0:\n", |
|
"# title = z['name']\n", |
|
"# else:\n", |
|
"# title = \"none\"\n", |
|
"# # print(count)\n", |
|
" title = z['name']\n", |
|
" title = title.replace(\".\", \"\")\n", |
|
" link = string.replace(\"/\", \"-\")\n", |
|
"\n", |
|
" mydb = myclient[\"awesome-lists\"]\n", |
|
" mycol = mydb[title]\n", |
|
"\n", |
|
" one_list = requests.get(\n", |
|
" \"https://raw.githubusercontent.com/lockys/awesome.json/master/repo-json/\"\n", |
|
" + link + \".json\",\n", |
|
" headers={\"Accept\": \"application/vnd.github.v3+json\"},\n", |
|
" )\n", |
|
" print(title)\n", |
|
" for x in one_list.json():\n", |
|
" try:\n", |
|
" mydict = x\n", |
|
"\n", |
|
"# pprint.pprint(mydict)\n", |
|
"\n", |
|
" new = mycol.insert_one(mydict)\n", |
|
"\n", |
|
" # print(new.inserted_id)\n", |
|
" except:\n", |
|
" print(x)\n", |
|
" except ValueError as error:\n", |
|
" print(z)\n", |
|
"# print(\"invalid json: %s\" % error)\n" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 13, |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"name": "stdout", |
|
"output_type": "stream", |
|
"text": [ |
|
"63136ab944dfc9e0de996f01\n", |
|
"['test']\n" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"import pymongo\n", |
|
"\n", |
|
"myclient = pymongo.MongoClient(\"mongodb://donaldrich:ibanez69@192.168.1.101:27017\")\n", |
|
"# DB\n", |
|
"\n", |
|
"mydb = myclient[\"awesome-lists\"]\n", |
|
"\n", |
|
"# Collectinon\n", |
|
"\n", |
|
"mycol = mydb[\"test\"]\n", |
|
"\n", |
|
"mydict = {\"name\": \"Peter\", \"address\": \"Lowstreet 27\"}\n", |
|
"\n", |
|
"x = mycol.insert_one(mydict)\n", |
|
"\n", |
|
"print(x.inserted_id)\n", |
|
"\n", |
|
"print(mydb.list_collection_names())" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"!pip install pymongo" |
|
] |
|
} |
|
], |
|
"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.10.5" |
|
}, |
|
"vscode": { |
|
"interpreter": { |
|
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" |
|
} |
|
} |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 2 |
|
}
|
|
|