-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex.py
28 lines (23 loc) · 1.05 KB
/
ex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os, re
docid, title, author, created, topic, tagging = [],[],[],[],[],[]
def files_in_dir(): #список файлов в дир.
return os.listdir()
def change_dir(dir_name): #меняет директорию
os.chdir(dir_name)
def opn(name):
with open(name, encoding='windows-1251') as f:
text = f.read()
return text
def find_inf(file_names):
for file in file_names:
global docid, title, author, created, topic, tagging
txt = opn(file)
docid.extend(re.findall(r'\<meta\scontent=\"([\w0-9\.]+)\"\sname=\"docid', txt))
author.extend(re.findall(r'\<meta\scontent=\"([а-яА-Я\s]+)\"\sname=\"author', txt))
created.extend(re.findall(r'\<meta\scontent=\"([0-9\.]+)\"\sname=\"created', txt))
topic.extend(re.findall(r'\<meta\scontent=\"([\,\s\w]+)\"\sname=\"topic', txt))
tagging.extend(re.findall(r'<meta\scontent=\"(\w+)\"\sname=\"tagging', txt))
title.extend(re.findall(r'\<title\>([^\<]+)', txt))
def main():
change_dir('news')
find_inf(files_in_dir())