【问题标题】:Guys, How can I send a new post on a website as a whatsapp message?伙计们,我怎样才能在网站上以 whatsapp 消息的形式发送新帖子?
【发布时间】:2023-02-12 18:36:58
【问题描述】:

对于这个网站上写的每一行新文章,我想在这里将新文章作为消息发送到 whatsapp http://www.koeri.boun.edu.tr/scripts/lst1.asp

chatgpt给我的代码如下,但是我想将网站上的新行作为消息发送到地方(XXX)

【问题讨论】:

    标签: python twilio whatsapp


    【解决方案1】:
    import requests
    
    import time
    
    import hashlib
    
    
    def send_whatsapp_message(message):
    
        account_sid = 'ACOUNT SID'
        auth_token = 'AUTH TOKEN'
        group_id = "whatsapp:ID"
        url = f"https://api.twilio.com/2010-04-01/Accounts/{'AUTH TOKEN'}/Messages.json"
    
        payload = {
            "From": f"whatsapp:{group_id}",
            "To": f"whatsapp:{group_id}",
            "Body": message
        }
    
        response = requests.post(url, auth=(account_sid, auth_token), data=payload)
    
        if response.status_code != 201:
            print(f"Error sending message: {response.text}")
            return False
        
        return True
     
     
    
    
    def check_for_new_posts(previous_posts_hash):
        # Get the HTML content of the website
        response = requests.get("http://www.koeri.boun.edu.tr/scripts/lst9.asp")
        html_content = response.text
    
        # Hash the HTML content to compare with previous hash
        current_posts_hash = hashlib.sha256(html_content.encode()).hexdigest()
        if current_posts_hash != previous_posts_hash:
            send_whatsapp_message("XXX") #<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=<=
            return current_posts_hash
        
        return previous_posts_hash
    
    previous_posts_hash = ""
    while True:
        previous_posts_hash = check_for_new_posts(previous_posts_hash)
        time.sleep(60)  # wait for 60 seconds before checking again
    

    【讨论】:

      猜你喜欢
      • 2011-01-02
      • 1970-01-01
      • 2012-12-25
      • 1970-01-01
      • 2021-03-17
      • 2016-11-03
      • 2022-01-21
      • 1970-01-01
      • 2018-10-25
      相关资源
      最近更新 更多