M
M
Maxim2020-10-03 11:52:39
css
Maxim, 2020-10-03 11:52:39

How to extract the necessary data from the text?

I am writing a script to automate checking the validity of UTM keys (EGAIS),
the problem is to extract data from the UTM response

Text

[
[
  Version: V3
  Subject: CN=Фамилия Имя Отчество, SURNAME=Фамилия, GIVENNAME=Имя Отчество, C=RU, ST=23 Регион, L=Город, STREET=ул. улица д. 00, OID.0.0.000.000.0=#00000000000000000000000000, OID.0.0.000.000.0=#00000000000000000000000000, [email protected], OID.0.0.000.000.0=#00000000000000000000000000
  Signature Algorithm: 0.0.000.0.0.0.0.0, OID = 0.0.000.0.0.0.0.0

  ...не нужные данные...

  Validity: [From: Thu Oct 10 09:45:58 MSK 2019,
               To: Sat Oct 10 09:55:58 MSK 2020]
  Issuer: CN="ООО \"РОГА И КОПЫТА\"", O="ООО \"РОГА И КОПЫТА\"", STREET=ул. улица д. 00, L=Город, ST=23 Регион, C=RU, OID.0.0.000.000.0=#00000000000000000000000000, OID.0.0.000.000.0=#00000000000000000000000000, [email protected]
  SerialNumber: [    00000000 00000000 0000]

...не нужные данные...

]
]


I want to extract CN, SURNAME, GIVENNAME, ST, L, STREET from an individual and the expiration date of the key
, please help with this.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dima, 2016-01-05
@Odinokun

This is Particles.JS vincentgarreau.com/particles.js as far as I know

D
Deodatuss, 2016-01-05
@Deodatuss

don’t use it, this “spider line” will soon overtake the miserable combed snowflakes in use, it is everywhere, really everywhere, it already twitches the eye

S
seriogja, 2016-01-05
@seriogja

Something tells me that you can see such an effect on this site :) I even have such a habit: I liked the site - I'll look into the console :) Open the console, find the file that "connects" the animation, then study the code itself or look for sources on the Internet (as a rule, they are indicated in the license).

V
Vladimir Kuts, 2020-10-03
@maxpointn2point

text = '''
  Version: V3
  Subject: CN=Фамилия Имя Отчество, SURNAME=Фамилия, GIVENNAME=Имя Отчество, C=RU, ST=23 Регион, L=Город, STREET=ул. улица д. 00, OID.0.0.000.000.0=#00000000000000000000000000, OID.0.0.000.000.0=#00000000000000000000000000, [email protected], OID.0.0.000.000.0=#00000000000000000000000000
  Signature Algorithm: 0.0.000.0.0.0.0.0, OID = 0.0.000.0.0.0.0.0

  ...не нужные данные...

  Validity: [From: Thu Oct 10 09:45:58 MSK 2019,
               To: Sat Oct 10 09:55:58 MSK 2020]
  Issuer: CN="ООО \"РОГА И КОПЫТА\"", O="ООО \"РОГА И КОПЫТА\"", STREET=ул. улица д. 00, L=Город, ST=23 Регион, C=RU, OID.0.0.000.000.0=#00000000000000000000000000, OID.0.0.000.000.0=#00000000000000000000000000, [email protected]
  SerialNumber: [    00000000 00000000 0000]

...не нужные данные...
'''

for line in text.split('\n'):
    if 'Subject' in line:
        a = [x.split('=') for x in line.split(':')[1].split(',')]
        data = dict(zip([x[0].strip() for x in a], [x[1].strip() for x in a]))

print('CN> ', data['CN'])
print('SURNAME> ', data['SURNAME'])

CN> Surname First Name Patronymic
SURNAME> Surname

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question