电报漫游器无法向网上论坛发送相同的消息

时间:2019-11-13 14:24:40

标签: python telegram

我制作了一个脚本,将从NASA API中获取的一些信息发送到Telegram中的一个小组。我做了一个机器人,但只能发送一次信息。我无法再发送相同的消息。在代码中,我做了一个临时变量k,如果我更改了一个字符串,它将被发送。我的主要讯息漫游器仅发送了一次,现在没有发送。 有人的建议吗?

import json
import requests
import requests_cache
import schedule

from mars_api import NASA_API_KEY as nasa_key
from mars_api import BOT_TOKEN as bot_token
from mars_api import bot_chatID

# from mars_api import TELEGRAM_API_KEY as telegram_key

requests_cache.install_cache('mars_cache')


class MarsDataLoader:

    def __init__(self,nasa_key):

        self.nasa_key = nasa_key
        data_from_nasa_api = requests.get(f'https://api.nasa.gov/insight_weather/?api_key={nasa_key}&feedtype=json&ver=1.0')
        content = data_from_nasa_api.json()
        self.content = content 

class DayAtMars(MarsDataLoader):

    def __init__(self, content):
        self.today = content['sol_keys'][0]
        self.temperature_on_mars = content[self.today]['AT']['av']
        self.speed_of_wind_on_mars = content[self.today]['HWS']['av']
        self.pressure_on_mars = content[self.today]['PRE']['av']

    def create_weather_on_mars_information(self,):
        massage =f'''Goood morning! Today is going to be sunny day on Elysium Platinia. There will be no clouds. 
        Temperature outside: {self.temperature_on_mars}, light wind with {self.speed_of_wind_on_mars} m/s. Air pressure is {self.pressure_on_mars} Pa. 
        Unfortunately there is still no chance to survive outside on Mars. So brace yourself 
        and prepare for another beautifull day on Earth. In case you ARE on Mars... so sunny 
        weather but still you are in a deep shit if you are outside without a spacesuit on.'''
        return massage

k = 'harrrrry'

def telegram_send_text_massage(massage, bot_token, bot_chatID):

    send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + massage

    response = requests.get(send_text)

    return response.json()

if __name__ == '__main__':
    data_from_nasa_api = MarsDataLoader(nasa_key)
    day_at_mars = DayAtMars(data_from_nasa_api.content)
    current_condition_on_mars = day_at_mars.create_weather_on_mars_information()
    print(type(current_condition_on_mars))
    print(type(k))
    telegram_send_text_massage(k,bot_token,bot_chatID)
    telegram_send_text_massage(current_condition_on_mars,bot_token,bot_chatID)

https://github.com/bartoszkobylinski/mars_weather_notification

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题。因为我使用了库request_cache,所以我认为那是将响应存储在那里。我已将其删除,现在可以正常工作了!无论如何,谢谢答案

相关问题