S
S
Samad_Samadovic2021-06-02 15:06:16
Python
Samad_Samadovic, 2021-06-02 15:06:16

How can I write text (which is contained in a text file) in NoSql (In order)?

Here is the file (abbreviated):
KP Provider Delphi 7.0 900+
Program Test program (version 1) Delphi 7.0 1000
Program Test program (version 2) Delphi 7.0 1400
Program Test program (version 3) Delphi 7.0 1400
WRC Control program homeowners (HOA) Delphi 7.0 2400+
KP The program for generating lists "Accounting" Delphi 7.0 1600+
Program A program in which, when hovering over the text, a word (color) is highlighted and its decoding is shown Delphi 7.0 1550
KP Designing a database "Warehouse accounting" Delphi 7.0 1200+
KP Designing a database for Delphi news agency 7.0 1400+
Program Designing an information system module for stimulating pedagogical activities Delphi 7.0 1800
KP Bicycle rental and sale (Delphi XE3) Delphi XE3 1500+
KP Psychological test (database + graphics) Delphi 7.0 800+
Program Psychological test. Psychological climate in the team Delphi 7.0 1000+
WRC Development of automated accounting for services provided by MCU SOK "Zhemchuzhina" Delphi 7.0 1550+
KP Development of an automated information system for inventory control of goods on the example of the MasterOK store Delphi 7.0 1600+
WRC Development of an automated information system for working with clients (on the example of TEK JSC) Delphi 7.0 2200+
WRC Development of an automated accounting system for electrical equipment of OJSC "Mosvodokanal" Delphi 7.0 2200+
WRC Development of AIS for training and knowledge control on the basics of working in MS Excel 2007 (Delphi + MS SQL Server) Delphi 7.0 3000+
KP Development of a database and a software interface for automating the accounting of computer, office equipment and components Delphi 7.0 2800+
KP Development of an information system to ensure acceptance tests of the unit Delphi 7.0 2000+
KP Development of a bank client accounting program Delphi 7.0 1000+
Program Schedule for the week Delphi 7.0 3600
VKR Vacation schedule for medical staff (Delphi + Access ) Delphi 2007-201x 1400+
KP Calculation of indicators of consumption and income distribution of the population Delphi 7.0 900+
Program Sound editor Delphi 7.0 600
Program Rating of students Delphi 7.0 1800
KP Computer repair (Delphi + MS Access database) new Delphi 7.0 1110+
KP Car dealership automation system (Delphi + MS SQL Server ) Delphi 7.0 500
KP System for storing and issuing information about goods (Delphi + Access) Delphi 7.0 1110+
KP System for selecting real estate for exchange Delphi 7.0 800+
KP Job search system (Delphi + Access) Delphi 7.0 1500+
KR Taxi service (Delphi + DBMS Access) Delphi 7.0 500
KP Creating and maintaining a database of college applicants (Delphi + Access) Delphi 7.0 600+
KP Creating and maintaining a movie lover database (Delphi + MS SQL SERVER) Delphi 7.0 900
KP Creating and maintaining a database for the sale of goods on credit (Delphi + MS SQL Server) Delphi 7.0 800+
KP Creating and maintaining an airline reservation database (Delphi 7 + MS SQL SERVER 2008) Delphi 7.0 2000
LR Creation of a reference system for the Film Archive Delphi 7.0 700
Program for scheduling classes in a gymnasium Delphi 7.0 2600
KP Reference system for standard functions Turbo Pascal Delphi 7.0 600+
KR Geographer's reference book Delphi 7.0 900+
KP Telephone directory Delphi 7.0 800+
KP Telephone directory using object-oriented programming technology (OOP) Delphi 7.0 1000+
KP Terminology. Definition base of any science (mathematics): the term to be entered, its interpretation (define Delphi 7.0 400+
LR Test "Capitals of the World" Delphi 7.0 200
Program Test in the traffic police (Interbase, DBExpress, 3-level access, DCOM) Delphi 7.0 1200
Program Test for knowledge of Turbo Pascal language operators, a guide to Pascal language operators Delphi 7.0 600
CP Test in kinematics (DBMS Access) Delphi 7.0 1200+
CP Testing (testing students' knowledge of information technology) Delphi 7.0 1000+
CP Testing in computer science Delphi 7.0 800+
Program Human Testing on IQ and MMPI Tests Delphi 7.0 1000
CP Travel Agency (version 2) (SQL Server 2000) Delphi 7.0 800+
KP Travel agency (Arm of the travel agency manager, AIS of the travel agency) (ADO + Access) Delphi 7.0 1600+
WRC Warehouse management at the enterprise OJSC "Neftekamsk Automobile Plant" Delphi 7.0 4840+
KP Accounting for all fish in the country Delphi 7.0 700+
KP Accounting for citizens in need of better housing conditions (Access) Delphi 2010 (Rad Studio) 890+
KR Accounting for animals in the zoo (Delphi + ADO + Access) Delphi 7.0 500
KP Accounting and distribution of goods by couriers in the online store Delphi 7.0 980
WRC Accounting for personnel at the enterprise Delphi 7.0 2200+
KP Accounting for personnel of the university and its divisions Delphi 7.0 1780+
Program Accounting for clients and services of the photo studio Delphi XE 1780
KP Accounting for computers and components at the enterprise Delphi 7.0 890
WRC Accounting for material assets (Delphi + ADO + Access) Delphi 7.0 900+
KP Accounting for receipts and sales of goods in OOO "Gefest" Delphi 7.0 900
Program Accounting for work and events for the dispatcher of the public utility Delphi 7.0 1900
KP Accounting for the consumption of components at the enterprise Delphi 7.0 1600 +
KP Accounting for the consumption of materials used in the production of products Delphi 7.0 1800+
KP Accounting for expenses (for housewives) Delphi 7.0 1200+
KP Accounting for the sale of dairy products (formation of a statement of drivers) Delphi 7.0 400+
KP Accounting for equipment at the enterprise Delphi 7.0 1000+
KP Accounting software Delphi 7.0 1400
Program Formation of the psychological characteristics of the student (in Word) Delphi 7.0 1900
Photoalbum program Delphi 7.0 500
KP Photocentric Delphi 7.0 1550
KP EIS for cost accounting for production of products (ADO + Access) Delphi 7.0 800+
WKR EIS for customer service support Delphi 7.0 2200
KP EIS for accounting for travel services to corporate clients (Delphi+MySQL) Delphi 7.0 1000
KP Expert assessment. Ranking (graphs, ADO, Access) Delphi 7.0 1400+
CP Expert system "Determining the solvency of a bank client to provide a loan" new Delphi 7.0 880+
CP Expert system (Delphi + ADO + Access) Delphi 7.0 2000+
Program Expert system for people search Delphi 7.0 600
Program Export data from a table to Excel Delphi 7.0 960
Program Electronic record book Delphi 7.0 1800 WQR
Electronic archive of documents (Interbase) Delphi 7.0 1400+
KP Electronic archive of documents on Delphi + Interbase Delphi 7.0 2500+
KP Electronic diary Delphi 7.0 2200+
WQR Electronic educational school journal of the teacher Delphi XE 2990+

And the question is to extract everything in json and write it to Nosql (MongoDB) (And there are only 5 columns)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Danil Gorev, 2021-06-02
@Samad_Samadovic

The file, alas, in this form is not parsed in a logical way, so it cannot be divided into reasonable objects.
You can simply load line by line, through with open readline, adding id's.
How to work with PyMongo can be read in the documentation: https://pymongo.readthedocs.io/en/stable/

M
maybebaby, 2021-06-02
@maybebaby

Let's assume that your data is in the file file.txt, and MongoDB is running on the same machine (locally), the script is extremely simple:

import pymongo

# Создаем клиент MongoDB
client = pymongo.MongoClient()
# Название БД
db = client['univercity']
# Название коллекции
collection = db['courseworks']

# Открываем файл
with open('file.txt') as file:
    # Читаем строки из файла в переменную
    lines = [line.strip() for line in file.readlines()]

# Проходим по каждой строке
for line in lines:
    # Делим строку на слова
    words = line.split()
    # Извлекаем столбцы
    a, b, c, d, e  = words[0], ' '.join(words[1:-3]), words[-3], words[-2], words[-1]
    # Вставляем документ в базу Монго
    collection.insert_one({
        "type":    a,
        "text":    b,
        "lang":    c,
        "version": d,
        "value":   e
        })

In the mongo shell, you can check the logged data:
> use univercity
switched to db univercity
> db.courseworks.find()
{ "_id" : ObjectId("60b77e2c9fa82c54395b405e"), "type" : "КП", "text" : "Провайдер", "lang" : "Delphi", "version" : "7.0", "value" : "900+" }
{ "_id" : ObjectId("60b77e2c9fa82c54395b405f"), "type" : "Программа", "text" : "Программа для тестирования (версия 1)", "lang" : "Delphi", "version" : "7.0", "value" : "1000" }
{ "_id" : ObjectId("60b77e2c9fa82c54395b4060"), "type" : "Программа", "text" : "Программа для тестирования (версия 2)", "lang" : "Delphi", "version" : "7.0", "value" : "1400" }

R
Romses Panagiotis, 2021-06-02
@romesses

You can break strings into their component parts using regular expressions.
Here, a partial version for the seed:
/(Delphi\s\S+)\s(\S+\+?)$/gm
where are the pair of Delphi XE and 2990+
The rest is self.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question