-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetFDroidIndex.py
More file actions
40 lines (32 loc) · 1.27 KB
/
getFDroidIndex.py
File metadata and controls
40 lines (32 loc) · 1.27 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
import requests
import os
from dotenv import load_dotenv
from xml.dom import minidom
load_dotenv("filePaths.env")
URL = "https://f-droid.org/repo/index.xml"
F_DROID_INDEX_FILE = os.getenv('F-DROID-INDEX-FILE')
OUTPUT_FILE = os.getenv('F-DROID-PROJECTS-LIST-FILE')
def downloadFDroidIndex():
response = requests.get(URL, stream = True)
with open(F_DROID_INDEX_FILE, "wb") as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)
print("SUCCESS: F-Droid index was downloaded and saved to " + F_DROID_INDEX_FILE)
def getFDroidIndexSourceTag():
indexFile = minidom.parse(F_DROID_INDEX_FILE)
sourceTag = indexFile.getElementsByTagName('source')
print("INFO: Total items in Index: " + str(sourceTag.length))
return sourceTag
def saveProjectsURLsToRegistry():
registryFile = open(OUTPUT_FILE, 'a')
for url in getFDroidIndexSourceTag():
if(url.firstChild != None):
repoURL = url.firstChild.data
registryFile.write(repoURL + "\n")
registryFile.close()
print("SUCCESS: F-Droid repos' urls were saved to " + OUTPUT_FILE)
if __name__ == "__main__":
os.makedirs(os.path.dirname(F_DROID_INDEX_FILE), exist_ok=True)
downloadFDroidIndex()
saveProjectsURLsToRegistry()