import discord from bs4 import BeautifulSoup import requests import threading results = {} def get_river_stats(river_id): url = requests.get("https://waterdata.usgs.gov/usa/nwis/uv?" + river_id) soup = BeautifulSoup(url.content, "lxml") river_name = ' '.join(soup.find('h2').text.split()[2:]) table = soup.find('table', border=1, align='left') title = table.find('caption').text.strip().split('--')[0].strip() for rows in table.findAll('tr'): flow_value = rows.findAll('td',{'class': 'highlight2'}) results[river_name] = flow_value[0].text def get_stats(): river_ids = [ '06752260', '07091200', '06719505', ] threads = [] for river in river_ids: t = threading.Thread(target=get_river_stats, args=(river,)) threads.append(t) t.start() for x in threads: x.join() final_string = '' for key, value in results.items(): final_string += "\n" + key + ": " + value return "```" + final_string + "```"