SHOW:
|
|
- or go back to the newest paste.
| 1 | - | import requests, re |
| 1 | + | import time, random |
| 2 | - | from matplotlib import pyplot as plt |
| 2 | + | |
| 3 | - | from matplotlib.ticker import EngFormatter |
| 3 | + | # decorator function |
| 4 | - | from bs4 import BeautifulSoup |
| 4 | + | def my_timer(func): |
| 5 | ||
| 6 | - | def main(url): |
| 6 | + | def wrapper(*args, **kwargs): |
| 7 | print("my_timer call")
| |
| 8 | - | result = requests.get(url) |
| 8 | + | |
| 9 | - | status = result.status_code |
| 9 | + | start = time.time() |
| 10 | result = func(*args, **kwargs) | |
| 11 | - | # status = 404 |
| 11 | + | print("my_timer result:", time.time()-start)
|
| 12 | - | assert status == 200, f"Site Error: Status Code {status}"
|
| 12 | + | |
| 13 | return result | |
| 14 | - | data = get_data(result.content) |
| 14 | + | |
| 15 | - | draw_data(data) |
| 15 | + | return wrapper |
| 16 | ||
| 17 | - | def get_data(source): |
| 17 | + | |
| 18 | - | """ |
| 18 | + | def print_something_decorator(func): |
| 19 | - | Gets a html source (str) and parses it with BeautifulSoup |
| 19 | + | |
| 20 | - | :param source: str() |
| 20 | + | def wrapper(*args, **kwargs): |
| 21 | - | :return: dict() |
| 21 | + | print("print_something_decorator call")
|
| 22 | - | """ |
| 22 | + | return func(*args, **kwargs) |
| 23 | ||
| 24 | - | soup = BeautifulSoup(source, 'lxml') |
| 24 | + | return wrapper |
| 25 | - | page_title = soup.title.text |
| 25 | + | |
| 26 | @my_timer | |
| 27 | - | columns = soup.find_all('div', class_="oszlop")
|
| 27 | + | @print_something_decorator |
| 28 | def get_all_files(root_folder): | |
| 29 | - | day_list = [] |
| 29 | + | print("Listing all files in", root_folder)
|
| 30 | - | temp_mins = [] |
| 30 | + | time.sleep( random.randint(2,10) ) |
| 31 | - | temp_maxes = [] |
| 31 | + | print("Data ready!")
|
| 32 | - | for col in columns: |
| 32 | + | |
| 33 | - | date_day = col.find('div', class_='nap')
|
| 33 | + | |
| 34 | - | date_num = col.find('div', class_='datum')
|
| 34 | + | get_all_files("c:/temp/photos") |