-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_workers.py
More file actions
65 lines (57 loc) · 2.13 KB
/
Copy pathmain_workers.py
File metadata and controls
65 lines (57 loc) · 2.13 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from uploader import Image_Upload
from config import BASE_PATH
import requests
import json
import os
import re
def Sort_Files(onlyFiles):
"""
Сортировка файлов по числам в названии,
если есть хоть один непронумированный файл,
сортировка будет пропущена
"""
try:
onlyFiles.sort(key=lambda file: int(
''.join(re.findall('\d+', file.partition('.')[:1][0]))))
except:
pass
def Send_Title(title_name, Postmen_data):
Files_Names = Get_Files_Names(title_name)
Files_urls = []
senders = []
for file in Files_Names:
senders.append(Image_Upload.delay(title=title_name, file=file))
for sender in senders:
sender.wait(timeout=None, interval=0.5)
if sender.get() == 'None':
print('Fail')
Files_urls.append({'tag': 'img', 'attrs': {'src': sender.get()}})
return Send_Post(title_name, Files_urls, postmen_data=Postmen_data)
def Get_Files_Names(title, subtitle=None):
'''
Возвращает отсортированный список названий файлов
(subtitle - недопиленная система мульти-пакетного обработчика)
'''
if subtitle == None:
osDir = f"{BASE_PATH}{title}/"
else:
osDir = f"{BASE_PATH}{title}/{subtitle}/"
onlyFiles = [f for f in os.listdir(
osDir) if os.path.isfile(os.path.join(osDir, f))]
try:
onlyFiles.remove('.DS_Store')
except:
pass
Sort_Files(onlyFiles)
return onlyFiles
def Send_Post(title_name, content, postmen_data):
'''
Создание поста
на вход получает:
postmen_data - первичные данные с токеном
content и title_name - набор ссылок на файлы и название поста(тайтла)
'''
postmen_data['title'], postmen_data['content'] = title_name, content
create_page = requests.post(
'https://api.telegra.ph/createPage?', json=postmen_data)
return json.loads(create_page.content)