G
G
guruvan_damm2021-06-08 10:29:14
Python
guruvan_damm, 2021-06-08 10:29:14

Automatic upload to telegram. How to do?

Hello! I wrote the code for calling via API and uploading the number of completed chats by each agent.

Purpose: automatically upload the results for the current day to the telegram channel every day at 00:00. For example, on 06/09/2021 at 00:00 the upload is sent for 'updated_before': '2021-06-09 00:00' and 'updated_after': '2021-06-08 00:00'
How to set it to automatic upload? And how can I make sure that the updated_before and updated_after values ​​are automatically changed to the required ones?

Now the result of running the program looks like this:

{'Catherine': 96, 'Margarita': 120, 'Maria': 213, 'Olga M.': 197, 'Daria': 225, 'Valeria': 112, 'Anastasia L. ': 242, 'Sofya': 106, 'Marina': 43, 'Artem': 1, '

import requests
import time


def take_all_chats():
    token = "ТОКЕН"
    offset = 0
    all_tickets = []

    while offset < 20:
        responce = requests.get('МЕТОД',
                                params={
                                    'api_token': token,
                                    'updated_before': '2021-06-08 00:00',
                                    'updated_after': '2021-06-07 00:00',
                                    'fstatus': '3',
                                    'fchannel': '25222',
                                    'offset': offset
                                })
        data = responce.json()
        offset += 1
        all_tickets.extend(data)
        time.sleep(1)

    values_per_key = {}

    for d in all_tickets:
        for k, v in d.items():
            if k == "assignee_id":
                if not values_per_key.get(v):
                    values_per_key[v] = 1
                else:
                    values_per_key[v] += 1

    replacemenets = {182004: 'Анастасия', 182870: 'Анастасия Л.', 176964: 'Артем', 186124: 'Артур', 184839: 'Валентина',
                     186484: 'Валерия', 181999: 'Владислав', 187229: 'Дария', 186486: 'Дарья', 182239: 'Екатерина',
                     186488: 'Екатерина П.', 186483: 'Елизавета', 187732: 'Людмила', 186485: 'Маргарита',
                     184335: 'Марина', 184002: 'Мария', 182753: 'Ольга', 182869: 'Ольга М.', 182007: 'Софья',
                     182008: 'Татьяна', 182005: 'Юлия'}

    for i in list(values_per_key):
        if i in replacemenets:
            values_per_key[replacemenets[i]] = values_per_key.pop(i)

    all_tickets_per_day = sum(values_per_key.values())
    print(values_per_key)
    print(all_tickets_per_day)


take_all_chats()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question