Created
May 21, 2017 09:01
-
-
Save Libisch/ac2bd3636076c35ca94d393c9c098495 to your computer and use it in GitHub Desktop.
Latest update (currently on server)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from pymongo import MongoClient | |
import os | |
import requests | |
client = MongoClient(os.environ.get("MONGO_HOST", "localhost"), int(os.environ.get("MONGO_PORT", "27017"))) | |
db = client[os.environ["MONGO_DB"]] | |
photoUnits = db['photoUnits'] | |
data = requests.get("https://raw.githubusercontent.com/Beit-Hatfutsot/dbs-bagnowka-scrape/master/bagnowka_all.json").json() | |
count = 0 | |
photoUnits.delete_many({"bagnowka": "True"}) | |
for slug, doc in data.items(): | |
try: | |
for k in doc: | |
if "He" in doc[k]: | |
del doc[k]["He"] | |
photoUnits.insert_one(data[slug]) | |
count += 1 | |
print("1 item was added to photoUnits") | |
except Exception: | |
print("unexpected exception processing slug {} count {}".format(slug, count)) | |
raise | |
print("{} items were inserted to photoUnits.".format(count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment