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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import glob
|
| 4 |
+
import re
|
| 5 |
+
import datetime
|
| 6 |
+
from urllib.parse import quote
|
| 7 |
+
|
| 8 |
+
# Define the markdown variables
|
| 9 |
+
Boxing_and_MMA_Commentary_and_Knowledge = """
|
| 10 |
+
# Boxing and UFC Study of 1971 - 2024 The Greatest Fights History
|
| 11 |
+
|
| 12 |
+
1. In Boxing, the most heart breaking fight in Boxing was the Boom Boom Mancini fight with Duku Kim.
|
| 13 |
+
2. After changes to Boxing made it more safe due to the heart break.
|
| 14 |
+
3. Rehydration of the brain after weight ins loss preparation for a match is life saving change.
|
| 15 |
+
4. Fighting went from 15 rounds to 12.
|
| 16 |
+
|
| 17 |
+
# UFC By Contrast..
|
| 18 |
+
1. 5 Rounds of 5 Minutes each.
|
| 19 |
+
2. Greatest UFC Fighters:
|
| 20 |
+
- Jon Jones could be the greatest of all time (GOAT) since he never lost.
|
| 21 |
+
- George St. Pierre
|
| 22 |
+
- BJ Penn
|
| 23 |
+
- Anderson Silva
|
| 24 |
+
- Mighty Mouse MMA's heart at 125 pounds
|
| 25 |
+
- Kabib retired 29 and 0
|
| 26 |
+
- Fedor Milliano
|
| 27 |
+
- Alex Pereira
|
| 28 |
+
- James Tony
|
| 29 |
+
- Randy Couture
|
| 30 |
+
3. You have to Judge them in their Championship Peak
|
| 31 |
+
4. Chris Weidman
|
| 32 |
+
5. Connor McGregor
|
| 33 |
+
6. Leg Breaking - Shin calcification and breaking baseball bats
|
| 34 |
+
|
| 35 |
+
# References:
|
| 36 |
+
1. Joe Rogan - Interview #2219
|
| 37 |
+
2. Donald J Trump
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """
|
| 41 |
+
|
| 42 |
+
# Multiplayer Simulated Worlds
|
| 43 |
+
|
| 44 |
+
1. 7 Days To Die PC
|
| 45 |
+
2. ARK: Survival Evolved PC
|
| 46 |
+
3. Arma 3 PC
|
| 47 |
+
4. Atlas PC
|
| 48 |
+
5. Conan Exiles PC
|
| 49 |
+
6. Craftopia PC
|
| 50 |
+
7. DayZ PC
|
| 51 |
+
8. Eco - Global Survival PC
|
| 52 |
+
9. Empyrion - Galactic Survival PC
|
| 53 |
+
10. Factorio PC
|
| 54 |
+
11. Farming Simulator 19 PC
|
| 55 |
+
12. Crossplay
|
| 56 |
+
13. Farming Simulator 22
|
| 57 |
+
14. Last Oasis PC
|
| 58 |
+
15. Last Oasis Classic PC
|
| 59 |
+
16. Minecraft (Vanilla) PC
|
| 60 |
+
17. Crossplay
|
| 61 |
+
18. Path of Titans
|
| 62 |
+
19. Rust PC
|
| 63 |
+
20. SCP: Secret Laboratory PC
|
| 64 |
+
21. SCUM PC
|
| 65 |
+
22. Satisfactory PC
|
| 66 |
+
23. Satisfactory (Experimental) PC
|
| 67 |
+
24. Crossplay
|
| 68 |
+
25. Space Engineers
|
| 69 |
+
26. Terraria (tShock & Vanilla) PC
|
| 70 |
+
27. The Forest PC
|
| 71 |
+
28. Crossplay
|
| 72 |
+
29. Valheim
|
| 73 |
+
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
# Function to parse markdown text and create external links for terms
|
| 77 |
+
def display_external_links(term):
|
| 78 |
+
search_urls = {
|
| 79 |
+
"ArXiv": lambda k: f"https://arxiv.org/search/?query={quote(k)}",
|
| 80 |
+
"Wikipedia": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
|
| 81 |
+
"Google": lambda k: f"https://www.google.com/search?q={quote(k)}",
|
| 82 |
+
"YouTube": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}",
|
| 83 |
+
}
|
| 84 |
+
links_md = ' | '.join([f"[{name}]({url(term)})" for name, url in search_urls.items()])
|
| 85 |
+
st.markdown(f"- **{term}** - {links_md}")
|
| 86 |
+
|
| 87 |
+
# Function to parse markdown text and extract terms
|
| 88 |
+
def extract_terms(markdown_text):
|
| 89 |
+
# Split text into lines
|
| 90 |
+
lines = markdown_text.strip().split('\n')
|
| 91 |
+
terms = []
|
| 92 |
+
for line in lines:
|
| 93 |
+
# Remove markdown special characters
|
| 94 |
+
line = re.sub(r'^[#*\->\d\.\s]+', '', line).strip()
|
| 95 |
+
if line:
|
| 96 |
+
terms.append(line)
|
| 97 |
+
return terms
|
| 98 |
+
|
| 99 |
+
# Function to create internal links with query parameters
|
| 100 |
+
def display_internal_links(term):
|
| 101 |
+
app_url = st.experimental_get_query_params()
|
| 102 |
+
# Reconstruct the app URL without parameters
|
| 103 |
+
base_url = st.request.host_url
|
| 104 |
+
link = f"{base_url}?q={quote(term)}"
|
| 105 |
+
st.markdown(f"- [{term}]({link})")
|
| 106 |
+
|
| 107 |
+
# Function to automatically generate filenames based on date and content
|
| 108 |
+
def generate_filename(prefix, content):
|
| 109 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 110 |
+
safe_content = re.sub(r'\W+', '_', content[:50])
|
| 111 |
+
filename = f"{prefix}_{timestamp}_{safe_content}.md"
|
| 112 |
+
return filename
|
| 113 |
+
|
| 114 |
+
# Sidebar for file management
|
| 115 |
+
def file_management_sidebar():
|
| 116 |
+
st.sidebar.title("📁 File Management")
|
| 117 |
+
|
| 118 |
+
# Get list of .md files excluding README.md
|
| 119 |
+
md_files = [file for file in glob.glob("*.md") if os.path.basename(file).lower() != 'readme.md']
|
| 120 |
+
md_files.sort()
|
| 121 |
+
|
| 122 |
+
if md_files:
|
| 123 |
+
selected_file = st.sidebar.selectbox("Select a markdown file to view/edit", md_files)
|
| 124 |
+
|
| 125 |
+
# Navigation buttons
|
| 126 |
+
file_index = md_files.index(selected_file)
|
| 127 |
+
col1, col2 = st.sidebar.columns([1,1])
|
| 128 |
+
if col1.button("Previous"):
|
| 129 |
+
if file_index > 0:
|
| 130 |
+
selected_file = md_files[file_index -1]
|
| 131 |
+
st.experimental_set_query_params(selected_file=selected_file)
|
| 132 |
+
st.experimental_rerun()
|
| 133 |
+
if col2.button("Next"):
|
| 134 |
+
if file_index < len(md_files) -1:
|
| 135 |
+
selected_file = md_files[file_index +1]
|
| 136 |
+
st.experimental_set_query_params(selected_file=selected_file)
|
| 137 |
+
st.experimental_rerun()
|
| 138 |
+
|
| 139 |
+
# Load file content
|
| 140 |
+
with open(selected_file, 'r', encoding='utf-8') as f:
|
| 141 |
+
file_content = f.read()
|
| 142 |
+
|
| 143 |
+
# Tabs for Markdown View and Code Editor
|
| 144 |
+
tab1, tab2 = st.tabs(["Markdown View", "Code Editor"])
|
| 145 |
+
|
| 146 |
+
with tab1:
|
| 147 |
+
st.markdown(f"### {selected_file}")
|
| 148 |
+
st.markdown(file_content)
|
| 149 |
+
|
| 150 |
+
with tab2:
|
| 151 |
+
edited_content = st.text_area("Edit the markdown content", file_content, height=400)
|
| 152 |
+
if st.button("Save Changes"):
|
| 153 |
+
with open(selected_file, 'w', encoding='utf-8') as f:
|
| 154 |
+
f.write(edited_content)
|
| 155 |
+
st.success(f"Changes saved to {selected_file}")
|
| 156 |
+
st.experimental_rerun()
|
| 157 |
+
else:
|
| 158 |
+
st.sidebar.write("No markdown files found.")
|
| 159 |
+
|
| 160 |
+
# Option to create a new markdown file
|
| 161 |
+
if st.sidebar.button("Create New Markdown File"):
|
| 162 |
+
# Generate automatic filename
|
| 163 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 164 |
+
new_filename = f"note_{timestamp}.md"
|
| 165 |
+
with open(new_filename, 'w', encoding='utf-8') as f:
|
| 166 |
+
f.write("# New Markdown File\n")
|
| 167 |
+
st.sidebar.success(f"Created new file: {new_filename}")
|
| 168 |
+
st.experimental_set_query_params(selected_file=new_filename)
|
| 169 |
+
st.experimental_rerun()
|
| 170 |
+
|
| 171 |
+
# Main application logic
|
| 172 |
+
def main():
|
| 173 |
+
st.title("Markdown Content with Links and File Management")
|
| 174 |
+
|
| 175 |
+
# Display the original markdown content
|
| 176 |
+
st.markdown("## Original Markdown Content")
|
| 177 |
+
st.markdown(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 178 |
+
st.markdown(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 179 |
+
|
| 180 |
+
# Parse and display external links
|
| 181 |
+
st.markdown("## External Links Generated from Markdown Content")
|
| 182 |
+
terms = extract_terms(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 183 |
+
for term in terms:
|
| 184 |
+
display_external_links(term)
|
| 185 |
+
|
| 186 |
+
terms = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 187 |
+
for term in terms:
|
| 188 |
+
display_external_links(term)
|
| 189 |
+
|
| 190 |
+
# Parse and display internal links
|
| 191 |
+
st.markdown("## Internal Links Generated from Markdown Content")
|
| 192 |
+
terms = extract_terms(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 193 |
+
for term in terms:
|
| 194 |
+
display_internal_links(term)
|
| 195 |
+
|
| 196 |
+
terms = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 197 |
+
for term in terms:
|
| 198 |
+
display_internal_links(term)
|
| 199 |
+
|
| 200 |
+
# Process 'q' query parameter from the URL
|
| 201 |
+
query_params = st.experimental_get_query_params()
|
| 202 |
+
if 'q' in query_params:
|
| 203 |
+
search_query = query_params['q'][0]
|
| 204 |
+
st.write(f"### Search query received: {search_query}")
|
| 205 |
+
# Here you can implement your search logic
|
| 206 |
+
# For demonstration, we'll create a markdown file with the search query
|
| 207 |
+
filename = generate_filename("search", search_query)
|
| 208 |
+
content = f"# Search Results for '{search_query}'\n\n"
|
| 209 |
+
content += f"Here are the results for your search query: '{search_query}'.\n"
|
| 210 |
+
with open(filename, 'w', encoding='utf-8') as f:
|
| 211 |
+
f.write(content)
|
| 212 |
+
st.write(f"Generated file **{filename}** with search results.")
|
| 213 |
+
|
| 214 |
+
# File management sidebar
|
| 215 |
+
file_management_sidebar()
|
| 216 |
+
|
| 217 |
+
if __name__ == "__main__":
|
| 218 |
+
main()
|