# your code goes here
import requests
from bs4 import BeautifulSoup
import time
from random import randint 

def lineNotifyMessage(token, msg):
    headers = {
          "Authorization": "Bearer " + token, 
          "Content-Type" : "application/x-www-form-urlencoded"
      }
    payload = {'message': msg}
    r = requests.post("https://n...content-available-to-author-only...e.me/api/notify", headers = headers, params = payload)
    return r.status_code

token = 'my token'
message = '有票RRR'
URL = "https://w...content-available-to-author-only...t.cc/bbs/Drama-Ticket/index.html"
lastOne = ""

while True:
    response = requests.get(URL)
    soup = BeautifulSoup(response.text, 'html.parser')
 
    titles = soup.find_all('div', {'class': 'title'})
    
    for title in titles[-5::-1]:       
        if title == lastOne:
            break
       
        if '五月天' in title.text and '售' in title.text:
            lineNotifyMessage(token,message+title.text)
            print(title.text)

    lastOne = titles[-5]

    waiting_times = 30+randint(0,40)
    print(waiting_times)
    time.sleep(waiting_times)
