Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -129,53 +129,59 @@ def get_download_link(file):
|
|
| 129 |
b64 = base64.b64encode(bytes).decode()
|
| 130 |
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Click to download {os.path.basename(file)}</a>'
|
| 131 |
return href
|
| 132 |
-
|
| 133 |
def main():
|
| 134 |
st.sidebar.title('Web Datasets Bulk Downloader')
|
| 135 |
|
| 136 |
-
#
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
if url_input_method == "Enter URL":
|
| 140 |
-
url = st.sidebar.text_input('Please enter a Web URL to bulk download text and files')
|
| 141 |
-
else:
|
| 142 |
-
selected_site = st.sidebar.selectbox("Select a Website", list(URLS.keys()))
|
| 143 |
-
url = URLS[selected_site]
|
| 144 |
-
|
| 145 |
-
# Reading or creating history.json
|
| 146 |
-
if not os.path.exists("history.json"):
|
| 147 |
-
with open("history.json", "w") as f:
|
| 148 |
-
json.dump({}, f)
|
| 149 |
-
|
| 150 |
-
with open("history.json", "r") as f:
|
| 151 |
-
history = json.load(f)
|
| 152 |
-
|
| 153 |
-
# Handling URL submission
|
| 154 |
-
if url:
|
| 155 |
-
subdir = hashlib.md5(url.encode()).hexdigest()
|
| 156 |
-
if not os.path.exists(subdir):
|
| 157 |
-
os.makedirs(subdir)
|
| 158 |
-
if url not in history:
|
| 159 |
-
history[url] = subdir
|
| 160 |
-
with open("history.json", "w") as f:
|
| 161 |
-
json.dump(history, f)
|
| 162 |
-
|
| 163 |
-
# Button for downloading content
|
| 164 |
-
if st.sidebar.button('📥 Get All the Content'):
|
| 165 |
-
download_html_and_files(url, history[url])
|
| 166 |
-
show_download_links(history[url])
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
|
| 180 |
if __name__ == "__main__":
|
| 181 |
main()
|
|
|
|
|
|
| 129 |
b64 = base64.b64encode(bytes).decode()
|
| 130 |
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{os.path.basename(file)}\'>Click to download {os.path.basename(file)}</a>'
|
| 131 |
return href
|
|
|
|
| 132 |
def main():
|
| 133 |
st.sidebar.title('Web Datasets Bulk Downloader')
|
| 134 |
|
| 135 |
+
# Check for query parameters for file editing
|
| 136 |
+
query_params = st.experimental_get_query_params()
|
| 137 |
+
file_to_edit = query_params.get('file_to_edit', [None])[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
if file_to_edit and os.path.exists(file_to_edit):
|
| 140 |
+
file_editor(file_to_edit)
|
| 141 |
+
else:
|
| 142 |
+
# Selecting URL input method
|
| 143 |
+
url_input_method = st.sidebar.radio("Choose URL Input Method", ["Enter URL", "Select from List"])
|
| 144 |
+
url = ""
|
| 145 |
+
if url_input_method == "Enter URL":
|
| 146 |
+
url = st.sidebar.text_input('Please enter a Web URL to bulk download text and files')
|
| 147 |
+
else:
|
| 148 |
+
selected_site = st.sidebar.selectbox("Select a Website", list(URLS.keys()))
|
| 149 |
+
url = URLS[selected_site]
|
| 150 |
|
| 151 |
+
# Reading or creating history.json
|
| 152 |
+
if not os.path.exists("history.json"):
|
| 153 |
+
with open("history.json", "w") as f:
|
| 154 |
+
json.dump({}, f)
|
| 155 |
+
|
| 156 |
+
with open("history.json", "r") as f:
|
| 157 |
+
history = json.load(f)
|
| 158 |
+
|
| 159 |
+
# Handling URL submission
|
| 160 |
+
if url:
|
| 161 |
+
subdir = hashlib.md5(url.encode()).hexdigest()
|
| 162 |
+
if not os.path.exists(subdir):
|
| 163 |
+
os.makedirs(subdir)
|
| 164 |
+
if url not in history:
|
| 165 |
+
history[url] = subdir
|
| 166 |
+
with open("history.json", "w") as f:
|
| 167 |
+
json.dump(history, f)
|
| 168 |
+
|
| 169 |
+
# Button for downloading content
|
| 170 |
+
if st.sidebar.button('📥 Get All the Content'):
|
| 171 |
+
download_html_and_files(url, history[url])
|
| 172 |
+
show_download_links(history[url])
|
| 173 |
+
|
| 174 |
+
# Button for showing download links
|
| 175 |
+
if st.sidebar.button('📂 Show Download Links'):
|
| 176 |
+
for subdir in history.values():
|
| 177 |
+
show_download_links(subdir)
|
| 178 |
+
|
| 179 |
+
# Expander for showing URL history and download links
|
| 180 |
+
with st.expander("URL History and Downloaded Files"):
|
| 181 |
+
for url, subdir in history.items():
|
| 182 |
+
st.markdown(f"#### {url}")
|
| 183 |
+
show_download_links(subdir)
|
| 184 |
|
|
|
|
| 185 |
if __name__ == "__main__":
|
| 186 |
main()
|
| 187 |
+
|