Дополнительно
Добавить в избранноеSabir
Местный
Скрипт на Python для уведомления о новых платежах Qiwi в Telegram.
В файле qiwiConfig все настраиваем (сами поймете, там комменты оставил)
В файле qiwiConfig все настраиваем (сами поймете, там комменты оставил)
Скрытое содержимое доступно для зарегистрированных пользователей!
Python:
# {0} - ID транзакции в сервисе QIWI Кошелек.
# {1} - Номер отправителя.
# {2} - Дата/время платежа.
# {3} - Данные о сумме пополнения.
# {4} - Комментарий к платежу.
TEXT = 'Пришёл платеж от {1} на сумму {3}.\nДата/время платежа: {2}.\n\n' # Текст сообщения. Пример: Пришёл платеж от {1} на сумму {3}.\nДата/время платежа: {2}.\n\n
# {0} - Дата/время.
# {1} - Список платежей. (TEXT)
# {2} - Выводит баланс.
SEND_TEXT = 'Список пополнений за {0}:\n\n{1}\nБаланс: {2}' # Текст отправки сообщения. (USER_IDS)
LIST_IN = 10 # Число пополнений. От 1 до 50. Рекомендуется: 10.
TIME_SLEEP = 60 # Время через которое нужно проверить все пополнения (секунды). Рекомендуется: 60 секунд.
# QIWI
QIWI_TOKEN = ' ' # Ключ доступа от аккаунта.
QIWI_LOGIN = ' ' # Логин от аккаунта.
# TELEGRAM
TELEGRAM_TOKEN = ' ' # Ключ доступа от бота
USER_IDS = [ ] # Список пользователей которым будет приходить уведомление. Пример [12345678, 1].
Python:
import time
from datetime import datetime
import pytz
import requests
import qiwiConfig
# ╔══╗─╔╗╔╗╔═══╗╔═══╗╔══╗╔══╗╔╗
# ║╔╗║─║║║║║╔══╝║╔═╗║║╔╗║║╔╗║║║
# ║╚╝╚╗║║║║║║╔═╗║╚═╝║║║║║║║║║║║
# ║╔═╗║║║║║║║╚╗║║╔══╝║║║║║║║║║║
# ║╚═╝║║╚╝║║╚═╝║║║───║╚╝║║╚╝║║╚═╗
# ╚═══╝╚══╝╚═══╝╚╝───╚══╝╚══╝╚══╝
def qiwi_balance():
s = requests.Session()
s.headers['authorization'] = 'Bearer ' + qiwiConfig.QIWI_TOKEN
h = s.get('https://edge.qiwi.com/funding-sources/v2/persons/' + qiwiConfig.QIWI_LOGIN + '/accounts')
return h.json()
def payment_history():
s = requests.Session()
s.headers['authorization'] = 'Bearer ' + qiwiConfig.QIWI_TOKEN
parameters = {'rows': qiwiConfig.LIST_IN, 'operation': 'IN'}
h = s.get('https://edge.qiwi.com/payment-history/v2/persons/' + qiwiConfig.QIWI_LOGIN + '/payments', params=parameters)
return h.json()
def telegram_request(method, argument):
s = requests.Session()
h = s.get('https://api.telegram.org/bot' + qiwiConfig.TELEGRAM_TOKEN + '/' + method, params=argument)
return h.json()
def send_message(chat_id, text):
telegram_request('sendMessage', {'chat_id': chat_id, 'text': text})
def main():
sum_time_sleep = qiwiConfig.TIME_SLEEP + (qiwiConfig.TIME_SLEEP / 2)
history_temp = []
while True:
moscow_datetime = datetime.now(pytz.timezone('Europe/Moscow')).strftime('%Y-%m-%d %H:%M:%S')
moscow_unix_time = int(time.mktime(time.strptime(moscow_datetime, '%Y-%m-%d %H:%M:%S')))
history = payment_history()['data']
payments_temp = ''
for payment in history:
payment_datetime = datetime.strptime(payment['date'], '%Y-%m-%dT%H:%M:%S%z').strftime('%Y-%m-%d %H:%M:%S')
payment_unix_time = int(time.mktime(time.strptime(payment_datetime, '%Y-%m-%d %H:%M:%S')))
sum_time = moscow_unix_time - payment_unix_time
if payment['status'] == 'SUCCESS' and payment['txnId'] not in history_temp and sum_time <= sum_time_sleep:
if len(history_temp) >= qiwiConfig.LIST_IN:
history_temp = []
history_temp.append(payment['txnId'])
if payment['account'] is None or payment['account'] == '' or payment['account'] == '+' + qiwiConfig.QIWI_LOGIN:
payment['account'] = '[Другой способ оплаты]'
if payment['comment'] is None:
payment['comment'] = ''
payments_temp += qiwiConfig.TEXT.format(
payment['txnId'],
payment['account'],
payment_datetime,
payment['sum']['amount'],
payment['comment'])
if payments_temp != '':
balance = qiwi_balance()['accounts'][0]['balance']['amount']
for user in qiwiConfig.USER_IDS:
send_message(user, qiwiConfig.SEND_TEXT.format(moscow_datetime, payments_temp, balance))
time.sleep(1)
time.sleep(qiwiConfig.TIME_SLEEP)
if __name__ == '__main__':
print('Made by BUGPOOL with love.')
main()



