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.
9.3 KiB
9.3 KiB
<html>
<head>
</head>
</html>
In [25]:
import json
import pprint
import requests
import pymongo
myclient = pymongo.MongoClient(
"mongodb://donaldrich:ibanez69@192.168.1.101:27017")
# DB
data = requests.get(
"https://raw.githubusercontent.com/lockys/Awesome.json/master/awesome/awesome.json?ref=master",
headers={"Accept": "application/vnd.github.v3+json"},
)
#
repos = data.json()
for x in repos.values():
for z in x:
try:
string = z['repo']
# if len(z['name']) > 0:
# title = z['name']
# else:
# title = "none"
# # print(count)
title = z['name']
title = title.replace(".", "")
link = string.replace("/", "-")
mydb = myclient["awesome-lists"]
mycol = mydb[title]
one_list = requests.get(
"https://raw.githubusercontent.com/lockys/awesome.json/master/repo-json/"
+ link + ".json",
headers={"Accept": "application/vnd.github.v3+json"},
)
print(title)
for x in one_list.json():
try:
mydict = x
# pprint.pprint(mydict)
new = mycol.insert_one(mydict)
# print(new.inserted_id)
except:
print(x)
except ValueError as error:
print(z)
# print("invalid json: %s" % error)
Node.js Node.js - Cross-Platform Frontend Development iOS Android IoT & Hybrid Apps Electron Cordova React Native Xamarin Linux Linux - Containers Linux - eBPF Linux - Arch-based Projects Linux - AppImage macOS - Screensavers macOS - Apps macOS - Open Source Apps watchOS JVM Salesforce Amazon Web Services Windows IPFS Fuse Heroku Raspberry Pi Qt WebExtensions Smart TV GNOME KDE
--------------------------------------------------------------------------- InvalidName Traceback (most recent call last) Input In [25], in <cell line: 18>() 28 link = string.replace("/", "-") 30 mydb = myclient["awesome-lists"] ---> 31 mycol = mydb[title] 33 one_list = requests.get( 34 "https://raw.githubusercontent.com/lockys/awesome.json/master/repo-json/" 35 + link + ".json", 36 headers={"Accept": "application/vnd.github.v3+json"}, 37 ) 38 print(title) File /opt/conda/lib/python3.10/site-packages/pymongo/database.py:237, in Database.__getitem__(self, name) 229 def __getitem__(self, name: str) -> "Collection[_DocumentType]": 230 """Get a collection of this database by name. 231 232 Raises InvalidName if an invalid collection name is used. (...) 235 - `name`: the name of the collection to get 236 """ --> 237 return Collection(self, name) File /opt/conda/lib/python3.10/site-packages/pymongo/collection.py:212, in Collection.__init__(self, database, name, create, codec_options, read_preference, write_concern, read_concern, session, **kwargs) 210 raise InvalidName("collection names must not contain '$': %r" % name) 211 if name[0] == "." or name[-1] == ".": --> 212 raise InvalidName("collection names must not start or end with '.': %r" % name) 213 if "\x00" in name: 214 raise InvalidName("collection names must not contain the null character") InvalidName: collection names must not start or end with '.': '.NET'
In [13]:
import pymongo
myclient = pymongo.MongoClient("mongodb://donaldrich:ibanez69@192.168.1.101:27017")
# DB
mydb = myclient["awesome-lists"]
# Collectinon
mycol = mydb["test"]
mydict = {"name": "Peter", "address": "Lowstreet 27"}
x = mycol.insert_one(mydict)
print(x.inserted_id)
print(mydb.list_collection_names())
63136ab944dfc9e0de996f01 ['test']
In [ ]:
!pip install pymongo