-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathuploadproductsdata.py
112 lines (81 loc) · 3.38 KB
/
uploadproductsdata.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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# - *- coding: utf- 8 - *-
import asyncio
import os
import csv
from datetime import datetime
#import requests
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from aiogram import Bot, types, Dispatcher
from aiogram.types import FSInputFile
#from tgbot.services.api_sqlite import get_position_of_day
API_TOKEN = '5337905343:AAFnZEexDdOAhn16AEw1zofEzVrPPEag89Q'
#API_TOKEN = '5337905343:AAFnZEexDdOAhn16AEw1zofEzVrPPEag89Q'
CHANNEL_ID = 919148970
bot = Bot(token=API_TOKEN) #ParseMode. parse_mode=HTML
dp = Dispatcher()
positions = []
'''def send_photo_tb(photo):
#with FSInputFile(photo) as photo:
#with open('uploadproductdata/' + position['Photo'], 'rb') as photo:
with open(photo, 'rb') as photo:
id_photo = bot.send_photo(CHANNEL_ID, photo, disable_notification=True)
idp = id_photo['photo'][-1]['file_id']
@dp.message(content_types=['photo'])
def scan_message(message: types.Message):
document_id = message.photo[0].file_id
file_info = bot.get_file(document_id)
print(f'file_id: {file_info.file_id}')
print(f'file_path: {file_info.file_path}')
print(f'file_size: {file_info.file_size}')
print(f'file_unique_id: {file_info.file_unique_id}')
return file_info.file_id'''
# Отправка рассылки
def function_sendphoto(message, caption='test', ct='photo'):
try:
print("||||")
if ct == "text":
bot.send_message(user['user_id'], message, disable_web_page_preview=True)
elif ct == "photo":
with open(message, 'rb') as photo:
bot.send_photo(chat_id=CHANNEL_ID, photo=photo, caption=caption or None)
print("|||")
file_id = message.photo[0].file_id
print(file_id)
except Exception:
pass
fieldnames = ["Cat1", "Cat2", "Code", "Art", "Name", "Price", "Weight", "WeightType", "Description", "photo"]
with open("uploadproductdata/data4.csv", encoding='UTF-8') as f:
rows = csv.reader(f,delimiter=",",lineterminator="\n")
next(rows, None)
for row in rows:
position = {
'Cat1': row[0],
'Cat2': row[1],
'Code': row[2],
'Art': row[3],
'Name': row[4],
'Price': row[5],
'Weight': row[6],
'WeightType': row[7],
'Description': row[8],
'Photo': row[9],
}
#photo = open("uploadproductdata/" + str(row[9]), 'rb')
photo = f"uploadproductdata/{str(row[9])}"
#photo=open(photof, 'rb')
function_sendphoto(photo, "test", "photo")
#idp = send_photo_tb('uploadproductdata/' + position['Photo'])
#photof = FSInputFile('uploadproductdata/' + str(row[9])
#id_photo = bot.send_photo(chat_id=CHANNEL_ID, photo=photo) # этот метод поможет получить file_id
#idp = id_photo['photo'][-1]['file_id'] #
#with open(photof, 'rb') as photo:
#bot.send_photo(chat_id=chat_id, photo=open(photof, 'rb'))
#id_photo = bot.send_photo(CHANNEL_ID, photof, disable_notification=True)
#filef_id = message.photo[-1].file_id
#bot.send_photo(chat_id=chat_id, photo=file_id)
#idp = id_photo['photo'][0]['file_id']
#print(filef_id)
#send_photo_tb(position['Photo'])
#position['PhotoUrl'] = scan_message()
print(position)
positions.append(position)