awacke1 commited on
Commit
06cd2c3
·
1 Parent(s): 04a03d2

Update backup.py

Browse files
Files changed (1) hide show
  1. backup.py +63 -11
backup.py CHANGED
@@ -6,12 +6,21 @@ import base64
6
  from bs4 import BeautifulSoup
7
  import hashlib
8
  import json
 
9
 
10
  EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
11
  URLS = {
12
  "Chordify - Play Along Chords": "https://chordify.net/",
13
  "National Guitar Academy - Guitar Learning": "https://www.guitaracademy.com/",
14
  "Ultimate Guitar - Massive Song Database": "https://www.ultimate-guitar.com/",
 
 
 
 
 
 
 
 
15
  }
16
 
17
  if not os.path.exists("history.json"):
@@ -50,36 +59,67 @@ def list_files(directory_path='.'):
50
  files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
51
  return [f for f in files if f not in EXCLUDED_FILES]
52
 
53
- def show_file_operations(file_path):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  st.write(f"File: {os.path.basename(file_path)}")
55
  unique_key = hashlib.md5(file_path.encode()).hexdigest()
 
 
 
56
  col1, col2, col3 = st.columns(3)
57
 
58
  with col1:
59
- if st.button(f"✏️ Edit", key=f"edit_{unique_key}"):
60
- file_content = ""
61
  with open(file_path, "r") as f:
62
  file_content = f.read()
63
- file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=f"text_area_{unique_key}")
 
64
 
65
  with col2:
66
- if st.button(f"💾 Save", key=f"save_{unique_key}"):
67
- with open(file_path, "w") as f:
68
- f.write(file_content)
69
- st.success(f"File saved!")
 
 
70
 
71
  with col3:
72
- if st.button(f"🗑️ Delete", key=f"delete_{unique_key}"):
 
73
  os.remove(file_path)
74
  st.markdown(f"File deleted!")
75
 
 
 
 
76
  def show_download_links(subdir):
77
- st.write(f'Files for {subdir}:')
78
  for file in list_files(subdir):
79
  file_path = os.path.join(subdir, file)
 
 
 
 
 
 
80
  if os.path.isfile(file_path):
81
  st.markdown(get_download_link(file_path), unsafe_allow_html=True)
82
- show_file_operations(file_path)
83
  else:
84
  st.write(f"File not found: {file}")
85
 
@@ -92,6 +132,8 @@ def get_download_link(file):
92
 
93
  def main():
94
  st.sidebar.title('Web Datasets Bulk Downloader')
 
 
95
  url_input_method = st.sidebar.radio("Choose URL Input Method", ["Enter URL", "Select from List"])
96
  url = ""
97
  if url_input_method == "Enter URL":
@@ -100,9 +142,15 @@ def main():
100
  selected_site = st.sidebar.selectbox("Select a Website", list(URLS.keys()))
101
  url = URLS[selected_site]
102
 
 
 
 
 
 
103
  with open("history.json", "r") as f:
104
  history = json.load(f)
105
 
 
106
  if url:
107
  subdir = hashlib.md5(url.encode()).hexdigest()
108
  if not os.path.exists(subdir):
@@ -112,18 +160,22 @@ def main():
112
  with open("history.json", "w") as f:
113
  json.dump(history, f)
114
 
 
115
  if st.sidebar.button('📥 Get All the Content'):
116
  download_html_and_files(url, history[url])
117
  show_download_links(history[url])
118
 
 
119
  if st.sidebar.button('📂 Show Download Links'):
120
  for subdir in history.values():
121
  show_download_links(subdir)
122
 
 
123
  with st.expander("URL History and Downloaded Files"):
124
  for url, subdir in history.items():
125
  st.markdown(f"#### {url}")
126
  show_download_links(subdir)
127
 
 
128
  if __name__ == "__main__":
129
  main()
 
6
  from bs4 import BeautifulSoup
7
  import hashlib
8
  import json
9
+ import uuid
10
 
11
  EXCLUDED_FILES = ['app.py', 'requirements.txt', 'pre-requirements.txt', 'packages.txt', 'README.md','.gitattributes', "backup.py","Dockerfile"]
12
  URLS = {
13
  "Chordify - Play Along Chords": "https://chordify.net/",
14
  "National Guitar Academy - Guitar Learning": "https://www.guitaracademy.com/",
15
  "Ultimate Guitar - Massive Song Database": "https://www.ultimate-guitar.com/",
16
+ "Wolf Alice": "https://www.chordie.com/song.php/songartist/Wolf+Alice/index.html",
17
+ "Everclear": "https://www.chordie.com/song.php/songartist/Everclear/index.html",
18
+ "Jungle": "https://www.ultimate-guitar.com/artist/jungle_47745",
19
+ "Mylie Cyrus": "https://www.ultimate-guitar.com/search.php?title=mile+cyrus&spelling=Mylie+cyrus",
20
+ "Kanye": "https://www.ultimate-guitar.com/search.php?search_type=title&value=Kanye%20west",
21
+ "Cat Stevens": "https://www.ultimate-guitar.com/search.php?search_type=title&value=cat%20stevens",
22
+ "Metric": "https://www.ultimate-guitar.com/search.php?search_type=title&value=Metric",
23
+ "John Lennon": "https://www.ultimate-guitar.com/search.php?search_type=title&value=John%20Lennon",
24
  }
25
 
26
  if not os.path.exists("history.json"):
 
59
  files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
60
  return [f for f in files if f not in EXCLUDED_FILES]
61
 
62
+ def file_editor(file_path):
63
+ st.write(f"Editing File: {os.path.basename(file_path)}")
64
+ file_content = ""
65
+
66
+ with open(file_path, "r") as f:
67
+ file_content = f.read()
68
+
69
+ file_content = st.text_area("Edit the file content:", value=file_content, height=250)
70
+
71
+ if st.button("💾 Save"):
72
+ with open(file_path, "w") as f:
73
+ f.write(file_content)
74
+ st.success(f"File '{os.path.basename(file_path)}' saved!")
75
+
76
+
77
+ def show_file_operations(file_path, sequence_number):
78
  st.write(f"File: {os.path.basename(file_path)}")
79
  unique_key = hashlib.md5(file_path.encode()).hexdigest()
80
+
81
+ file_content = ""
82
+
83
  col1, col2, col3 = st.columns(3)
84
 
85
  with col1:
86
+ edit_key = f"edit_{unique_key}_{sequence_number}"
87
+ if st.button(f"✏️ Edit", key=edit_key):
88
  with open(file_path, "r") as f:
89
  file_content = f.read()
90
+ text_area_key = f"text_area_{unique_key}_{sequence_number}"
91
+ file_content = st.text_area("Edit the file content:", value=file_content, height=250, key=text_area_key)
92
 
93
  with col2:
94
+ save_key = f"save_{unique_key}_{sequence_number}"
95
+ if st.button(f"💾 Save", key=save_key):
96
+ if file_content: # Ensure file_content is not empty
97
+ with open(file_path, "w") as f:
98
+ f.write(file_content)
99
+ st.success(f"File saved!")
100
 
101
  with col3:
102
+ delete_key = f"delete_{unique_key}_{sequence_number}"
103
+ if st.button(f"🗑️ Delete", key=delete_key):
104
  os.remove(file_path)
105
  st.markdown(f"File deleted!")
106
 
107
+
108
+ file_sequence_numbers = {}
109
+
110
  def show_download_links(subdir):
111
+ global file_sequence_numbers
112
  for file in list_files(subdir):
113
  file_path = os.path.join(subdir, file)
114
+ if file_path not in file_sequence_numbers:
115
+ file_sequence_numbers[file_path] = 1
116
+ else:
117
+ file_sequence_numbers[file_path] += 1
118
+ sequence_number = file_sequence_numbers[file_path]
119
+
120
  if os.path.isfile(file_path):
121
  st.markdown(get_download_link(file_path), unsafe_allow_html=True)
122
+ show_file_operations(file_path, sequence_number)
123
  else:
124
  st.write(f"File not found: {file}")
125
 
 
132
 
133
  def main():
134
  st.sidebar.title('Web Datasets Bulk Downloader')
135
+
136
+ # Selecting URL input method
137
  url_input_method = st.sidebar.radio("Choose URL Input Method", ["Enter URL", "Select from List"])
138
  url = ""
139
  if url_input_method == "Enter URL":
 
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):
 
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
+ # Button for showing download links
169
  if st.sidebar.button('📂 Show Download Links'):
170
  for subdir in history.values():
171
  show_download_links(subdir)
172
 
173
+ # Expander for showing URL history and download links
174
  with st.expander("URL History and Downloaded Files"):
175
  for url, subdir in history.items():
176
  st.markdown(f"#### {url}")
177
  show_download_links(subdir)
178
 
179
+
180
  if __name__ == "__main__":
181
  main()