pythonpython-3.xautomationrssifttt

Parse new URL into IFTTT


The RSS reader in IFTTT doesn't like https://rss.art19.com/the-daily. I am using python to extract a new link and schedule it for every morning at 06:30. I, however, find it extremely difficult to parse a new url into an IFTTT applet. I am using glitch.com to combine events.

The point is to automatically play this podcast at 06:30 on my Sonos setup.

import schedule
import time
from bs4 import BeautifulSoup
import requests


def job():
    url = 'https://rss.art19.com/the-daily'
    request = requests.get(url)
    respose = request.content.decode('utf-8')
    soup = BeautifulSoup(respose, 'lxml')

    link = soup.find_all('enclosure')[0]

    a = str(link).split(' ')[3]
    x = slice(a)
    y = str(x).split('"')[1]

    print(y) 



# def notification(message):
#  report = {}
#  report[“value1”] = message
#  requests.post('https://maker.ifttt.com/trigger/play_sonos/with/key/KEY", data=report')

# notification(number)

schedule.every().day.at("06:30").do(job,'It is 06:30am')
print('\n')
print(' Got it')

while True:
    schedule.run_pending()
    time.sleep(60)

Solution

  • I ended up using the SOCO Library.

    from soco import SoCo
    import schedule
    import time
    from bs4 import BeautifulSoup
    import requests
    
    #Play5
    five_son = SoCo('PLAYER_IP')
    
    #Play5(Office)
    five_office_son = SoCo('PLAYER_IP')
    
    #Play3
    three_son = SoCo('PLAYER_IP')
    print( 'Players are Active! ')
    print('\n')
    
    
    def get():
        url = 'https://rss.art19.com/the-daily'
        request = requests.get(url)
        respose = request.content.decode('utf-8')
        soup = BeautifulSoup(respose, 'lxml')
    
        link = soup.find_all('enclosure')[0]
    
        a = str(link).split(' ')[3]
        x = slice(a)
        y = str(x).split('"')[1]
    
        return y
    
    def job():  
        sonos = five_office_son.partymode()
        sonos.play_uri(get())
    
        track = sonos.get_current_track_info()
    
        print(track)
    
        sonos.pause()
        sonos.play()
    
    
    schedule.every().monday.at("06:30").do(job,'It is 06:30am')
    schedule.every().tuesday.at("06:30").do(job,'It is 06:30am')
    schedule.every().wednesday.at("06:30").do(job,'It is 06:30am')
    schedule.every().thursday.at("06:30").do(job,'It is 06:30am')
    schedule.every().friday.at("06:30").do(job,'It is 06:30am')
    print('\n')
    print('Got it')
    
    while True:
        schedule.run_pending()
        time.sleep(60)