Advertisement
VssA

th

Dec 25th, 2023
1,129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import threading
  2. import requests
  3. from bs4 import BeautifulSoup
  4.  
  5. def get_currencies(url, id, currencies, semaphore):
  6.     response = requests.get(url)
  7.     if response.status_code == 200:
  8.         semaphore.acquire()
  9.         try:
  10.             secret_code()
  11.             soup = BeautifulSoup(response.text, 'html.parser')
  12.             currency = str(soup.find_all('valute')[id])
  13.             if currency not in currencies:
  14.                 currencies.append(currency)
  15.         finally:
  16.             semaphore.release()
  17.  
  18. if __name__ == '__main__':
  19.  
  20.     currencies = []
  21.     id = int(input())
  22.     semaphore = threading.Semaphore(4)
  23.    
  24.     threads = []
  25.     for url in urls:
  26.         thread = threading.Thread(target=get_currencies, args=(url, id, currencies, semaphore))
  27.         threads.append(thread)
  28.         thread.start()
  29.  
  30.     for thread in thread:
  31.         thread.join()
  32.  
  33.  
  34.  
  35.     currencies_string = ''.join(currencies)
  36.     print(currencies_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement