awacke1 commited on
Commit
c0bcae6
·
1 Parent(s): f034102

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from github import Github
3
+ import requests
4
+
5
+ # Set up the Streamlit app
6
+ st.title("GitHub Repository Downloader")
7
+
8
+ # Get user input for GitHub repository details
9
+ owner = st.text_input("Enter the repository owner:")
10
+ repo = st.text_input("Enter the repository name:")
11
+
12
+ # Create a PyGitHub object for the repository
13
+ g = Github()
14
+ repository = g.get_repo(f"{owner}/{repo}")
15
+
16
+ # Get all files in the repository
17
+ files = repository.get_contents("")
18
+
19
+ # Create a list to store the URLs of the files to download
20
+ urls_to_download = []
21
+
22
+ # Loop through each file and check if it's a data file or markdown file
23
+ for file in files:
24
+ if file.name.endswith(".csv") or file.name.endswith(".md"):
25
+ urls_to_download.append(file.download_url)
26
+
27
+ # If there are files to download, create a button to start the download
28
+ if len(urls_to_download) > 0:
29
+ if st.button("Download Files"):
30
+ for url in urls_to_download:
31
+ # Download the file using the requests library
32
+ response = requests.get(url)
33
+ # Save the file with the original name in the current working directory
34
+ with open(f"./{url.split('/')[-1]}", "wb") as file:
35
+ file.write(response.content)
36
+ st.success("Download complete!")
37
+ else:
38
+ st.write("No data or markdown files found in the repository.")