except Exception, e: editor = User(username=p.editor, puzzle_pref=PuzzleType.objects.get(type='US'), user_type=UserType.objects.get(type='Editor'), joined=date.today()) editor.save() else: editor = setter if hasattr(p, "date"): (m, d, y) = p.date.split('/') pdate = date(int(y),int(m),int(d)) else: pdate = date.today() if hasattr(p, "type"): try: ptype = PuzzleType.objects.get(type=p.type) except Exception: ptype = PuzzleType(type=p.type) ptype.save() else: ptype = PuzzleType.objects.get(type="US") try: grid = Grid.objects.get(format=p.dbgridstr) except Exception: grid = Grid(format=p.dbgridstr, type=ptype) grid.save() try: puzzle = Puzzle.objects.get(setter=setter, publisher=publisher, editor=editor, date=pdate, title=p.title, type=ptype) print "using existing puzzle" except Exception: puzzle = Puzzle(setter=setter, publisher=publisher, editor=editor, date=pdate, title=p.title, type=ptype, grid=grid)
def impXPF(url): xml_handle = urlopen(url) fname = "-".join(sys.argv[1].split("/")) + ".xpf" file_contents = xml_handle.read() save_file = open("/home/bbundy/puzzles/nyt/" + fname,"w") save_file.write(file_contents) save_file.close() try: PuzzleType.objects.get(type="Cryptic") except ObjectDoesNotExist: t = PuzzleType(type="Cryptic") t.save() t = PuzzleType(type="US") t.save() try: UserType.objects.get(type="Setter") except ObjectDoesNotExist: t = UserType(type="Setter") t.save() t = UserType(type="Editor") t.save() t = UserType(type="Publisher") t.save() t = UserType(type="Solver") t.save() p = xwcore.Puzzle.fromXML(file_contents) try: setter = User.objects.get(username=p.author) except Exception, e: setter = User(username=p.author, puzzle_pref=PuzzleType.objects.get(type='US'), user_type=UserType.objects.get(type='Setter'), joined=date.today()) setter.save()