Created
April 28, 2020 19:57
-
-
Save jugmac00/8dfc1f237bb824ddf197b5e26453c03f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import telegram | |
| import requests | |
| from bs4 import BeautifulSoup | |
| from urllib.parse import urljoin | |
| DAREBEE_URL = "https://www.darebee.com/" | |
| API_KEY = os.getenv("API_KEY") | |
| ID_JUERGEN = os.getenv("ID_JUERGEN") | |
| def get_source_code(url): | |
| r = requests.get(url) | |
| return r.text | |
| def get_parser(html): | |
| return BeautifulSoup(html, "html.parser") | |
| def extract_dailydare_url(): | |
| html = get_source_code(url=DAREBEE_URL) | |
| parser = get_parser(html) | |
| dailydare_div = parser.find('div', attrs={"class" : "custom dailydare"}) | |
| dailydare_img = dailydare_div.img['src'] | |
| return urljoin(DAREBEE_URL, dailydare_img) | |
| def extract_wod_url(): | |
| html = get_source_code(url=DAREBEE_URL) | |
| parser = get_parser(html) | |
| wod_div = parser.find('div', attrs={"class" : "custom darewod"}) | |
| wod_name = wod_div.a['href'].split('/')[2].split('.')[0] | |
| img_path = '/images/workouts/' | |
| wod_img = wod_name + '.jpg' | |
| path = os.path.join(img_path, wod_img) | |
| return urljoin(DAREBEE_URL, path) | |
| if __name__ == '__main__': | |
| bot = telegram.Bot(token=API_KEY) | |
| dailydare_url = extract_dailydare_url() | |
| print(dailydare_url) | |
| bot.send_photo(chat_id=int(ID_JUERGEN), photo=dailydare_url) | |
| wod_url = extract_wod_url() | |
| print(wod_url) | |
| bot.send_photo(chat_id=int(ID_JUERGEN), photo=wod_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment