-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_new_releases.py
76 lines (62 loc) · 2.19 KB
/
check_new_releases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
from bs4 import BeautifulSoup
from datetime import datetime, timedelta
# URL of the webpage to check
URL = 'https://disk.comindware.ru/CBAP/4.7/Astra/'
def fetch_page(url):
"""Fetches the webpage content."""
try:
response = requests.get(url)
if response.status_code == 200:
return response.text
else:
print(f"Failed to retrieve data, status code: {response.status_code}")
return None
except Exception as e:
print(f"Error fetching the page: {e}")
return None
def get_new_files(html_content):
"""Extracts new files with a date later than yesterday."""
soup = BeautifulSoup(html_content, 'html.parser')
# Find the table with id="list"
table = soup.find('table', id='list')
if not table:
print("Table with id='list' not found.")
return []
rows = table.find_all('tr')
# Get yesterday's date for comparison
yesterday = datetime.now() - timedelta(days=1)
new_files = []
# Loop through each row in the table to find file details
for row in rows:
columns = row.find_all('td')
if len(columns) < 3:
continue
file_name = columns[0].text.strip()
file_date_str = columns[2].text.strip()
if file_name == 'Parent directory/':
continue
# Convert the date string to a datetime object
try:
file_date = datetime.strptime(file_date_str, '%Y-%b-%d %H:%M')
except ValueError:
continue # Skip rows where the date is not in the expected format
# Check if the file's date is later than yesterday
if file_date < yesterday:
new_files.append(file_name)
return new_files
def main():
"""Main function to fetch and check for new files."""
html_content = fetch_page(URL)
if not html_content:
return
new_files = get_new_files(html_content)
if new_files:
# Print file names, this will be captured by the shell script
print("New files found:")
for file in new_files:
print(file)
else:
print("No new files found.")
if __name__ == "__main__":
main()