def getAddress(_id): _address = prod["addresses"].find_one({"_id": Client.getId(_id)}) if "_class" in _address: del _address["_class"] if _address: return _address return ''
def get_trusted_persons(claim): persons = [] if "trustedPersons" in claim: for person in claim["trustedPersons"]: persons.append( Client.getId(str(person["trustedPerson"]["trustedId"]))) data = get_data_from_db(persons) return data
def get_data_from_db(ids): persons_list = [] addresses_ids = [] documents = [] persons = dps["persons"].find({"_id": {"$in": ids}}) for person in persons: persons_list.append(person) documents = get_person_documents( Client.getId(person["currIdentityDocId"]) ) if "currIdentityDocId" in person else [] for ad in addresses_types: if ad in person: addresses_ids.append(Client.getId(person[ad])) addresses = get_addresses(addresses_ids) return { "persons": persons_list, "documents": documents, "addresses": addresses }
def get_string_address(obj, param): AddressId = get_attribute(obj, param) if AddressId != '': address_projection = { "country": 1, "region": 1, "area": 1, "locality": 1, "street": 1, "houseNumber": 1, "corps": 1, "room": 1, "countryPrefix": 1, "regionPrefix": 1, "areaPrefix": 1, "localityPrefix": 1, "streetPrefix": 1, "houseNumberPrefix": 1, "corpsPrefix": 1, "roomPrefix": 1, } address = prod["addresses"].find_one({"_id": Client.getId(AddressId)}, address_projection) if address is not None: addressObj = { "country": get_prefix(address, "country"), "region": get_prefix(address, "region"), "area": get_prefix(address, "area"), "locality": get_prefix(address, "locality"), "street": get_prefix(address, "street"), "houseNumber": f'д. {get_prefix(address, "houseNumber")}' if get_prefix(address, "houseNumber") != '' else '', "corps": get_prefix(address, "corps"), "room": f'кв. {get_prefix(address, "room")}' if get_prefix(address, "room") != '' else '' } reg_adr = [] for adr in list(addressObj.keys()): if addressObj[adr] == '': del addressObj[adr] else: reg_adr.append(addressObj[adr]) return ", ".join(reg_adr) return ''
from time import sleep import pymongo from bson import InvalidBSON from rldd.client import Client from rldd import config import datetime import requests from colors import console_colors yellow = console_colors.CYELLOW end = console_colors.CEND db = Client(config.PROD).connect() processed = 0 insert_count = 0 query = { "activationDate": { "$gte": Client.ISODate("2020-10-03T00:00:00.000+0000") }, "suspenseReason": { "$exists": True } } result_file = open('deadlines_correct.csv', 'w+') result_file.write( "customClaimNumber;activationDate;old DeadlineDate;new deadlineDate;daysToDeadline\n" ) projection = {
from rldd.client import Client from rldd.config import PROD from statuses.newIntegrationTest import create_status, send_file, create_doc, update_status db = Client(PROD).connect() statusId = "603f84e0799ab5000154eae6" sendFile1 = send_file("empty.txt") docId = create_doc(statusId, "STATUS", "empty.txt", sendFile1) print(sendFile1) print(docId)
"locationAddressId", "dateOfBirth", "placeOfBirth", "citizenshipCode", "registrationAddressId", "locationAddressId", "registrationAddress", "locationAddress", "familyStatus", "lowerCaseSurname", "lowerCaseFirstName", "lowerCaseMiddleName", "fio", ] person_attribute = ["surname", "firstName", "middleName", "fio"] db = Client(config.PROD).connect() db_persons = Client(config.DPS, "dps").connect() claims = db["claims"].find( {"customClaimNumber": { "$in": ["P001-6834136667-43022962"] }}) for claim in claims: claim_id = claim["_id"] claim_unset_data = {} isChanged = False person_id = str personsInfo = claim["personsInfo"] for index, pers in enumerate(personsInfo): if pers["type"] == "JURIDICAL": person_id = pers["_id"] path = f"personsInfo.{index}."
import json import requests from deadlines.deadline_functions import setDeadlineToOneDay from rldd.client import Client from rldd.config import PROD, DEV db = Client(PROD).connect() def postStatus(body): url = 'http://10.10.80.54:8080/api/statuses/' headers = {'Content-Type': 'application/json'} del body["_id"] del body["statusDate"] del body["createDate"] del body["lastModified"] del body["_class"] requests.request("POST", url=url, headers=headers, data=json.dumps(body)) query = { "service.srguServicePassportId": { "$in": ["5000000010000000897", "5000000000185430600", "5000000000186973891"] }, "claimCreate": { "$gte": Client.ISODate("2018-12-31T21:00:00.000+0000"),
from rldd.client import Client from rldd import config import datetime result_file = open('result.csv', 'w+') result_file.write(f"dbName;status\n") dbName_list = open('dbs.txt', 'r+').read().split("\n") for index, dbName in enumerate(dbName_list): db = Client(config.PROD).connect() remote = Client(config.REMOTE, dbName).connect() orgcard = remote["orgcard"].find_one() services = remote["services"].find({"serviceIdSrgu": {"$exists": True}}) if orgcard and services is not None: updater = { "oktmo": orgcard["oktmo"], "name": dbName, "shortName": orgcard["armsCaption"], "fullName": orgcard["shortName"], "email": orgcard["email"], "address": orgcard["address"], "phone": orgcard["phone"], "senderCode": orgcard["senderCode"], "srguServiceIds": [], "type": "MFC" if dbName.startswith("mfc") else "DEPARTMENT", "lastModified": datetime.datetime.now() - datetime.timedelta(hours=3) } for serv in services:
def getAddress(_id): _address = db["addresses"].find_one({"_id": Client.getId(_id)}) if "_class" in _address: del _address["_class"] return _address
from rldd.client import Client from rldd import config db = Client(config.PROD).connect() projection = { "_id": 1, "deadlineDate": 1, "docSendDate": 1, "customClaimNumber": 1 } result_file = open('claims_correct2.csv', 'w+') result_file.write("Номер заявления;Предыдущая дата;Дата сейчас\n") claims = db["claims"].find( { "activationDate": { "$gte": Client.ISODate("2020-10-01T21:00:00.000+0000"), "$lte": Client.ISODate("2020-11-26T21:00:00.000+0000") }, "resultStatus": { "$exists": True }, "service.srguServicePassportId": "5000000000167433775" }, projection) for claim in claims: ccn = claim["customClaimNumber"] claimId = claim["_id"] deadlineDate = claim["deadlineDate"] if claim["docSendDate"] > claim["deadlineDate"]: upd = db["claims"].update_one( {"_id": claimId}, {"$set": {
from rldd.client import Client from rldd.config import REMOTE dbList = Client(REMOTE, "").connect().list_database_names() result_file = open("departmentsChanges.csv", "w+") result_file.write(f"Наименование базы;Id документа;fullName;Изменено\n") def update_department(_depId, _db): _db["departments"].update_one({"_id": _depId}, {"$set": { "deptIdSrgu": "123" }}) for dbName in dbList: isCorrected = False if dbName.startswith("mfc") or dbName.startswith("omsu"): db = Client(REMOTE, dbName).connect() departments = db["departments"].find( {"fullName": "Органы местного самоуправления"}) for dep in departments: depId = dep["_id"] if "deptIdSrgu" in dep: if dep["deptIdSrgu"].strip() == "": update_department(depId, db) isCorrected = True result_file.write( f"{dbName};{depId};{dep['fullName']};{isCorrected}\n") else: result_file.write(
claimNum = row[2] result_data = { "statements._id": rs_id, "statements.internalNum": "", "orgName": "", "orgCode": "", "name": "", "statements.recordRequisites.recordNum": "", "whenClose": "", "guid_name": "" } client = pymongo.MongoClient("mongodb://*****:*****@10.50.109.227:27017/pvdrs") db = client["pvdrs"] doc = db["rs_appeal"].find_one({"statements._id": Client.getId(rs_id)}) if doc: appeal_id = doc["_id"] for state in doc["statements"]: if state["_id"] == Client.getId(rs_id): result_data["statements.internalNum"] = state["internalNum"] if "recordRequisites" in state: if "recordNum" in state["recordRequisites"]: result_data["statements.recordRequisites.recordNum"] = state["recordRequisites"]["recordNum"] event = doc["createEvent"]["performer"] orgName = event["orgName"] if "\n" in orgName: orgName = orgName.replace('\n', '') if "\r" in orgName:
def get_person(self): db = Client(config.DPS, "dps").connect() person = db["persons"].find_one({"_id": Client.getId(self.person_id)}) return person
from rldd.client import Client from rldd import config import csv dps = Client(config.DPS, "dps").connect() iteration = 0 with open('snilses.csv') as csvfile: snilses_list = list(csv.reader(csvfile, delimiter=';', quotechar='|'))[1434301:] for snils in snilses_list: iteration += 1 person = dps["persons"].find_one({"snils": snils[0]}) if person: personId = person["_id"] upd = dps["persons"].update_one( {"_id": personId}, {"$set": { "esiaAutorisation": True }}) print( f'{iteration}. {personId}, {upd.modified_count} / {upd.matched_count}' )
import csv import datetime from rldd.client import Client from rldd.config import PKPVD iteration = 0 db = Client(PKPVD, "pvdrs").connect() file_in = open('rm.csv', 'r+') file_out = open('rm_result.csv', 'w+', newline="") file_out.write( "Номер заявления;Наименование процедуры;Текущий статус;Наименование выдаваемого документа;Номер КУВД;Дата отправки на выдачу\n" ) csvReader = csv.reader(file_in, delimiter=";") for row in csvReader: iteration += 1 print(iteration) intNum = row[2] claim = db["rs_appeal"].find_one({"statements.internalNum": intNum}) if claim: name = claim["name"] statusNotePPOZ = claim["statusNotePPOZ"] statements = claim["statements"] for state in statements: if state["internalNum"] == intNum: stateId = state["_id"] numPPOZ = state["numPPOZ"] if "numPPOZ" in state else "" issuedDocs = list(db["rs_issued_document"].find({ "statementGuid": str(stateId), "name": {
import re from bson import InvalidBSON from rldd.client import Client from rldd import config import csv dps = Client(config.DPS, "dps").connect() prod = Client(config.PROD).connect() def get_attribute(doc, field): if field in doc: return doc[field] else: return '' def get_prefix(doc, field): if get_attribute(doc, field) != '': if f"{field}Prefix" in doc: if doc[f"{field}Prefix"].strip() != '': return f"{doc[field]} {doc[f'{field}Prefix']}" return get_attribute(doc, field) def get_contact(doc, *contact_types): contact_list = [] if "contacts" in doc: isFound = False
def getDoc(_id): _doc = db["docs"].find_one({"_id": Client.getId(_id)}) if "_class" in doc: del _doc["_class"] return _doc
from bson import InvalidBSON from rldd.client import Client from rldd.config import PROD, DEV db = Client(DEV).connect() query = { "activationDate": { "$gte": Client.ISODate("2020-09-01T00:00:00.000+0000") }, "docSendDate": { "$exists": True } } pjct = { "_id": 1, "deadlineDate": 1, "docSendDate": 1, "customClaimNumber": 1, "daysToDeadline": 1 } iteration = 0 total_count = db["claims"].count_documents(query) while True: try: claims = db["claims"].find(query, pjct).skip(iteration) for claim in claims: iteration += 1 claimId = claim["_id"] daysToDeadline = (claim["deadlineDate"] -
from rldd.client import Client from rldd import config replica = Client(config.replicaSET, "mfc-objects-replication").connect() replicaData = replica["dbs-info"].find({"dbType": "OMSU"}) iteration = 0 mfcUsersCount = 0 for rep in replicaData: dbName = rep["dbName"] remote = Client(config.REMOTE, dbName).connect() usersCount = remote["users"].count_documents( {"$or": [{ "isDeleted": False }, { "isDeleted": { "$exists": False } }]}) mfcUsersCount += usersCount print(mfcUsersCount)
from rldd import config from rldd.client import Client query = { "statusDate": { '$gte': Client.ISODate("2020-10-15T21:00:00.000+0000"), '$lte': Client.ISODate("2020-10-20T21:00:00.000+0000") }, "createDate": { '$gte': Client.ISODate("2020-09-22T21:00:00.000+0000"), '$lte': Client.ISODate("2020-09-23T21:00:00.000+0000") } } iteration = 0 count = 0 db = Client(config.PROD).connect() claims = db["claims_status_mku"].find(query, {"claimId": 1}) for data in claims: iteration += 1 isFound = False claimId = data["claimId"] claim = db["claims"].find_one({"_id": claimId}) if claim is None: continue ccn = claim["customClaimNumber"] if "deadlineStages" in claim: for index, stage in enumerate(claim["deadlineStages"]): if "stageName" in stage: if stage["stageName"] == "Корректировка срока":
import re from pymongo.errors import DuplicateKeyError from rldd.client import Client from rldd import config from concurrent.futures.thread import ThreadPoolExecutor from datetime import datetime from bson import ObjectId # from tests.dps.db_client import Client dps = Client(config.DPS, "dps").connect() rldd = Client(config.PROD, "rldd2").connect() def get_attribute(doc, field): if field in doc: return doc[field] else: return '' def get_prefix(doc, field): if get_attribute(doc, field) != '': if f"{field}Prefix" in doc: if doc[f"{field}Prefix"].strip() != '': return f"{doc[field]} {doc[f'{field}Prefix']}" return get_attribute(doc, field)
import csv from rldd.client import Client from rldd import config dps = Client(config.DPS, 'dps').connect()["persons"] db = Client(config.PROD).connect() res_file = open('data.csv', 'w+') iteration = 0 with open('data2.csv') as csv_file: file = csv.reader(csv_file, delimiter=',') for row in file: iteration += 1 personId = row[2] person = dps.find_one({"_id": Client.getId(personId)}) print(iteration, personId)
from rldd import config result_file = open('claims_result.csv', 'w+') result_file.write("customClaimNumber;statusDate\n") claims_list = open('claims.txt', 'r+').read().split('\n') iteration = 0 jop = { "_id": 1, "activationDate": 1, "customClaimNumber": 1, "resultStatus": 1, "docSendDate": 1 } db = Client(config.PROD).connect() claims = db["claims"].find( { "customClaimNumber": { "$in": claims_list }, "resultStatus": { "$exists": True }, "activationDate": { "$gte": Client.ISODate("2019-11-30T21:00:00.000+0000"), "$lte": Client.ISODate("2020-01-08T21:00:00.000+0000") }, "docSendDate": { "$lte": Client.ISODate("2020-01-27T21:00:00.000+0000") }
import pymongo from rldd.client import Client from rldd.config import PROD db = Client(PROD).connect() result_file = open("services.csv", "w+", newline="") result_file.write("Наименование услуги;Код процедуры\n") query = { "statusCode": "53", "statusDate": { "$gte": Client.ISODate("2019-01-01T00:00:00.000+0000") } } total_count = db["claims_status"].count_documents(query) statuses = db["claims_status"].find(query, no_cursor_timeout=True) serviceDict = {} iteration = 0 for status in statuses: iteration += 1 print(f"{iteration} / {total_count}") claimId = status["claimId"] statusesList = list(db["claims_status"].find({ "claimId": claimId }).sort("statusDate", pymongo.ASCENDING)) for index, statusElement in enumerate(statusesList): if statusElement["statusCode"] == "53": if len(statusesList) > index + 1: if statusesList[index + 1]["statusCode"] == "2": claim = db["claims"].find_one( {"_id": Client.getId(claimId)})
from rldd.client import Client from rldd import config import pymongo from datetime import datetime, timedelta db = Client(config.DEV).connect() claims = db["claims"].find().sort("activationDate", pymongo.DESCENDING).limit(100) for claim in claims: deadlineDate = claim["deadlineDate"] result_dict = { "createDate": datetime.now() - timedelta(hours=3), "previousDeadlineDate": deadlineDate - timedelta(days=2), "nextDeadlineDate": deadlineDate, "claimId": str(claim["_id"]) } db["claim_deadline_changes"].insert_one(result_dict)
from rldd.client import Client from rldd import config db = Client(config.PROD).connect() iteration = 0 query = { "activationDate": { "$gte": Client.ISODate("2019-12-31T21:00:00.000+0000"), "$lte": Client.ISODate("2020-12-03T21:00:00.000+0000") } } projection = { "_id": 1, "customClaimNumber": 1, "service.srguServiceId": 1, "service.srguServiceName": 1, "service.name": 1, "service.srguDepartmentId": 1, "service.srguDepartmentName": 1, "service.srguServicePassportId": 1, "service.srguServicePassportName": 1, } total_count = 11460885 claims = db["claims"].find(query, projection).limit(10000) for claim in claims: iteration += 1 print(f"{iteration} / {total_count}") ccn = claim["customClaimNumber"] if "srguServicePassportName" not in claim["service"]: print(ccn)
from rldd.client import Client from rldd import config db = Client(config.PROD).connect() names = [ "name", "srguServiceName", "srguDepartmentName", "srguServicePassportName" ] data_names = [ "customClaimNumber", "activationDate", ] result_file = open('nonames.csv', 'w+') query = {"activationDate": {'$gte': Client.ISODate("2019-12-31T21:00:00.000+0000")}, "oktmo": {'$ne': "99999999"}} projection = {"_id": 1, "customClaimNumber": 1, "activationDate": 1, "service": 1} claims = db["claims"].find(query, projection).limit(1000) def form_string_from_dict(diction: dict): result_string = "" for value in diction.values(): result_string += value + ';' return result_string[:-1] + "\n" def add_array_to_obj(obj, arr): for i in arr:
from rldd.client import Client from rldd import config db = Client(config.PROD).connect() projection = { "_id": 1, "customClaimNumber": 1, "deadlineDate": 1, "docSendDate": 1 } def setDeadlineToOneDay(query): claims = db["claims"].find(query, projection) for claim in claims: ccn = claim["customClaimNumber"] claimId = claim["_id"] deadlineDate = claim["deadlineDate"] if "docSendDate" in claim: upd = db["claims"].update_one( {"_id": claimId}, {"$set": { "docSendDate": deadlineDate, "daysToDeadline": 1 }}) print( f"Claim: {ccn}, progress: {upd.modified_count} / {upd.matched_count}" )
import pymongo from bson import InvalidBSON from rldd.client import Client from rldd import config corrected = 0 wrongs = open('wrongs.csv', 'w+') wrongs.write("claimId;customClaimNumber;Error\n") rights = open('rights.csv', 'w+') rights.write( "claimId;customClaimNumber;FirstStatusDate;DocSendDate;Deadline correct\n") db = Client(config.PROD).connect() iteration = 0 isDead = False projection = { "_id": 1, "activationDate": 1, "customClaimNumber": 1, "deadlineDate": 1, "docSendDate": 1 } while True: try: claims = db["claims"].find( { "docSendDate": { "$exists": True }, "senderCode": { "$ne": "RRTR01001"