-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (38 loc) · 1.32 KB
/
Copy pathmain.py
File metadata and controls
49 lines (38 loc) · 1.32 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
import sqlite3
import requests
# Function to connect to DB and properly handle exceptions
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file, check_same_thread=False)
print(sqlite3.version)
except sqlite3.Error as e:
print(e)
conn = None
finally:
return conn
con = create_connection("entitlement.db")
c = con.cursor()
c.execute("SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE 'entitlement_%' ORDER BY name")
tables_to_check = c.fetchall()
sql_results = []
for table in tables_to_check:
c.execute(f'SELECT JSON FROM {table[0]} WHERE Entitlement_type = 5 AND Package_subtype IS NULL')
sql_results = sql_results + c.fetchall()
urls_to_check = []
for result in sql_results:
json_res = json.loads(result[0])
try:
urls_to_check.append(json_res['entitlement_attributes'][0]['reference_package_url'])
except KeyError:
pass
with open('links.txt', 'w') as f:
for url in urls_to_check:
url_result = requests.get(url).json()
part = 1
for link in url_result['pieces']:
print(link)
f.write(f"part{part}: {link['url']}\n")
part += 1
f.write("========================================\n")