summaryrefslogtreecommitdiff
path: root/archlinux_checker.py
blob: cf1c51143f8308f8a80d4e2188add4be8b3a2949 (plain)
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
#!/bin/python3

import requests, shutil, datetime
import os, re
from bs4 import BeautifulSoup

base = "https://www.archlinux.org"
url = base+"/releng/releases/"

# match yy.mm and yy.mm.dd archlinux version
regex = re.compile("[0-9]{4}\.[0-9]{2}.*")

torrent_dir="./"

def download_file(url):
    filename = list(filter(regex.search, url.split('/')))
    if filename:
        local_filename = torrent_dir+filename[0]+".torrent"
        if not os.path.isfile(local_filename):
            with requests.get(url, stream=True) as r:
                with open(local_filename, 'wb') as f:
                    shutil.copyfileobj(r.raw, f)
            return local_filename+" downloaded."
        else:
            return local_filename+" already exist."
    else:
        return "This is not a torrent..."


r = requests.get(url)

soup= BeautifulSoup(r.text, 'lxml')

tbody = soup.find('tbody')

links = tbody.find_all('a', {'href': re.compile(r'torrent')})


print("==========- {:%Y-%m-%d} -==========".format(datetime.datetime.now()))
print("==================================")
for link in links:
    print(download_file(base+link['href']))
print("==================================")