def replace_formats_clean_pagination2(self, old, new): """Replaces the old value in physical format fields by the new value. This method tries to process all records with old as format value, which are potentially millions of records. """ print_log("Getting records with format '"+old+"'...") olids = self.ol.query({"type":"/type/edition", "physical_format": old, "limit": 1000}) list = [] for olid in olids: # Feed authors to buffer list list.append(olid) if len(list) > 99: # Process these few authors before continuing feeding # Get records print_log("Getting full records") records = self.ol.get_many(list) for obj in records.itervalues(): obj = unmarshal(obj) self._replace_formats_clean_pagination(obj, old, new) list = [] if len(list) > 0: records = self.ol.get_many(list) for obj in records.itervalues(): obj = unmarshal(obj) self._replace_formats_clean_pagination(obj, old, new) self.flush_all()
def undelete_author(a, ol): key = a['key'] assert a['type'] == '/type/delete' url = 'http://openlibrary.org' + key + '.json?v=' + str(a['revision'] - 1) prev = unmarshal(json.load(urllib2.urlopen(url))) assert prev['type'] == '/type/author' ol.save(key, prev, 'undelete author')
def undelete_author(a): key = a['key'] assert a['type'] == '/type/delete' url = 'http://openlibrary.org' + key + '.json?v=' + str(a['revision'] - 1) prev = unmarshal(json.load(urlopen(url))) assert prev['type'] == '/type/author' ol.save(key, prev, 'undelete author')
def add_by(self, obj, by): if by != "": if "by_statement" in obj.keys(): if len(obj["by_statement"]) == 0: obj["by_statement"] = by return (obj, "updated By statement") elif "notes" in obj.keys(): # and "value" in obj["notes"].keys() print self.enc(obj["notes"]) if isinstance(obj["notes"], Text): obj["notes"] = obj["notes"] + "\n\nBy statement found in format: " + by + "\n" return (obj, "added By statement to notes, because By statement field was not empty") elif isinstance(obj["notes"], dict): d = unmarshal(obj["notes"]) obj["notes"] = d + "\n\nBy statement found in format: " + by + "\n" return (obj, "added By statement to notes, because By statement field was not empty") else: obj["notes"] = Text("By statement found in format: " + by + "\n") return (obj, "put By statement in notes") else: obj["notes"] = Text("By statement found in format: " + by + "\n") return (obj, "put By statement in notes") else: obj["by_statement"] = by return (obj, "added By statement") else: return (obj, None)