Advertisement
Guest User

holosupachacalc.py

a guest
Dec 24th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import requests
  2. import urllib.request
  3. from bs4 import BeautifulSoup
  4. from datetime import datetime, timedelta
  5. import re
  6.  
  7. def supacha_scanner(url):
  8.     response = requests.get(url)
  9.     soup = BeautifulSoup(response.text, "html.parser")
  10.     supacha_elements = soup.find_all('a', href=re.compile("superchat"))
  11.     supacha_sum = 0
  12.     for element in supacha_elements:
  13.         supacha = element.text.replace(',', '')
  14.         supacha = supacha[:-3]
  15.         supacha_sum += int(supacha)
  16.     print(supacha_sum)
  17.     return supacha_sum
  18.  
  19. if __name__ == '__main__':
  20.     start_date = datetime.strptime(input("start date(YYYY-MM-DD)(leave blank for today's total):"), "%Y-%m-%d")
  21.     end_date = datetime.strptime(input("end date(YYYY-MM-DD)(leave blank for today's total):"), "%Y-%m-%d")
  22.     total_supacha = 0
  23.     if start_date == "" and end_date == "":      
  24.         total_supacha = supacha_scanner("https://www.hololyzer.net/youtube/realtime/index.html")
  25.    
  26.     delta = timedelta(days=1)
  27.  
  28.     while start_date <= end_date:
  29.         print(start_date.strftime("%Y-%m-%d")+":")
  30.         total_supacha += supacha_scanner("https://www.hololyzer.net/youtube/realtime/list/"+start_date.strftime("%Y-%m-%d")+".html")
  31.         start_date += delta
  32.  
  33.     print(str(total_supacha)+"円")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement