-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathradio.py
40 lines (31 loc) · 1.09 KB
/
radio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup
from tweet import twitter_post
module = "Radio"
def radio_data():
"""Gets appearences of BLACKPINK on italian radios
"""
print("[{}] Starting...".format(module))
URL = "https://radioairplay.fm/artista/175127/blackpink/airplay/shut-down/"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
table = soup.find("table", class_="table-striped")
try:
rows = table.find("tbody").find_all("tr")
radio = []
for row in rows:
radio.append(row.text.strip().replace('\n', ' on ').replace(' (Italia)',' (Italy)'))
f = open("last_radio.txt", "r")
last = f.readline()
for appearence in radio:
if appearence == last:
break
else:
twitter_post("#ShutDown aired on radio at " + appearence)
f.close()
f = open("last_radio.txt", "w")
f.write(radio[0])
f.close()
except AttributeError:
print("WARNING: no table found on the radio page")