def handle(self, *args, **options): print('Parsing persons.') print("Deleting all persons") Person.objects.filter(source='zakon.kz').delete() Person2Document.objects.all().delete() paginator = Paginator(MainDocuments.objects.all().order_by('-id'), 1000) for page in range(1, paginator.num_pages + 1): for md in paginator.page(page).object_list: match = re.search('Судья:(.*)', md.title) try: rezult = match.group(1) try: exist = Person.objects.get(raw_name=rezult, source='zakon.kz') except Exception as e: p = Person() p.raw_name = rezult p.role = 'СУДЬЯ' p.source = 'zakon.kz' p.save() p.parse() p2d = Person2Document() p2d.person = p p2d.document = md p2d.save() print("%s Судья ... %s" % (md.id, rezult)) except Exception as e: pass #print(str(e)) match = re.search(': (.*)Судья:', md.title) try: rezult = match.group(1) for nm in rezult.split(','): nm.replace('.', '') if len(nm) > 2: checking_words = nm.split(' ') if len(checking_words) < 5: try: exist = Person.objects.get( raw_name=rezult, source='zakon.kz') except Exception as e: p = Person() p.raw_name = nm p.role = 'ОТВЕТЧИК' p.source = 'zakon.kz' p.save() p.parse() p2d = Person2Document() p2d.person = p p2d.document = md p2d.save() print("%s Истец ... %s" % (md.id, rezult)) except Exception as e: #print(str(e)) pass
def parse_company(c): try: city = City.objects.get(name_ru__icontains=c.city_text) c.city = city c.save() except: print('City not found') namear = c.faunders_text.split(',') p = Person() p.raw_name = namear[0] p.role = namear[1] p.source = 'flagma.kz' p.save() p.parse() p2c = Person2Company() p2c.company = c p2c.person = p p2c.save() print('Saving person %s' % namear[0])