def migrate_reprints_lars(): # 18732 Superman # 26245 Superboy # 31648 Batman Sonderheft # 36955 Grüne Leuchte # 36980 Wundergirl # 36973 Superman Sonderausgabe # 36949 Batman Sonderausgabe # 36975 Superman Superband # 36964 Roter Blitz # 36953 Gerechtigkeitsliga # 36967 Superfreunde # 39648 Atom issues = Issue.objects.exclude(deleted=True).filter(series__id__in=[ 18732, 26245, 31648, 36955, 36980, 36973, 36949, 36975, 36964, 36953, 36967, 39648 ], reserved=False) #issues = Issue.objects.filter(series__id__in = [36953], reserved=False) migrated = [] for migrate_issue in issues: changeset = migrate_reserve(migrate_issue, 'issue', 'to migrate reprint notes into links') if not changeset: # this should not happen since we filter out reserved issues raise ValueError, "%s is reserved" % migrate_issue #else: #print migrate_issue, migrate_issue.id things = changeset.storyrevisions.all() for i in things: text_reprint = "" if i.reprint_notes: for string in split_reprint_string(i.reprint_notes): #print len(string) if string == " USA": break #print string issue, notes, sequence_number, story = parse_reprint_lars( string) if issue and issue.series.language.code.lower( ) == 'en' and string.startswith('in '): # Lars sometimes copied further US printings, don't create links #print "double", string issue = None #print issue, notes, sequence_number, story if sequence_number < 0 and issue: if i.sequence_number == 0: story = Story.objects.exclude(deleted=True).filter( issue=issue) story = story.filter(sequence_number=0) if story.count() == 1: story = story[0] sequence_number = 0 else: story = False #else: #print "no sequence number found", string, issue #print issue if issue: if sequence_number >= 0 and story: changeset.reprintrevisions.create( origin_story=story, target_story=i.story, notes=notes) else: if issue.series.language.code.lower() == 'de': nr = find_reprint_sequence_in_issue( i.story, issue.id) if string.lower().startswith('from'): if nr > 0: story = issue.active_stories().get( sequence_number=nr) changeset.reprintrevisions.create( origin_story=story, target_story=i.story, notes=notes) else: changeset.reprintrevisions.create( origin_issue=issue, target_story=i.story, notes=notes) else: if nr > 0: story = issue.active_stories().get( sequence_number=nr) changeset.reprintrevisions.create( origin_story=i.story, target_story=story, notes=notes) else: changeset.reprintrevisions.create( target_issue=issue, origin_story=i.story, notes=notes) else: changeset.reprintrevisions.create( origin_issue=issue, target_story=i.story, notes=notes) else: text_reprint += string + "; " if len(text_reprint) > 0: text_reprint = text_reprint[:-2] #print "Reprint Note Left: ", i.issue, i.issue.id, text_reprint i.migration_status.reprint_needs_inspection = True i.migration_status.save() i.reprint_notes = text_reprint i.save() if changeset.reprintrevisions.count(): migrated.append((changeset, True)) else: # nothing migrated #print 'nothing migrated' changeset.discard(changeset.indexer) # free reservation changeset.delete() # no need to keep changeset if len(migrated) > 100: do_auto_approve(migrated, 'reprint note migration') migrated = [] if len(migrated): do_auto_approve(migrated, 'reprint note migration')
def migrate_reprints_lars(): # 18732 Superman # 26245 Superboy # 31648 Batman Sonderheft # 36955 Grüne Leuchte # 36980 Wundergirl # 36973 Superman Sonderausgabe # 36949 Batman Sonderausgabe # 36975 Superman Superband # 36964 Roter Blitz # 36953 Gerechtigkeitsliga # 36967 Superfreunde # 39648 Atom issues = Issue.objects.exclude(deleted=True).filter(series__id__in = [18732,26245,31648,36955,36980,36973,36949,36975,36964, 36953, 36967, 39648], reserved=False) #issues = Issue.objects.filter(series__id__in = [36953], reserved=False) migrated = [] for migrate_issue in issues: changeset = migrate_reserve(migrate_issue, 'issue', 'to migrate reprint notes into links') if not changeset: # this should not happen since we filter out reserved issues raise ValueError, "%s is reserved" % migrate_issue #else: #print migrate_issue, migrate_issue.id things = changeset.storyrevisions.all() for i in things: text_reprint = "" if i.reprint_notes: for string in split_reprint_string(i.reprint_notes): #print len(string) if string == " USA": break #print string issue, notes, sequence_number, story = parse_reprint_lars(string) if issue and issue.series.language.code.lower() == 'en' and string.startswith('in '): # Lars sometimes copied further US printings, don't create links #print "double", string issue = None #print issue, notes, sequence_number, story if sequence_number < 0 and issue: if i.sequence_number == 0: story = Story.objects.exclude(deleted=True).filter(issue = issue) story = story.filter(sequence_number = 0) if story.count() == 1: story = story[0] sequence_number = 0 else: story = False #else: #print "no sequence number found", string, issue #print issue if issue: if sequence_number >= 0 and story: changeset.reprintrevisions.create(origin_story=story, target_story=i.story, notes=notes) else: if issue.series.language.code.lower() == 'de': nr = find_reprint_sequence_in_issue(i.story, issue.id) if string.lower().startswith('from'): if nr > 0: story = issue.active_stories().get(sequence_number = nr) changeset.reprintrevisions.create(origin_story=story, target_story=i.story, notes=notes) else: changeset.reprintrevisions.create(origin_issue=issue, target_story=i.story, notes=notes) else: if nr > 0: story = issue.active_stories().get(sequence_number = nr) changeset.reprintrevisions.create(origin_story=i.story, target_story=story, notes=notes) else: changeset.reprintrevisions.create(target_issue=issue, origin_story=i.story, notes=notes) else: changeset.reprintrevisions.create(origin_issue=issue, target_story=i.story, notes=notes) else: text_reprint += string + "; " if len(text_reprint) > 0: text_reprint = text_reprint[:-2] #print "Reprint Note Left: ", i.issue, i.issue.id, text_reprint i.migration_status.reprint_needs_inspection = True i.migration_status.save() i.reprint_notes = text_reprint i.save() if changeset.reprintrevisions.count(): migrated.append((changeset, True)) else: # nothing migrated #print 'nothing migrated' changeset.discard(changeset.indexer) # free reservation changeset.delete() # no need to keep changeset if len(migrated) > 100: do_auto_approve(migrated, 'reprint note migration') migrated = [] if len(migrated): do_auto_approve(migrated, 'reprint note migration')
def find_migration_candidates(story, string, standard=True): """ Calls parser for reprint notes and returns results. returns: found issue notes found in [] sequence number of origin story (if found) origin story (if found) True if story is original, False otherwise """ string = string.strip() if string == '?' or string == '' or string[-1] == '?' or \ string.startswith('from ?') or string.startswith('uit ?') or \ string.startswith(uni("från ?")): return False, '', -1, False, False if standard == False: #otherwise some Disney stuff takes ages if string.lower().find('donald daily') >= 0: return False, '', -1, False, False elif string.lower().find('duck daily') >= 0: return False, '', -1, False, False elif string.lower().find('duck sunday') >= 0: return False, '', -1, False, False elif string.lower().find('donald sunday') >= 0: return False, '', -1, False, False elif string.lower().find('mouse sunday') >= 0: return False, '', -1, False, False elif string.lower().find('mickey sunday') >= 0: return False, '', -1, False, False elif string.lower().find('mouse daily') >= 0: return False, '', -1, False, False elif string.lower().find('mickey daily') >= 0: return False, '', -1, False, False # possible from/in in other languages reprint_direction = ["from ", "in "] if story.issue.series.language.code.lower() == 'it': #da, in reprint_direction = ["da ", "di "] + reprint_direction elif story.issue.series.language.code.lower() in ['es', 'pt']: #de, en reprint_direction = ["de ", "en "] + reprint_direction elif story.issue.series.language.code.lower() == 'nl': # uit, in reprint_direction = ["uit "] + reprint_direction elif story.issue.series.language.code.lower() in ['sv', 'no']: # från, i reprint_direction = [uni("från "), "i "] + reprint_direction elif story.issue.series.language.code.lower() == 'de': # aus reprint_direction = ["aus "] + reprint_direction reprint_direction_search = reprint_direction + [""] other_fr = True for from_to in reprint_direction_search: if standard: # check for our format reprint, notes = parse_reprint(string, from_to) # exclude same series if several issues (all with same starting year) are found if reprint.count() > 1: reprint = reprint.exclude(series__id=story.issue.series.id) if reprint.count() > 1 and reprint.count() <= 15: a = [] for i in range(reprint.count()): nr = find_reprint_sequence_in_issue(story, reprint[i].id) if (nr >= 0): a.append(i) if len(a) == 1: reprint = reprint.filter(id=reprint[a[0]].id) else: # check for some others reprint, notes = parse_reprint_full(string, from_to) reprint = reprint.exclude(id=story.issue.id) if reprint.count() > 1 and reprint.count() <= 15: a = [] for i in range(reprint.count()): nr = find_reprint_sequence_in_issue(story, reprint[i].id) if (nr >= 0): a.append(i) if len(a) == 1: reprint = reprint.filter(id=reprint[a[0]].id) # one other routine for a few specials if reprint.count() != 1: #== 0 or reprint.count() > 5: if other_fr: # need marker to only do once other_fr = False reprint = parse_reprint_fr(string) reprint = reprint.exclude(id=story.issue.id) if reprint.count() > 1 and reprint.count() <= 15: a = [] for i in range(reprint.count()): nr = find_reprint_sequence_in_issue( story, reprint[i].id) if (nr >= 0): a.append(i) if len(a) == 1: reprint = reprint.filter(id=reprint[a[0]].id) if reprint.count() == 1: reprint_direction = "from " if reprint.count() == 1: nr = find_reprint_sequence_in_issue(story, reprint[0].id) if from_to in ["from ", "aus ", "da ", "di ", "de ", \ "uit ",u"från "]: origin = False elif from_to == "": origin = False if notes: notes += " Confirm: direction of reprint" else: notes = "Confirm: direction of reprint" else: origin = True if notes: if notes.find('originaltitel') >= 0: pos = notes.find('originaltitel') notes = notes.replace('originaltitel', 'original title') if notes.find('Originaltitel') >= 0: pos = notes.find('Originaltitel') notes = notes.replace('Originaltitel', 'original title') if notes.lower().find(uni('história original')) >= 0: pos = notes.lower().find(uni('história original')) notes = notes.replace(uni('história original'), 'original title') if notes.lower().find(uni('História original')) >= 0: pos = notes.lower().find(uni('História original')) notes = notes.replace(uni('História original'), 'original title') if notes.lower().find('titolo originale') >= 0: pos = notes.lower().find('titolo originale') notes = notes.replace('titolo originale', 'original title') if notes.find('titre original') >= 0: pos = notes.find('titre original') notes = notes.replace('titre original', 'original title') if notes.find('Titre original') >= 0: pos = notes.find('Titre original') notes = notes.replace('Titre original', 'original title') if notes.lower().find('originally titled') >= 0: pos = notes.lower().find('originally titled') notes = notes.replace('originally titled', 'original title') if nr >= 0: other_story = Story.objects.exclude(deleted=True).filter( issue=reprint[0]) other_story = other_story.filter(sequence_number=nr) return reprint[0], notes, nr, other_story[0], origin elif notes and notes.lower().find('original ti') >= 0: pos = notes.lower().find('original ti') pos2 = notes[pos:].find('"') if pos2 > 0: pos3 = notes[pos + pos2 + 1:].find('"') if pos3 > 0: original_title = notes[pos + pos2 + 1:pos + pos2 + pos3] end_title = pos + pos2 + pos3 + 2 else: original_title = notes[pos + pos2:] end_title = len(notes) else: pos2 = notes[pos:].find(']') if pos2 > 0: original_title = notes[pos + len('original title'):pos + pos2] end_title = pos + pos2 + 1 else: pos2 = notes[pos:].find(';') if pos2 > 0: original_title = notes[pos + len('original title'):pos + pos2] end_title = pos + pos2 + 1 else: original_title = notes[pos + len('original title'):] end_title = len(notes) results = Story.objects.exclude(deleted=True) results = results.filter(issue=reprint[0]) results = results.filter( title__icontains=original_title.strip(' !.":')) if results.count() == 1: notes = notes[:pos] + notes[end_title:] return reprint[0], notes, results[ 0].sequence_number, results[0], origin elif results.count() > 1: results = results.filter(type=story.type) if results.count() == 1: notes = notes[:pos] + notes[end_title:] return reprint[0], notes, results[ 0].sequence_number, results[0], origin return reprint[0], notes, -1, False, origin else: return reprint[0], notes, -1, False, origin return False, '', -1, False, False
def find_migration_candidates(story, string, standard = True): """ Calls parser for reprint notes and returns results. returns: found issue notes found in [] sequence number of origin story (if found) origin story (if found) True if story is original, False otherwise """ string = string.strip() if string == '?' or string == '' or string[-1] == '?' or \ string.startswith('from ?') or string.startswith('uit ?') or \ string.startswith(uni("från ?")): return False, '', -1, False, False if standard == False: #otherwise some Disney stuff takes ages if string.lower().find('donald daily') >= 0: return False,'',-1,False,False elif string.lower().find('duck daily') >= 0: return False,'',-1,False,False elif string.lower().find('duck sunday') >= 0: return False,'',-1,False,False elif string.lower().find('donald sunday') >= 0: return False,'',-1,False,False elif string.lower().find('mouse sunday') >= 0: return False,'',-1,False,False elif string.lower().find('mickey sunday') >= 0: return False,'',-1,False,False elif string.lower().find('mouse daily') >= 0: return False,'',-1,False,False elif string.lower().find('mickey daily') >= 0: return False,'',-1,False,False # possible from/in in other languages reprint_direction = ["from ", "in "] if story.issue.series.language.code.lower() == 'it': #da, in reprint_direction = ["da ", "di "] + reprint_direction elif story.issue.series.language.code.lower() in ['es', 'pt']: #de, en reprint_direction = ["de ", "en "] + reprint_direction elif story.issue.series.language.code.lower() == 'nl': # uit, in reprint_direction = ["uit "] + reprint_direction elif story.issue.series.language.code.lower() in ['sv', 'no']: # från, i reprint_direction = [uni("från "), "i "] + reprint_direction elif story.issue.series.language.code.lower() == 'de': # aus reprint_direction = ["aus "] + reprint_direction reprint_direction_search = reprint_direction + [""] other_fr = True for from_to in reprint_direction_search: if standard: # check for our format reprint, notes = parse_reprint(string, from_to) # exclude same series if several issues (all with same starting year) are found if reprint.count() > 1: reprint = reprint.exclude(series__id = story.issue.series.id) if reprint.count() > 1 and reprint.count() <= 15: a = [] for i in range(reprint.count()): nr = find_reprint_sequence_in_issue(story, reprint[i].id) if (nr >= 0): a.append(i) if len(a) == 1: reprint = reprint.filter(id = reprint[a[0]].id) else: # check for some others reprint,notes = parse_reprint_full(string, from_to) reprint = reprint.exclude(id = story.issue.id) if reprint.count() > 1 and reprint.count() <= 15: a = [] for i in range(reprint.count()): nr = find_reprint_sequence_in_issue(story, reprint[i].id) if (nr >= 0): a.append(i) if len(a) == 1: reprint = reprint.filter(id = reprint[a[0]].id) # one other routine for a few specials if reprint.count() != 1 :#== 0 or reprint.count() > 5: if other_fr: # need marker to only do once other_fr = False reprint = parse_reprint_fr(string) reprint = reprint.exclude(id = story.issue.id) if reprint.count() > 1 and reprint.count() <= 15: a = [] for i in range(reprint.count()): nr = find_reprint_sequence_in_issue(story, reprint[i].id) if (nr >= 0): a.append(i) if len(a) == 1: reprint = reprint.filter(id = reprint[a[0]].id) if reprint.count() == 1: reprint_direction = "from " if reprint.count() == 1: nr = find_reprint_sequence_in_issue(story, reprint[0].id) if from_to in ["from ", "aus ", "da ", "di ", "de ", \ "uit ",u"från "]: origin = False elif from_to == "": origin = False if notes: notes += " Confirm: direction of reprint" else: notes = "Confirm: direction of reprint" else: origin = True if notes: if notes.find('originaltitel') >= 0: pos = notes.find('originaltitel') notes = notes.replace('originaltitel', 'original title') if notes.find('Originaltitel') >= 0: pos = notes.find('Originaltitel') notes = notes.replace('Originaltitel', 'original title') if notes.lower().find(uni('história original')) >= 0: pos = notes.lower().find(uni('história original')) notes = notes.replace(uni('história original'), 'original title') if notes.lower().find(uni('História original')) >= 0: pos = notes.lower().find(uni('História original')) notes = notes.replace(uni('História original'), 'original title') if notes.lower().find('titolo originale') >= 0: pos = notes.lower().find('titolo originale') notes = notes.replace('titolo originale', 'original title') if notes.find('titre original') >= 0: pos = notes.find('titre original') notes = notes.replace('titre original', 'original title') if notes.find('Titre original') >= 0: pos = notes.find('Titre original') notes = notes.replace('Titre original', 'original title') if notes.lower().find('originally titled') >= 0: pos = notes.lower().find('originally titled') notes = notes.replace('originally titled', 'original title') if nr >= 0: other_story = Story.objects.exclude(deleted=True).filter(issue = reprint[0]) other_story = other_story.filter(sequence_number = nr) return reprint[0],notes,nr,other_story[0],origin elif notes and notes.lower().find('original ti') >=0: pos = notes.lower().find('original ti') pos2 = notes[pos:].find('"') if pos2 > 0: pos3 = notes[pos+pos2+1:].find('"') if pos3 > 0: original_title = notes[pos+pos2+1:pos+pos2+pos3] end_title = pos+pos2+pos3+2 else: original_title = notes[pos+pos2:] end_title = len(notes) else: pos2 = notes[pos:].find(']') if pos2 > 0: original_title = notes[pos+len('original title'):pos+pos2] end_title = pos+pos2+1 else: pos2 = notes[pos:].find(';') if pos2 > 0: original_title = notes[pos+len('original title'):pos+pos2] end_title = pos+pos2+1 else: original_title = notes[pos+len('original title'):] end_title = len(notes) results = Story.objects.exclude(deleted=True) results = results.filter(issue = reprint[0]) results = results.filter(title__icontains = original_title.strip(' !.":')) if results.count() == 1: notes = notes[:pos] + notes[end_title:] return reprint[0],notes,results[0].sequence_number,results[0],origin elif results.count() > 1: results = results.filter(type=story.type) if results.count() == 1: notes = notes[:pos] + notes[end_title:] return reprint[0],notes,results[0].sequence_number,results[0],origin return reprint[0],notes,-1,False,origin else: return reprint[0],notes,-1,False,origin return False,'',-1,False,False