-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetUrl.py
More file actions
executable file
·35 lines (34 loc) · 1.87 KB
/
getUrl.py
File metadata and controls
executable file
·35 lines (34 loc) · 1.87 KB
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
#!/usr/bin/python3
import urllib.request, urllib.error, urllib.parse
from bs4 import BeautifulSoup
import sys
import re
import os
import hashlib
if __name__ == "__main__":
with urllib.request.urlopen('https://www.eclipse.org/downloads/eclipse-packages/?osType=linux&release=undefined') as f:
page = BeautifulSoup(f.read(), 'html.parser')
a = page.find(lambda tag: tag.name == "a" and tag.string is not None and tag.string.strip() == "Eclipse IDE for Enterprise Java Developers")
b64 = a.parent.parent.parent.find(lambda tag: tag.name == "span" and tag["class"] == ["linux"]).find("a")["href"]
b64 = 'https:' + b64
print(b64)
with urllib.request.urlopen(b64) as f:
page = BeautifulSoup(f.read(), 'html.parser')
finalLink = page.find(lambda tag: tag.name == "a" and tag.string is not None and tag.string.strip().lower() == "direct link to file")["href"]
finalLink = 'https://www.eclipse.org/downloads/' + finalLink
shaLink = finalLink.replace('download.php', 'sums.php')
with urllib.request.urlopen(shaLink) as f:
shasum = bytes.fromhex(f.read().split()[0].decode('utf-8'))
#link = page.find(href = re.compile('^download\.php.+'))['href']
#link = 'https://www.eclipse.org/downloads/' + link
#with urllib.request.urlopen(link) as f:
# page = BeautifulSoup(f.read(), 'html.parser')
# finalLink = page.find(lambda tag: tag.name == "a" and tag.string is not None and tag.string.strip() == "click here")["href"]
sha = hashlib.sha512()
with urllib.request.urlopen(finalLink) as f, os.fdopen(sys.stdout.fileno(), 'wb') as stdout:
for part in iter(lambda: f.read(8192), b""):
sha.update(part)
stdout.write(part)
if sha.digest() != shasum:
stdout.write('sha512 check failed'.encode('utf-8'))
raise Exception('sha512 check failed')